Click here to Skip to main content
15,035,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Friends,
I am using C# ASP.NET 2010

I have a Textbox with TextMode="MultiLine" and need to validate using
<asp:regularexpressionvalidator>

of course it validates, but doesn't move to next view on clicking button after validation

please help me.
thanks
ravi

What I have tried:

I tried this
In the design page....
ASP.NET
<asp:textbox id="txtdetail" runat="server" autopostback="false" height="56px" width="240px" textmode="MultiLine" maxlength="200" required="">

<asp:regularexpressionvalidator id="RequiredFieldValidator28" runat="server" errormessage="Alphabet, Numbers and Space are allowed." controltovalidate="txtdetail" validationexpression="^[a-zA-Z0-9 ,]+$">


<asp:button id="Button3" runat="server" onclick="BtnGoToOtherDetail_Click" text="To Other Detail">

In the CodeBehind......
C#
protected void BtnGoToOtherDetail_Click(object sender, EventArgs e)
{
    MultiView1.ActiveViewIndex = 2;
}
Posted
Updated 5-Aug-21 23:14pm
v2
Comments
SeeSharp2 27-Jul-21 13:41pm
   
1. Format the question so that we can read it.
2. What do you mean it does validate but doesn't move to next view?

Your regular expression doesn't allow new-line characters. If you enter more than one line of text in the textbox, the validation will fail.

If you want the field to be required, you'll also need a required field validator.
ASP.NET
<asp:requiredFieldValidator runat="server" controlToValidate="txtdetail" errorMessage="You must enter the detail." />

<asp:regularExpressionValidator runat="server" controlToValidate="txtdetail" validationExpression="^[a-zA-Z0-9 ,\n]+$" errorMessage="Alphabet, Numbers and Space are allowed." />

You also need to check the Page.IsValid property in your code-behind event handler.
C#
protected void BtnGoToOtherDetail_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
        MultiView1.ActiveViewIndex = 2;
    }
}
   
Comments
ravitv 10-Aug-21 5:10am
   
Wow great Richard, It works,
Thank you so much.
Ravi.
Hi Sorry for late reply,
The format was not correct - I agree - and that happened due to some malfunctioning of this site at the time of posting this question.
Anyway here I post it again.
....
......

of-course it validates, but doesn't move to next view(I have 5 MultiView1.ActiveViewIndex = 1;) on clicking button after validation.

...
....

But I tried using "Required" property

<asp:textbox id="txtdetail" runat="server" cssclass="inputtxt" textmode="MultiLine" maxlength="100" required="">

It works, But I want the user NOT to enter any other character except AlphaNumeric, Hyphen, Space and Dot.
I tried Regular Validation like

<asp:regularexpressionvalidator id="RegularExpressionValidator10"
="" controltovalidate="txtdetail" validationexpression="[a-zA-Z0-9\s-.]*$" display="Static" enableclientscript="true" errormessage="Details ?" forecolor="Red" runat="server">

But it doesnt validates.
What mistake did i commit?
Please help,
Thanks
Ravi
   
Comments
Richard Deeming 6-Aug-21 5:08am
   
If you want to reply to a comment, click the "Reply" button next to that comment.

If you want to update your question, click the green "Improve question" link and update your question.

Do not post your comment or update as a "solution" to your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900