0

I have a dropdownlist with autopostback and an update panel, it works correctly, but I have also other controls in my page with autopostback. What I need is to control when the page is autopostback but the dropdownlist is not autopostback do something, like this:

     If is not Page.autopostback then
    'do something

else if is not MyDropdownlist.autopostback then    
    ' do something different    
    End if

I can use this:

If is not Page.autopostback then
End If

But I can´t do this:

If is not MyDropdownlist.autopostback then
End If

So how can I do this? I hope my explanation has been helpful, thanks.

4

1 回答 1

3

The __EVENTTARGET request form variable has the name of control that caused postback to happen. You can query the name of this control and do whatever you want to do.

For example,

If IsPostBack Then
    Dim postBackControlId As String = Request.Form("__EVENTTARGET")
    If Not String.IsNullOrEmpty(postBackControlId) Then
        If postBackControlId = "DropdownList1" Then
            ' the postback happened due to DropdownList1

        Else
            ' the postback happened due to some other control.

        End If
    End If
End If
于 2016-03-09T14:27:27.093 回答