more asp:updatepanel fun - dynamic triggers
Friday, April 20th, 2007Another post for my own future reference, and maybe it’ll help someone else when google comes by. I spent a very long time looking for the answer.
I have a DropDownList, and when value 999 is selected I want the Textbox in my UpdatePanel to become visible. Worked a charm with this:
<asp:AsyncPostBackTrigger ControlID="dropList" EventName="SelectedIndexChanged" />
</Triggers>
But, for reasons I won’t go into, I needed to dynamically declare the trigger in code. So, what I have finally come to is this:
ScriptManager1.RegisterAsyncPostBackControl(dropList)
If Not IsPostBack Then
Dim trigger As New UI.AsyncPostBackTrigger
trigger.ControlID = dropList.UniqueID.ToString
trigger.EventName = "SelectedIndexChanged"
UpdatePanel1.Triggers.Add(trigger)
End If
End Sub
Sub dropDeptsAreas_SelectedIndexChanged(ByVal s As Object, ByVal e As EventArgs)
If s.SelectedValue = "999" Then
txtNewbox.Visible = True
Else
txtNewbox.Visible = False
End If
UpdatePanel1.Update()
End Sub
Hurrah. The bit I was missing was RegisterAsynchPostBackControl.