c# - Post Data from contentpage to Masterpage using ajax technique -
c# - Post Data from contentpage to Masterpage using ajax technique -
i'm working on web application based on asp.net , c#. when click button in content page, want pass data(string) masterpage , show user. know technique , codes problem ajax. since button in content page within of updatepanel, when click button, message not appear in masterpage. because part of page wil refrsh , not know, how refesh master page
code within contentpage:
<asp:content id="content1" contentplaceholderid="contentplaceholder_body_member" ...> <asp:updatepanel id="updatepanel1" runat="server"> <contenttemplate> <asp:textbox ... ></asp:textbox> <asp:button id="showtext" ... /> </contenttemplate> </asp:updatepanel>
code within masterpage (actually nested masterpage):
<asp:content id="content1" contentplaceholderid="contentplaceholder_toprightside" runat="server"> ... </asp:content> <asp:content id="content2" contentplaceholderid="contentplaceholder_menu" runat="server"> ... </asp:content> <asp:content id="content3" contentplaceholderid="contentplaceholder_body" runat="server"> <asp:contentplaceholder id="contentplaceholder_body_member" runat="server"> </asp:contentplaceholder> </asp:content> <asp:content id="content4" contentplaceholderid="contentplaceholder_footer" runat="server"> <asp:updatepanel runat="server" id="updatepanel" updatemode="conditional"> <contenttemplate> <asp:label id="datafrompage" ... ></asp:label> </contenttemplate> </asp:updatepanel> </asp:content>
button insde of "contentplaceholder_body_member" , label within of "contentplaceholder_footer"
to accomplish result need need create little alter on master page design code below:
on master-page place content-place-holder within update panel first:
<asp:updatepanel id="updatepanel1" runat="server"> <contenttemplate> <asp:label id="datafrompage" runat="server" text="label"></asp:label> <asp:contentplaceholder id="contentplaceholder1" runat="server"></asp:contentplaceholder> </contenttemplate> </asp:updatepanel>
then in content page have (almost same yours)
<asp:content id="content2" contentplaceholderid="contentplaceholder1" runat="server"> <asp:updatepanel id="updatepanel1" runat="server"> <contenttemplate> <asp:button id="button1" runat="server" text="button" onclick="button1_click" /> </contenttemplate> </asp:updatepanel> </asp:content>
finally in code-behind on button-click event assign value master page's label command code shown below:
protected void button1_click(object sender, eventargs e) { label mylabel = page.master.findcontrol("updatepanel1").findcontrol("datafrompage") label; mylabel.text = "this message content page"; }
and here result :
update 1
ok remember if have nested update panel way find command in 1 bit different if need create changes on other content page need forcefulness update panel create changes in code behind, code should this:
//your button control's event needs find update panel , label both:
protected void button1_click(object sender, eventargs e) { updatepanel myupdatepanel = page.master.master.findcontrol("contentplaceholder_footer").findcontrol("updatepanel") updatepanel; label mylabel = page.master.master.findcontrol("contentplaceholder_footer").findcontrol("datafrompage") label; mylabel.text = "this message content page"; myupdatepanel.update(); //force panel updated }
cheers
c# asp.net ajax updatepanel master-pages
Comments
Post a Comment