hi ....

i need help to unserstand this code please

if someone can help by explain or write commant

Public Shared Function GetPostBackControl(ByVal thePage As Page) As Control

 
        Dim myControl As Control = Nothing

        ' 
        Dim ctrlName As String = thePage.Request.Params.Get("__EVENTTARGET")
        If ((ctrlName IsNot Nothing) And (ctrlName <> String.Empty)) Then
            myControl = thePage.FindControl(ctrlName)

        Else

            For Each Item As String In thePage.Request.Form
                Dim c As Control = thePage.FindControl(Item)
                If (TypeOf (c) Is System.Web.UI.WebControls.Button) Then
                    myControl = c

                End If
            Next

        End If
        Return myControl
    End Function
Protected Overrides Sub OnInit(ByVal e As EventArgs)
        MyBase.OnInit(e)
        dynamicTextBoxes = New TextBox(myCount - 1) {}
        Dim i As Integer
        For i = 0 To myCount - 1 Step i + 1
            If myCount - 1 <= 3 Then


                Dim textBox As TextBox = New TextBox()
                textBox.ID = "myTextBox" + i.ToString()
                Dim requiredfield As RequiredFieldValidator = New RequiredFieldValidator()
                requiredfield.ControlToValidate = "myTextBox" + i.ToString()
                requiredfield.ErrorMessage = " fill this Option"
                requiredfield.ID = "myRequiredField" + i.ToString
                Dim Op As LiteralControl = New LiteralControl("Option  " & i + 1 & " : ")
                myPlaceHolder.Controls.Add(Op)
                myPlaceHolder.Controls.Add(textBox)
                myPlaceHolder.Controls.Add(requiredfield)

                dynamicTextBoxes(i) = textBox
                Dim literalBreak As LiteralControl = New LiteralControl("<br /> <br/>")
                myPlaceHolder.Controls.Add(literalBreak)


            End If
        Next
    End Sub

thanks :$

What is the question specifically? You can have 5 checkboxes with AutoPostBack=True and a button which causes a postback. The GetPostbackControl() indicates which control triggered the postback, otherwise you would only know that a postback occured but not what triggered it. Sometimes you want the postback to behave differently depending on what the user did.

Since that is the topic of this thread i'm thinking thats what you wanted?

hi ,

Dim ctrlName As String = thePage.Request.Params.Get("__EVENTTARGET")

what is " thepage.request.params.Get("_EventTarget") " return ?

is it indecate from where event come?

If ((ctrlName IsNot Nothing) And (ctrlName <> String.Empty)) Then            myControl = thePage.FindControl(ctrlName)

this if CHECK IF event come from control not page load , right?

But this else i dont understand it , what it means ?

Else             For Each Item As String In thePage.Request.Form                Dim c As Control = thePage.FindControl(Item)                If (TypeOf (c) Is System.Web.UI.WebControls.Button) Then                    myControl = c                 End If            Next         End If
Return myControl    End Function

can you explain it ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.