simply have dropdownlist requiredfieldvalidatior in updatepanel on page, have enabled autopostback dropdownlist.
the problem dropdownlist selectedindex event not firing. unexpected behavior happens when validate page , ant error occurs.
i searched lot unable find solution
my code follows:
<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default" %> <!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> <script type="text/javascript"> function validateme() { if (page_clientvalidate("vgoption")) { alert("valid"); } return false; } </script> </head> <body> <form id="form1" runat="server"> <asp:scriptmanager id="smmain" runat="server"> </asp:scriptmanager> <asp:updatepanel id="pnlmain" runat="server" childrenastriggers="true"> <contenttemplate> <table border="1" cellpadding="5" cellspacing="0"> <tr> <td> option: </td> <td> <asp:dropdownlist runat="server" autopostback="true" id="opt" onselectedindexchanged="opt_selectedindexchanged" validationgroup="vgoption"> <asp:listitem text="--select option--" value="0" /> <asp:listitem text="upload" /> <asp:listitem text="download" /> </asp:dropdownlist> <asp:requiredfieldvalidator id="rfv" runat="server" controltovalidate="opt" display="none" initialvalue="0" validationgroup="vgoption" errormessage="please select option"></asp:requiredfieldvalidator> </td> </tr> <tr> <td> postback: </td> <td> <asp:label text="" id="lblmessage" runat="server" /> </td> </tr> <tr> <td> </td> <td> <input type="button" onclick="return validateme();" value="test" title="test" /> <asp:validationsummary validationgroup="vgoption" runat="server" showmessagebox="true" showsummary="false" displaymode="list" /> </td> </tr> </table> </contenttemplate> </asp:updatepanel> </form> </body> </html>
codebehind:
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; public partial class _default : system.web.ui.page { protected void page_load(object sender, eventargs e) { } protected void opt_selectedindexchanged(object sender, eventargs e) { lblmessage.text = "autopostback: " + datetime.now.tostring(); } }
steps repopulate issue:
1. click first option in dropdown
2. click on submit button
3. change dropdownlist value (this should fire selectedindex changed event, doesn't)
ps: not want postback happen when submit button clicked why added <input>
instead of asp.net button,
if add asp.net button doesnt work
replace
<input type="button" value="test" title="test" runat="server" validationgroup="vgoption"/>
with
<asp:button id="btn" runat="server" title="test" text="test" validationgroup="vgoption" onclientclick="return validateme()"/>
the issue solved.
Comments
Post a Comment