Update label on MasterPage from content page with UpdatePanel without full Postback

北慕城南 提交于 2019-12-23 13:11:07

问题


Does there exist a solution for this scenario?

I have a content page which contains an UpdatePanel and has a combobox. When the combobox value is changed I want to change a label in my Master page. So, the main problem for me is that I don't want to make a full postback with every combobox value changing. Is there some trick to overcome full postback?

Thanks in advance.


回答1:


  • Put your label in your MasterPage in a separate UpdatePanel.
  • On dropdownlist's SelectedIndexChange make an asnychronous postback
  • From the SelectedIndexChanged-Handler call a function on Masterpage(f.e. ShowMessage) that changes the Text of the Label and calls Update on the Masterpage's UpdatePanel.

You can access your MasterPage's functions in the following way(from ContentPage just as UserControls in ContentPage):

((MyMaster)this.Page.Master).ShowMessage(text);

in VB.Net

DirectCast(Me.Page.Master, MyMaster).ShowMessage(text)

Of course you have to replace MyMaster with the actual type of your MasterPage and implement a public function(sub) that changes the Label's Text(ShowMessage in this example) and updates the UpdatePanel in the MasterPage. Set its UpdateMode property to Conditional and make sure that the ChildrenAsTriggers property is false and that no explicit triggers are defined for the panel.



来源:https://stackoverflow.com/questions/4889081/update-label-on-masterpage-from-content-page-with-updatepanel-without-full-postb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!