Archive for the ‘.net’ Category

more asp:updatepanel fun - dynamic triggers

Friday, April 20th, 2007

Another 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:

<Triggers>
  <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:

Sub page_load()
  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.

‘sys’ is undefined

Wednesday, April 11th, 2007

There’s a lot of blogging and forum posting about this error, but I wanted to make a note-to-self about what fixed it for me, for future reference.

From C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025\web.config grab the <httpHandlers> block and stick it inside <system.web>