Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,
I'm having trouble validate a simple control in a form.
the form is in a content page (I'm using masterpage- just saying incase it's relevant)
when I click the button, if it's empty - the validation works, BUT - when I enter text in the textbox (meaning -the page is valid) there's no postback- the button doesn't go to the server and do what I want..

what can be the problem?

there's example of my code:

HTML
<table>
<tr>
<td><asp:TextBox ID=txtEmail runat=server </asp:TextBox>
<asp:RequiredFieldValidator ID=rfvEmail runat=server
ControlToValidate=txtEmail errormessege=Please enter your email> </asp:RequiredFieldValidator></td></tr>
<tr><td><asp:Button ID=btnSave runat=server Text=Save OnClick=btnSave_Click> </asp:Button>
</td></tr></table>


VB
protected sub btnSave_Click(sender  as object, e as  EventArgs)
{
    If (page.isvalid) then
     ....
    End if
}
Posted
Updated 9-Oct-12 23:15pm
v3
Comments
danait25 10-Oct-12 7:44am    
I looked about my code again and relized I have one more validator- range validator and after checking everything around the code it seems like the range validator is the one that causing the problem.
Can you tell me what's wrong?

<asp:rangevalidator id="xx" runat="server" controltovalidate=txtEmail minimumvalue=1 maximumvalue=11>

I think it might be going, just put an alert before "If(page.Isvalid)"

Or a breakpoint on the function and check value of Page.IsValid
 
Share this answer
 
Comments
danait25 10-Oct-12 5:03am    
I've already put a breakpoint on the function but when i click the button nothing happens - I can't get there - it doesnt go to the serverside at all.. :/
Code for designer page :

C#
<asp:TextBox ID="TextBox1" runat="server" MaxLength="11"  oncopy="return false" oncut="return false" onpaste="return false"></asp:TextBox>
       <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
           ControlToValidate="TextBox1" ErrorMessage="cannt be blank"
           ValidationGroup="myValidator"></asp:RequiredFieldValidator>
       <br />
       <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"
           style="height: 26px" ValidationGroup="myValidator" />



Mark my answer , if it fulfills your requirement.

Thanks,

Arshad
 
Share this answer
 
v2
Comments
danait25 11-Oct-12 1:30am    
sorry, that didn't work as well
My problem is with the rangevalidator and not with the RequiredFieldValidator .. and I tried to add them all to the same validationgroup but nothing happened.
arshad alam 11-Oct-12 2:07am    
what do you want to validate , kindly elaborate it ?
danait25 16-Oct-12 4:34am    
I want to validate 2 things:
1.the textbox isn't empty
2.no more than 11 chars allowed.
If I use the "maxlength" in the textbox it limits the number of characters a user can enter, but it doesn't help in case of "copy paste" for example..
arshad alam 16-Oct-12 5:20am    
check the updated solution.
Attiq-ul Islam 22-Jan-14 8:31am    
Thanks for the solution.

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