Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a TextBox with autoPostBack Set to true with a RequiredFieldValidator

<asp:TextBox ID="txtLaborID" runat="server" AutoPostBack="True"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtLaborID" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>


And on TextChanged in ocdeBehind I have the code.

The problem is when I have text it in and empty this text and press tab the page is posting back this should not happen since I have RequiredFieldValidator. Why it is posting back?
Posted
Comments
You have not declared the event inside TextBox? Are you really using? Please correct the code again in that case.
[no name] 2-Nov-13 3:52am    
I don't need to declare the event? What do you mean?
If you have not declared in mark up of TextBox in aspx page, then how it is going to TextChanged event?
JoCodes 2-Nov-13 4:03am    
Any Particular reason for the autopostback set to true?
[no name] 2-Nov-13 5:20am    
Yes I am getting his name after inserting his ID. This code in the TextChanged in code behind

Refer the links below which deals with similar issue

http://forums.asp.net/t/1919818.aspx?TextBox+CausesValidation[^]

http://forums.asp.net/t/1119411.aspx[^]

Hope this helps...
 
Share this answer
 
Comments
[no name] 5-Nov-13 2:01am    
Thanks
JoCodes 5-Nov-13 2:24am    
Happy to see that it helped you...
Quote:
why page is PostBack when I have a RequiredFieldValidator


The page get postback because of Autopostback property of textbox.
Refer here:
TextBox.AutoPostBack Property [^]
 
Share this answer
 
Comments
[no name] 2-Nov-13 3:57am    
Ok But I have a required field validator why it is not stopping it from post back?
Tom Marvolo Riddle 2-Nov-13 4:03am    
Require field validator is used for validation for specific control.for eg.user must provide value for a particular control(textbox/dropdown...).He/She cannot skip it .required field validator have no connection with postback
Tom Marvolo Riddle 2-Nov-13 4:04am    
if you want to send particular value of a page to server instead of sending whole thing use Update Panel
[no name] 2-Nov-13 4:15am    
Iam already using update panel for this textbox

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