focus on required fields in Asp.Net Tab Control in asp.net - c#

net application, in that i have many required field text boxes in Tabcontrol in both tab panels.
when i have clicked submit button, it only focus current tab text box controls,
but when i filled all the current tab panel controls then press submit button,
i want to focus the next tab panel text box which is empty,
but it can't focus on another tab panel textbox.
i don't know how to focus this, please any body let me know.
required="required"
<td><asp:Label ID="lblCustomerMobileNo" runat="server" Text="Customer Mobile No" CssClass="label"></asp:Label></td>
<td><asp:TextBox ID="txtCustomerMobileNo" runat="server" CssClass="smalltextbox" PlaceHolder="Customer Mobile No" Width="100px" MaxLength="10" OnKeypress="javascript:return onlyNumbers(event,this.value);"
required="required" /> </td>
when i am in TAB 4, i press save button it focus required text box.
but i filled customer mobile no, and then press save button TAB 0 also having some required field text boxes but its not focus..

you can use javascript function to check fields and focus in tab which has empty field.
or in server side check fields and set active tab

If you use the build-in aspnet Validation Controls, you have the SetFocusOnError property.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Field is required" ValidationGroup="myForm" ControlToValidate="TextBox1"
SetFocusOnError="true"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="myForm" />

Related

asp.net can't press "back" button because of field validator

I have some textboxes in my asp.net site and also some field validators for that textboxes.
Now I've added a "back" button to go back to another page, but I can't press the button when not every field is filled.
Do you have any sugestions how to solve this problem?
aspx:
<asp:TextBox ID="tbInformation" runat="server" TextMode="MultiLine" Height="130px" Width="550px" />
<asp:RequiredFieldValidator runat="server" ID="rfvInformation" ControlToValidate="tbInformation" ErrorMessage="*Required*" />

asp.net textbox doesn't populate after postback

I am using ASP.NET and C# couple text boxes to calculate results entered. Textbox2 has a value entered and on button click Textbox1 gets populated. This works fine the first time I enter the value. But the second time I change the value in Textbox2, I see that the value is being assigned to Textbox1 while debugging on Button click, but doesn't show up on the screen. I have many other controls and a master page. The textboxes are within an update panel.
Can someone help me what's going on?
Here is the code:
<asp:TextBox ID="Textbox1" runat="server" Width="150px" TabIndex="6" MaxLength="8"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="TextBox1" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:TextBox runat="server" ID="Textbox2" Width="150px" Visible="false"></asp:TextBox>&nbsp
<asp:ImageButton runat="server" ID="imgCalcAdjRate" ImageUrl="~/Resource/Images/calrate_0.bmp" onmouseout="this.src='../Resource/Images/calrate_0.bmp'" onmouseover="this.src='../Resource/Images/calrate_1.bmp'" Height="25px" Width="25px" Visible="false" onclick="imgCalcAdjRate_Click" />
Check the postback in the page_load function.
if(!Page.IsPostBack) {
}
I think you are loosing information on post back. The data is changed, but it get reset on post back.

Sliding (or moving) controls in ASP.NET with just javascript

Because of how my page is set up, I can not send postBack events and reload the page with controls in new positions. Therefore, I need to move controls around using javascript.
If I were to have 3 radio buttons on my UI, and when one of the radio buttons is clicked in the list, I want to be able to slide the other radio buttons down and have the clicked radio button show new text boxes, drop down lists, etc, to gain more information from the user. Code example:
(When no radio buttons are clicked)
<asp:RadioButton ID="radioYes" GroupName="group1" Text="Yes, I'll give you more information." runat="server" /><br />
<asp:RadioButton ID="radioMaybe" GroupName="group1" Text="Not sure yet." runat="server" /><br />
<asp:RadioButton ID="radioNo" GroupName="group1" Text="Nope." runat="server" /><br />
Once the 'yes' radio button is pushed, I want to have 'maybe' and 'no' slide down and leave room as if I had this coded up:
<asp:RadioButton ID="radioYes" GroupName="group1" Text="Yes, I'll give you more information." runat="server" /><br />
<asp:Label ID="labelName" Text="Name" runat="server" /><br />
<asp:TextBox ID="textBox" runat="server" /><br />
<asp:RadioButton ID="radioMaybe" GroupName="group1" Text="Not sure yet." runat="server" /><br />
<asp:RadioButton ID="radioNo" GroupName="group1" Text="Nope." runat="server" /><br />
And the opposite effect could happen too: When 'yes' is unclicked, the radio buttons slide back up.
Maybe you can use jQuery slideToggle(),or ajaxtoolkit PopupControl http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/PopupControl/PopupControl.aspx
My english is very poor ,But if you want have slide down you can use this.

Validation effects the entire form, no button can be pressed

I've got a page that contains a huge amount of controls, (gridviews, reportviewers, buttons etc.)
Now I've a couple of textboxes and dropdowns that represent a "form" user might want to fill up and submit by clicking a button. Some of these controls contain "RequiredFieldValidator"s.
<fieldset runat="server" >
<asp:Label ID="lblName" runat="server" Text="Name:" AssociatedControlID="txtName" />
<asp:RequiredFieldValidator ID="rfvTxtName" runat="server" ControlToValidate="txtName" Text="(Required)" />
<asp:TextBox ID="txtName" Width="175px" runat="server" />
....
....
</fieldset>
The problem I encounter is that no other button on the entire asp form can be clicked because of these validation controls.
The question is; how do I set this validation to only listen to that particular fieldset and not the whole page?
Set the ValidationGroup property of those controls to something unique.
More info here.
Set your controll's ValidationGroup property to make them one group . Like
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
ValidationGroup="MyGroup" />
The ValidationGroup property specifies which group of controls is
validated on validation. This property is mostly used when there are
several buttons in a form.
ASP.NET ValidationGroup Property
You ca also change property CausesValidation to False for control that you don't want to validate.

button and validators

I have a Table with two textboxes. Every textbox has a required validator to make the user insert data in the textbox.
I also have a Login table to confirm user privilages.
When I submit the button of login, the validators from the first table appear and prevent the user from logging in. I changed the login button property (Causes validation ) to false, but the validators which I added in the login table didn't appear.
So please how can I solve this problem.
I think you can solve your problem by using ValidationGroups. Here is an excerpt from a page with a longer explanation for you:
This page has two groups – a “Group1” and a “Group2” of validators. There are then two buttons on the page – when button1 is clicked, the first group of validators will fire. When button2 is clicked, the second group of validators will fire. Postback will be blocked client-side by default if the validation fails:
<html>
<body>
<form runat=“server”>
<asp:textbox id=“TextBox1” runat=“server”/>
<asp:requiredfieldvalidator ValidationGroup=“Group1”
ErrorText=“Need to Fill in Value!”
ControlToValidate=“TextBox1”
runat=“server”/>
<asp:textbox id=“TextBox2” runat=“server”/>
<asp:requiredfieldvalidator ValidationGroup=“Group2”
ErrorText=“Need to Fill in Value!”
ControlToValidate=“TextBox2”
runat=“server”/>
<asp:button text=“Group1” ValidationGroup=“Group1” runat=“server”/>
<asp:button text=“Group2” ValidationGroup=“Group2” runat=“server”/>
</form>
</body>
</html>
What you need to use is a ValidationGroup attribute on both the buttons and the validations. This allows certain actions to only enforce a subset of validators on the page when the button is clicked.
<asp:TextBox ID="txtA" runat="server" />
<asp:RequiredFieldValidator ID="rfvA" runat="server" ErrorMessage="Message." ControlToValidate="txtA" ValidationGroup="A" />
<asp:Button ID="btnA" runat="server" Text="A" ValidationGroup="A" />
<asp:TextBox ID="txtB" runat="server" />
<asp:RequiredFieldValidator ID="rfvB" runat="server" ErrorMessage="Message." ControlToValidate="txtA" ValidationGroup="B" />
<asp:Button ID="btnB" runat="server" Text="B" ValidationGroup="B" />
Now when btnA is clicked, it will only check whether rfvA is valid (checking txtA) and when btnB is clicked, it will only check whether rfvB is valid. And yes you can have multiple validation controls in the same validation group.
When you set the CausesValidation property to false, you were disabling all validation actions for the button, not just the ones you didn't want on.

Categories

Resources