ASP.NET 3.5 :No Postback triggered for button click - asp.net

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" />

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

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?

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.

I had this same exact problem. The RequiredFieldValidator was working as expected when the textbox was empty, but the button click wasn't causing a postback when there was text. My problem? I was using the same validationgroup name in a separate user control. So make sure all of your validationgroup names are unique.

Related

move focus to another asp.net control after ajax toolkit calendar extender selection

I am having trouble finding an answer to this problem.
What I am trying to do is this;
I have an asp.net (aspx) page that has two text boxes on it (among other controls) that have an Ajax Toolkit Calendar Extender on them. The first text box get focus and the calendar control appears and I am able to select a date just fine.
Here is my problem. After the date is selected for the first text box with the calendar control I want the second text box to automatically have the same date entered into it and the focus moved to a button (btnSearch) not the second text box.
I am using VB in code behind. I must not be wording my searches correctly because I can't seem to find anything close to solving this.
Does anyone have any ideas as to how this can be done? I am open to using JQuery if I have to but would prefer not to.
Thanks for any help in advance.
Note: There is no code to show because I can't find anything to try.
Update:
Here is the html I have:
<asp:TextBox runat="server" ID="txbDateStart" CssClass="form-control input-lg" ReadOnly="true" Visible="false" OnTextChanged="txbDateStart_TextChanged"/>
<cc1:CalendarExtender ID="CalendarExtender1" PopupButtonID="imgPopup" runat="server" TargetControlID="txbDateStart" Format="MM/dd/yyyy" PopupPosition="Right" />
<asp:TextBox runat="server" ID="txbDateEnd" CssClass="form-control input-lg" Visible="false" ToolTip="Click to change End Date" ReadOnly="true" />
<cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txbDateEnd" Format="MM/dd/yyyy" />

asp.net validators ends up in same place

I'm writing an application with multiple validators (date, required, regexp for format) on the same page. They validate correctly, but they turn up in the same place. That is, they don't turn up next to the validated field, they are appended to another validation error message next to a completely other field.
Here goes example code snippets:
Number:
<asp:RegularExpressionValidator class="IMSIValidators" runat="server" ErrorMessage="Enter digits only, no other characters" ControlToValidate="IMSIRangeTextBox" Display="Dynamic" ValidationGroup="AllValidators" ValidationExpression="[0-9]+"></asp:RegularExpressionValidator>
<p class="IMSIEditLabels">Operator: <asp:TextBox ID="OperatorTextBox" runat="server"></asp:TextBox></p>
<asp:RequiredFieldValidator runat="server" class="IMSIValidators" Text="Enter the customer" ControlToValidate="OperatorTextBox" Display="Dynamic" ValidationGroup="AllValidators"></asp:RequiredFieldValidator>
<p class="IMSIEditLabels">Requested by:<asp:TextBox ID="RequestedTextBox" class="IMSIEditInputItems" runat="server" ValidationGroup="AllValidators"></asp:TextBox></p>
<asp:RequiredFieldValidator runat="server" Text="Enter a full name" ControlToValidate="RequestedTextBox" Display="Dynamic"></asp:RequiredFieldValidator>
I've tried all ways that I can think of, such as setting Display="Dynamic" and ValidationGroup="AllValidators". No combination works for me.
I've tried to set their position in a CSS class, but then they came up on top of each other (which is logical).
Any input is greatly appreciated. I'm getting SO frustrated :)
//Eva-Lotta

how to work with multiple forms in one asp.net page

I hava a asp.net that I thought is going to have multiple forms.I put a asp panel and added the form to it and validators to controls everyting works.but if I try to put another panel and a form page become invalid.the reason I do this is because any attempt to postback data will trigger all validtors.I know that I can brake each form to each page.but for my design this seems silly.
what im looking for a way to have multiple forms in one page.
or have validators work only on certain situations.
or group validators to work if the button click only happen in the same panel where validators reside.
You cannot place more than one form tag in a single ASPX page. It is a limitation of ASP.Net Web Form.
However, you can fake it with ValidationGroup. For example -
<%-- Group One --%>
<asp:TextBox ID="TextBox1" runat="server"
ValidationGroup="One" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
Display="Dynamic"
ValidationGroup="One"
ControlToValidate="TextBox1"
Text="Textbox one is required." />
<asp:Button runat="server" ID="Button1"
OnClick="Button1_Click"
Text="Submit"
ValidationGroup="One" />
<hr/>
<%-- Group Two --%>
<asp:TextBox ID="TextBox2" runat="server"
ValidationGroup="Two" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server"
Display="Dynamic"
ValidationGroup="Two"
ControlToValidate="TextBox2"
Text="Textbox two is required.." />
<asp:Button runat="server" ID="Button2"
OnClick="Button2_Click"
Text="Submit"
ValidationGroup="Two" />
Note: If you want multiple form tags in a single page, you might want to look at ASP.Net MVC.

ValidationSummary for display validation error messages

i am using validation control of asp.net . i got 10 fields and i have field validators with each of them . Now I want to show error but using ValidationSummary but errors also appear with individual validators. cant i close the individual error messages?
have you add a validation group.
try like this
<asp:ValidationSummary ID="ValidationSummaryVerifyInfo"
ValidationGroup="Verify" runat="server" DisplayMode="List"
ShowMessageBox="True" ShowSummary="False" />
<asp:RequiredFieldValidator ID="RFVEmail" runat="server"
ErrorMessage="Please enter Email Id." ForeColor="Red" SetFocusOnError="True"
ValidationGroup="Verify" ControlToValidate="TextBoxEmail">*</asp:RequiredFieldValidator>
To hide the validators you can place them into one div with CSS style display: none.

RequiredFieldValidator doesn't work when submitting form after Posting back by TextChanged event to the Textbox

In my .aspx form I have a text box with Autopostback=True.
I also set a RequiredFieldValidator next to it. But when Posting back by TextChanged event of my text box, my RequiredFieldValidator appears but still I can submit my form with nothing in the text box!
What is wrong, and how can I fix this?
You have to set the textbox's CausesValidation property to true (it's set to false by default for textboxes).
Give both the text box and the submit button the same validation group.
try this code
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ErrorMessage="*" ForeColor="Red" ControlToValidate="TextBox2" Display="Dynamic" runat="server" />
<asp:Button ID="btn" Text="button" CausesValidation="true" runat="server"/>
and make sure that ControlToValidate="" has same name as the <asp:texbox/>has
the best way to do is just right below TextBox field type <asp:Required and when the options come just pres TAB Button twice

Resources