asp.net - How to access page controls inside [WebMethod] method? -
asp.net - How to access page controls inside [WebMethod] method? -
i using ajax phone call method database method takes parameters page , gets values db want populate result page controls accessing these controls in web method.
below code. using collapsible panel extender. on click event collapses & should phone call verifyfunction method written in code behind.
<asp:toolkitscriptmanager id="toolkitscriptmanager1" runat="server" enablepagemethods="true"></asp:toolkitscriptmanager> <asp:panel id="panel1" runat="server"> </asp:panel> <asp:linkbutton id="linkbutton1" runat="server">linkbutton</asp:linkbutton> <asp:collapsiblepanelextender id="cpesop" runat="server" collapsecontrolid="linkbutton1" collapsedsize="0" collapsed="true" collapsedimage="~/imgages/addrow.gif" expandcontrolid="linkbutton1" expanddirection="vertical" expandedimage="~/imgages/addrow.gif" imagecontrolid="image1" suppresspostback="true" targetcontrolid="panel1">
<!-- javascript content --> <script type="text/javascript"> function pageload(sender,args){ $find("collapsiblebehavior").add_expandcomplete( expandhandler ); $find("collapsiblebehavior").add_collapsecomplete( collapsehandler ); } function expandhandler( sender , args ){ alert('i have expanded'); // newplanbudget.aspx/verifyfunction $.ajax( { url: "newplanbudget.aspx/verifyfunction", data: "flag=1", success: function (msg) { if (msg.d) { alert("sucess"); } } }); } function collapsehandler( sender , args ){ alert('i have collapsed'); }
the code behind
[webmethod]
protected void page_load(object sender, eventargs e) { cpesop.behaviorid = "collapsiblebehavior"; } public static void verifyfunction() { linkbutton1.text = "hello"; }
i think cannot access page controls in web method can homecoming results ajax , have results
and post sample code, dont know why calling page load in web-method,
and script must be
$.ajax( { url: "newplanbudget.aspx/verifyfunction", data: {flag="1"}, success: function (msg) { if (msg.d) { alert("sucess"); } } });
and must value in web-method as
public static void verifyfunction(string flag) { }
and give name link-button in design page itself
as
<asp:linkbutton id="linkbutton1" text="hello" runat="server">linkbutton</asp:linkbutton>
asp.net
Comments
Post a Comment