views:

1772

answers:

4

I have an ASP.NET page developed in VS 2008. there is a text box and login button.Required fireld validator and Validtion Group controls are associate for validation.I wrote code for the Button click evenet handler too.But the Button click is not getting fired.There is no post back happening. Can any one tell me why ?

HTM lmarkup

 <asp:TextBox ID="txtLoginPass" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtPassword" ValidationGroup="Login" ErrorMessage="Please enter password." runat="server" />


  <asp:Button ID="btnLogin" runat="server" Text="Login"
              onclick="btnLogin_Click" ValidationGroup="Login" />
+1  A: 

Validators generate client side JavaScript which can prevent a postback if the required field is empty.

sbreitzke
+1  A: 

Is that exact code snippet? It didn't work at all - no such control as txtPassword.

Altough, this worked as expected:

    <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtPassword" ValidationGroup="Login" ErrorMessage="Please enter password." runat="server" />
    <asp:Button ID="btnLogin" runat="server" Text="Login"
          onclick="btnLogin_Click" ValidationGroup="Login" />

I'm sure that you've got that correct in your code, so the problem must be somewhere else - could please post more code surrounding this snippet?

maciejkow
Yes i used the Wrong value in controlToValidate Thanks
Shyju
A: 

Yes, more of the code would be helpful. Is this contained in a tag with a runat="server" attribute? Also, have you tried putting a submitBehavior="true" attribute on the button?

ajh1138
A: 

I expect that you have AutoPostBack="True" on one of your components. If so then remove that and your onclick should work on the button.

James Black