asp.net validators still posting back
I'm using the default validation that comes with .NET
The problem I am having is that even with JavaScript enabled on my browser, a basic validation is still allowing postback.
<asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button" />
My App is usihg UrlRewriting.Net... could thi开发者_JAVA百科s be the problem?
<urlrewritingnet rewriteOnlyVirtualUrls="true" contextItemsPrefix="QueryString" xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<!--Fix the WebResource JS Error-->
<add name="WebResourceFix" virtualUrl="^~/WebResource.axd(.*)" rewriteUrlParameter="IncludeQueryStringForRewrite" destinationUrl="~/WebResource.axd$1" ignoreCase="true"/>
<!--Fix the ScriptResource JS Error-->
<add name="ScriptResource" virtualUrl="^~/ScriptResource.axd(.*)" rewriteUrlParameter="IncludeQueryStringForRewrite" destinationUrl="~/ScriptResource.axd$1" ignoreCase="true"/>
<!--Allow Extensionless Pages-->
<add name="pageExtensionless" virtualUrl="^~/(.+)$" redirectMode="Permanent" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/$1.aspx" ignoreCase="true"/>
</rewrites>
</urlrewritingnet>
Try adding CausesValidation = True
on your button.
<asp:Button ID="Button1" runat="server" Text="Button" CausesValidation="True" />
Here are some suggestions on debugging problems like this:
- Use Fiddler or some other HTTP debugger to ensure that the page is correctly downloading the external JavaScript files used to provide client-side validation, and that these client-side files are being correctly returned from the server (that is, that they are not returning 404 or some other HTTP error code).
- Use Firebug to set a breakpoint and step through the JavaScript execution.
In your RequiredFieldValidator I would suggest that you try setting EnableClientScript="true"
. Hopefully that will fix the problem.
精彩评论