Search code examples
asp.netvb.netupdatepanelmaster-pages

Force UpdatePanel to reload from master page


I have a dropdown menu in my master page and on its SelectedIndexChanged event, I want it to reload the content page's data. I have the content of the content page wrapped in an UpdatePanel so that I can do this in my master page's code behind:

Protected Sub ddlMyDropdown_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlMyDropdown.SelectedIndexChanged
    Session("NewVal") = ddlMyDropdown.SelectedValue
    upMyUpdatePanel.Update()
End Sub

Then in the content page I use the value set by the dropdown and display it to the screen:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    lblMyLabel.Text = Session("NewVal")
End Sub

The problem is that when upMyUpdatePanel updates, it's a step behind, meaning it reflects the value of ddlMyDropdown from one SelectedIndexChanged event before this one. I believe this is because the content page's Page_Load event is firing before the master page's SelectedIndexChanged event.

How do I update the content page's content when a new value is selected from the master page's dropdown?


Solution

  • The answer from @wazz would have solved my problem if I didn't need the SelectedIndexChanged event to fire before the code runs in my content page.

    I solved my issue by moving my content page's Page_Load code into the Page_PreRender so that it fires after the SelectedIndexChanged from the master page. Probably isn't ideal but it worked nicely.

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        'Do stuff...
    End Sub