c# - textbox ontextchanged event is firing in update panel but throws error on client side -
i have 2 div on page. when first time page load shows first div has 2 radio button. if select second button postback , hides first div , shows second div. has textbox , dropdown inside update panel. insert text textbox , hit tab fire ontextchanged event. adding option inside dropdown. throws error on client side.
error : "microsoft jscript runtime error: sys.webforms.pagerequestmanagerparsererrorexception: message received server not parsed."
not sure here.
here aspx page.
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org /tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div id="divpanel1" runat="server"> <asp:label id="label1" runat="server" text="label : "></asp:label> <asp:radiobutton id="radiobutton1" groupname="lbl" text="me first" runat="server"/> <asp:radiobutton id="radiobutton2" groupname="lbl" text="me second" runat="server" autopostback="true" oncheckedchanged="radiobutton2_checkedchanged" /> </div> <div id="divpanel" runat="server"> <asp:scriptmanager id="scriptmanager1" runat="server"> </asp:scriptmanager> <asp:updatepanel id="updatepanel1" runat="server"> <contenttemplate> <asp:textbox id="textbox1" runat="server" autopostback="true" ontextchanged="textbox1_textchanged"></asp:textbox> <asp:dropdownlist id="dropdownlist1" runat="server"> <asp:listitem selected="true" value="0">select</asp:listitem> </asp:dropdownlist> </contenttemplate> </asp:updatepanel> </div> </form> </body> </html>
here code behind.
public partial class _default : system.web.ui.page { protected void page_load(object sender, eventargs e) { this.divpanel.visible = false; } protected void textbox1_textchanged(object sender, eventargs e) { this.dropdownlist1.items.add(this.textbox1.text.tostring()); } protected void radiobutton2_checkedchanged(object sender, eventargs e) { this.divpanel.visible = true; this.divpanel1.visible = false; } }
thank time.
the error u need put in update panel <div />
, <asp:textbox /> <asp:dropdownlist>
, becouse when control textbox execute event ontextchanged
not able update controls , doesn't work.
the new code aspx below :
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org /tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div id="divpanel1" runat="server"> <asp:label id="label1" runat="server" text="label : "></asp:label> <asp:radiobutton id="radiobutton1" groupname="lbl" text="me first" runat="server" /> <asp:radiobutton id="radiobutton2" groupname="lbl" text="me second" runat="server" autopostback="true" oncheckedchanged="radiobutton2_checkedchanged" /> </div> <asp:scriptmanager id="scriptmanager1" runat="server"> </asp:scriptmanager> <asp:updatepanel id="updatepanel1" runat="server"> <contenttemplate> <div id="divpanel" runat="server"> <asp:textbox id="textbox1" runat="server" autopostback="true" ontextchanged="textbox1_textchanged"></asp:textbox> <asp:dropdownlist id="dropdownlist1" runat="server"> <asp:listitem selected="true" value="0">select</asp:listitem> </asp:dropdownlist> </div> </contenttemplate> </asp:updatepanel> </form> </body> </html>
the new codebehind below:
protected void page_load(object sender, eventargs e) { if (!ispostback) { this.divpanel.visible = false; } } protected void textbox1_textchanged(object sender, eventargs e) { this.dropdownlist1.items.add(this.textbox1.text.tostring()); dropdownlist1.databind(); } protected void radiobutton2_checkedchanged(object sender, eventargs e) { this.divpanel.visible = true; this.divpanel1.visible = false; }
i hope help.
cheers.
Comments
Post a Comment