Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar control and Datagrid control to edit 1

Status
Not open for further replies.

cjburkha

Programmer
Jul 30, 2004
76
US
Hi,

I think I programed myself into a corner.

I have a calendar control with differnt records associated with each day. When you click on a day, a datagrid displays the the events assosiated with that day.

I would like to be able to edit the events from that datagrid. My problem is that I can't get the OnEditCommand event to fire because I write over it on page_load. See, clicking on the calendar causes a post back, and I populate the grid on that postback. That kills my edit ability, because the postback also refreshes the datagrid.

If there anyway to tell what caused a page to postback? My real problem is I cannot hook into the "click" event before page_load fires. I need to check if the page posted back because of a click on the calendar, or a click on the datagrid. If I can tell that, I'm ok.

Thanks for your time,

CJB
 
You can check which control caused the postback by looking at the __EVENTTARGET form attribute. e.g.
Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ctlPostBack As Control = WhichControlPostback(Me)
        If Not ctlPostBack Is Nothing Then
            Response.Write(ctlPostBack.ID)
        End If
    End Sub

    Function WhichControlPostback(ByVal MyPage As Page) As Control
        If MyPage.IsPostBack Then
            Dim ctlName As String = MyPage.Request.Form("__EVENTTARGET")
            ' If the control exists return it
            If ctlName.Trim().Length > 0 Then
                Return MyPage.FindControl(ctlName)
            End If
            ' If it doesn't exist, loop through each entry in the Form
            Dim colName As String
            For Each colName In MyPage.Request.Form
                Dim MyControl As Control = MyPage.FindControl(colName)
                If Not MyControl Is Nothing Then
                    If TypeOf MyControl Is Button Then
                        Return MyControl
                    End If
                End If
            Next
        End If
        Return Nothing
    End Function

I think there was an article explaining this further on aspnet.4guysfromrolla.com but I can't find the reference to it at the moment.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Thats great, thanks. That is exactly the information I was looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top