Link to home
Start Free TrialLog in
Avatar of andrewmilner
andrewmilner

asked on

asp.net Form Validation i stopping OnClick event functioning

Okay so I had this function working fine which basically takes the postcode then looks up the address from code behind and then populates some other text boxes.

But now I have added the validation checks everytime I click the button to fire the onclick event the validation is fired and the onclick function isnt called.

Can you help?


<asp:TextBox CausesValidation="false" CssClass="GlobalFormTextBox" ID="PostCodeTextBox" runat="server" Text='<%# Bind ("Postcode") %>'></asp:TextBox>
 
<asp:RequiredFieldValidator runat="server"
id="reqPostCode" ControlToValidate="PostCodeTextBox"
ErrorMessage = "PostCode" Text="*"
display="Dynamic" />
 
<asp:ImageButton ID="CheckPostCode" runat="server" OnClick="CheckPostCodeButton_Click" ImageUrl="~/images/PostCodeLookupIcon.gif" AlternateText="Find Address" />
 
 
 
protected void CheckPostCodeButton_Click(object sender, EventArgs e) 
{
 
///some code in here
 
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of tiagosalgado
tiagosalgado
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is there a Validation Error, indicating that the textbox is empty?  If the textbox is empty, the OnClick won't fire, as the validation is checked first before even posting back.
Avatar of andrewmilner
andrewmilner

ASKER

Nice one.  Didnt think to add it to the button only the text box.
Many Thanks.