i am using two panels (login and registration) in asp.net where in both panels i used button control. and i also used validations for particular textboxes in both panels.
i want to show both panels at same time.
now what problem i am facing is that when i click on button of login panel, it shows validation error text in registration panel and vice-versa..
Is there nay other way to use any other control instead of button.
i am using visual studio-2008
i had created login panel as:
<asp:Panel ID="pnllogin" runat="server">
<table class = "style1">
<tr>
<td>
<asp:Label ID="lblloginid" runat="server" Text="Login_ID" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtboxloginid" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="requiredfieldvalidator1" runat="server"
ControlToValidate="txtboxloginid" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblpassword" runat="server" Text="Password" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtboxpassword" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="requiredfieldvalidator2" runat="server"
ControlToValidate="txtboxpassword" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:HyperLink ID="hyperlinkforgotpassword" runat="server" ForeColor="Red" NavigateUrl="~/ForgotPassword.aspx">Forgot Password??</asp:HyperLink>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:ImageButton ID="imgbtnlogin" runat="server" ImageUrl="~/images/login.png"
onclick="imgbtnlogin_Click" />
</td>
</tr>
</table>
</asp:Panel>
and somewhat same code for registration panel..
can someone please help me..
Make use of ValidationGroup property to fire the validation message related to proper panel
here is detail info : http://www.w3schools.com/ASPNET/prop_webcontrol_imagebutton_validationgroup.asp
demo : http://www.w3schools.com/ASPNET/showasp.asp?filename=demo_prop_webcontrol_imagebutton_validationgroup
Specifying Validation Groups
Related
The code below has always worked, but now somehow I can't submit the form anymore even though I provide both username and password. I get no errors in backend or the Chrome Developer Console. I tried enabling/disabling all validators and found that if I add Enabled="false" to validator UserNameRequired, the form does submit. But obviously I want to have this requiredfieldvalidator enabled.
Why is this happening?
You can also see it live here (fill in a random email address/password): http://www.zorgbeurs.nl/login
<table width="300">
<tr>
<td>
<asp:Label ID="UserNameLabel" Text="Email" runat="server" AssociatedControlID="UserName"/>
</td>
<td>
<asp:TextBox ID="UserName" Text="" runat="server" Width="160px"/><br />
<asp:RequiredFieldValidator Enabled="false" ValidationGroup="loginuser" Display="Dynamic" SetFocusOnError="True" ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="*"/>
<asp:RegularExpressionValidator ControlToValidate="UserName" ValidationGroup="loginuser" ErrorMessage="Ongeldig emailadres" ValidationExpression="<%$resources:glossary,regexValidEmail %>" ID="revUsername" runat="server" Display="Dynamic"/>
</td>
</tr>
<tr>
<td valign="top">
<asp:Label ID="PasswordLabel" Text="<%$ Resources:Glossary,Password%>" runat="server" AssociatedControlID="Password"/>
</td>
<td valign="top">
<asp:TextBox ID="Password" runat="server" TextMode="Password" Width="160px"/><br />
<asp:RequiredFieldValidator Enabled="false" SetFocusOnError="True" Display="Dynamic" ValidationGroup="loginuser" ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="*" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:ImageButton CausesValidation="true" ValidationGroup="loginuser" ID="LoginMember" meta:resourcekey="ibtnLogin" CommandName="Login" runat="server"/>
<asp:CheckBox TextAlign="Right" CssClass="cblist" Font-Bold="false" ID="RememberMe" runat="server" Text="<%$ Resources:Glossary,loginrememberme%>" /><br />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="FailureText" runat="server" ForeColor="Red" Font-Bold="true" EnableViewState="False"/>
</td>
</tr>
</table>
update
I also tried adding the ValidationExpression of revUsername expression directly in the code [-+.'\w]+#[-.\w]+\.[-.\w]+, but that does not help.
I can see the required validators working in your live site without making a postback.
Regarding the email's regular expression validator, it seems that your expression is not working properly. So, I suggest you to change your regular expression, try this one:
<asp:RegularExpressionValidator Enabled="true" ControlToValidate="UserName"
ValidationGroup="loginuser" ErrorMessage="Ongeldig emailadres"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
ID="revUsername" runat="server" Display="Dynamic" />
Also, remember to enable it again in order to make it work both on client and server side.
Hope it can help you!
I have a basic ASP.NET website which has a register page with the user name, password and email as text boxes. Only one of them, the email, has a validation which is the default email validation from ASP.NET.
After the validation, I want the cursor to be in the email textbox if the validation fails.
Currently the message is displayed but the cursor is not on the page.
<tr>
<td>
<asp:TextBox ID="txtPassword" runat="server" CssClass="cpTextBox" TextMode="Password"
TabIndex="7" ToolTip="Password must be at least six characters in length"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvPassword" runat="server" ControlToValidate="txtPassword"
ErrorMessage="Please enter password" Display="None">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revPassword" runat="server" ControlToValidate="txtPassword"
ErrorMessage="Password must be at least six characters in length" ValidationExpression=".{6,50}"
Display="None">*</asp:RegularExpressionValidator>
</td>
<td>
<asp:TextBox ID="txtTitle" runat="server" CssClass="cpTextBox" TabIndex="11"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblVerifyPassword" runat="server" CssClass="cpLabel" Text="Verify password"></asp:Label>
<asp:Label ID="Label4" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:Label ID="lblPhone" runat="server" CssClass="cpLabel" Text="Phone"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtVerifyPassword" runat="server" CssClass="cpTextBox" TextMode="Password"
TabIndex="8"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvConfirmPassword" runat="server" ControlToValidate="txtVerifyPassword"
ErrorMessage="Please verify the password" Display="None">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvVerifyPassword" runat="server" ControlToCompare="txtPassword"
ControlToValidate="txtVerifyPassword" ErrorMessage="Please verify the password"
Display="None">*</asp:CompareValidator>
</td>
Can someone guide me on how to do this?
Regards.
For the validator control please set SetFocusOnError="true"
I i'm using more than 1 validation for a text box in that case if 1st validation is not passed then the second validation is showing after some blank space that is for 1st validator.In my project for email textbox i'm using two validation requiredfield and regular expression but my regular expression validator not showing on right place.I tried css i.e left-margin but that not works for me.
my code is
First Name
Last Name
Email Id
</td>
</tr>
<tr>
<td>
User Id
</td>
<td>
<asp:TextBox ID="TextBox7" runat="server" EnableViewState="true" Height="22px" Width="189px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox7"
ErrorMessage="It is a mandatory field Can't be left blank" ForeColor="#FF3300"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" EnableViewState="true" TextMode="Password" Height="22px" Width="189px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ForeColor="#FF3300" ControlToValidate="TextBox4" ErrorMessage="It is a mandatory field Can't be left blank"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Full Address
</td>
<td>
<asp:TextBox ID="TextBox5" runat="server" Height="64px" TextMode="MultiLine" Width="189px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ForeColor="#FF3300" ControlToValidate="TextBox5" ErrorMessage="It is a mandatory field Can't be left blank"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Mobile No.
</td>
<td>
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ForeColor="#FF3300" ControlToValidate="TextBox4" ErrorMessage="It is a mandatory field Can't be left blank"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ForeColor="#FF3300" ControlToValidate="TextBox6" ErrorMessage="Not in the correct format"
MaximumValue="9999999999" MinimumValue="1000000000"></asp:RangeValidator>
</td>
</tr>
</table>
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/img/str/buttons/submit_blue.png" onclick="ImageButton1_Click" />
Try setting your validator's Display property to Dynamic. The default value for that property is Static, which means your validator's html is rendered with the visibility:hidden css rule, while with Dynamic it gets a display:none css rule instead. The visibility:hidden css rule will leave empty whitespace in place of an element, display:none won't.
you should divide the sections of data and validators. a Table will be fine or div sections
As you can see - if you put a table with td's so each side will have its own td. so when the break line occurs , the new line will be beneath the first one.
Also you will have to make some float:left inside you html for the red lines.
In a same manner , you can use div with fixed width.
Background: I have a bundles listbox that inherits values from the carriers listbox once a carrier is selected via a web service.
I have a validationGroup on the button, I used Page.IsValid on the click handler and it says "Nothing".
When i select different carriers in IE8 it resets the other form values but not in IE9.
With Autopost=false on the lbCarriers, the Bundles listbox wont load any data.
With CausesValidation="true" in "lbCarriers", Bundles listbox wont load any data either Do you know how to do that w Ajax?
Do you know how I could do this w/ Ajax?
Problem: Using the required field validator on the bundles listbox is returning an a false erorr when I have bundles selected. When I click the Send Button, I get the "Select At Least 1 Bundle" Error Message but the invitation still sends out an i get an email.
Here's a screenshot of the application:
asp.net code on default.aspx page:
<tr>
<td class="style5">
Carrier:<br />
<font size="1">*Hold Ctrl Key Down to Select Multiple Carriers</font></td>
<td bgcolor="#ffffff" class="style7">
<asp:ListBox ID="lbCarriers" SelectionMode="Multiple" AutoPostBack="true"
runat="server" Height="86px" Width="250px" ValidationGroup="ValidationGroup">
</asp:ListBox>
</td>
<td bgcolor="#ffffff" class="style2">
<asp:RequiredFieldValidator ID="CarrierValidator" runat="server" Text="*"
ErrorMessage="Select At Least 1 Carrier" ControlToValidate="lbCarriers"
ValidationGroup = "ValidationGroup" ForeColor="Red" ></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Bundles:<br />
<font size="1">*Hold Ctrl Key Down to Select Multiple Bundles</font></td>
<td bgcolor="#ffffff" class="style6">
<asp:ListBox ID="bundles" SelectionMode="Multiple" runat="server" Height="86px"
Width="250px" Enabled="True"
ValidationGroup="ValidationGroup" CausesValidation="True">
</asp:ListBox>
</td>
<td bgcolor="#ffffff" class="style2">
<asp:RequiredFieldValidator ID="BundleValidator" runat="server" Text="*"
ErrorMessage="Select At Least 1 Bundle" ControlToValidate="bundles"
ValidationGroup = "ValidationGroup" ForeColor="Red" ></asp:RequiredFieldValidator>
</td>
</tr>
<asp:Button ID="Send_Button" runat="server"
Text="Send Invitation" ValidationGroup="ValidationGroup" Width="123px"/>
<br />
<asp:Label ID="Send_Success" runat="server" Text="Invitation sent!" Visible="false"></asp:Label>
<br />
<asp:ValidationSummary ID="ValidationSummary" runat="server" ForeColor="Red"
ValidationGroup="ValidationGroup" />
Question: What alternate code or work-around do you recommend for this issue?
Thanks for looking!
EDIT:
Add CausesValidation="true" in "lbCarriers"
I have removed Autopost="true" from first listbox i.e. "lbCarriers" and it is working now.
i have a RegularExpressionValidator to validate an Email input that i have,
it works perfectly, if the input matches the Regular-expression,
However,if i enter a mistaken email it would show an error msg, if i fix the email in the input , it doesnt recheck it, the error msg stays not allowing me to click the Registeration button-or more like it gets clicked, but no event gets fired-
EDIT: added the ASPX code
< table width="100%">< tr><td>Username:</td>
<td>
<input runat="server" id="txtUsername" type="text" size="30" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtUsername" ErrorMessage="*"></asp:RequiredFieldValidator
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="Username has to be atleast between 4-8 "
ValidationExpression="[A-Z]{4-8}"
ControlToValidate="txtUsername"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td> Email:</td><td>
<input runat="server" id="txtemail" type="text" size="30" /></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtemail" ErrorMessage="*">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtemail" ErrorMessage="Format must be: abc#abc.com"
ValidationExpression="^[A-Za-z0-9._%+-]+#([A-Za-z0-9-]+\.)+([A-Za-z0-9]{2,4}|museum)$">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" ForeColor="red" ID="lblerror"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button runat="server" Text="Register"
ID="btnSubmit" Width="118px" onclick="btnSubmit_Click" />
</td>
</tr>
</table>
Are you checking for Page.IsValid in your btnSubmit_Click method?
Also your validation expression for username doesn't look correct, use a comma between your min and max lengths.
ValidationExpression="[A-Z]{4-8}"
ValidationExpression="[A-Z]{4,8}"