开发者

Validation summary control not showing message?

开发者 https://www.devze.com 2023-03-14 19:05 出处:网络
I have a page with TextBox to enter a Mobile Number. For that I have validated it using RequiredFieldValidator and RegularExpressionValidator

I have a page with TextBox to enter a Mobile Number. For that I have validated it using RequiredFieldValidator and RegularExpressionValidator with display=none:

And also I have placed a ValidationSummary Control

<asp:ValidationSummary ValidationGroup="mobile" ShowSummary="false" ID="vsValid"
    runat="server" ShowMessageBox="true" Enabled="true" 
    DisplayMode="SingleParagraph" />
<asp:TextBox ID="txtMobileNumber" runat="server" CssClass="Qinputbox"></asp:TextBox>
<asp:RequiredFieldValidator Display="None" ControlToValidate="txtMobileNumber" 
    ID="reqValidMobileNo" runat="server" ErrorMessage="*" 
    ValidationGroup="mobile"></asp:RequiredFieldValidator开发者_高级运维>
<asp:RegularExpressionValidator ControlToValidate="txtMobileNumber" Display="None"
    ID="regExValidMobileNo" runat="server" 
    ErrorMessage="Please enter a valid mobile number."
    ValidationExpression="^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9]
        (\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$"
    ValidationGroup="mobile"></asp:RegularExpressionValidator>

when I entered characters in the TextBox it is not showing the summary. What might be the problem?


From you code fragment: ShowSummary="false" Looks like a problem.


You should set either ShowSummary="false" to true or EnableClientScript="true". I'm assuming that you want the latter because you have ShowMessageBox="true".

Have a look: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.validationsummary.enableclientscript%28v=vs.71%29.aspx

Use this property to specify whether the ValidationSummary control updates itself using client-side script. When set to true, client-side script is rendered on the client to update the ValidationSummary control, if the browser supports that feature. When set to false, no client-side script is rendered on the client and the ValidationSummary control only updates itself on round-trips to the server. In this situation, the ShowMessageBox property has no effect.


In web.config setting:

<httpRuntime targetFramework="4.5"/>

This setting turns off Javascript injection of validation (client side). Remove this and retry.


Ensure that you do NOT have this in the web.config file:

<xhtmlConformance mode="Legacy"/>

0

精彩评论

暂无评论...
验证码 换一张
取 消