<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Height="146px"
Width="308px">
<Columns>
<asp:TemplateField HeaderText="Original Price" ControlStyle-Width="100px">
<ItemTemplate>
<asp:TextBox ID="txtOriginalPrice" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtOriginalPrice"
ValidationGroup="GridView1" Display="Static" ErrorMessage="" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I am using above code but its not working though I have put requirefield validator it does not show me the '*'
Yes, your requiredfieldvalidator is certainly there, and it knows which control to validate.What is missing is "when to validate that control".And to answer this question you need to add your textbox the same ValidationGroup with your requiredfieldvalidator and also the control(this can be a button for example) causes to do a validation.So your code will be like
<%--<asp:Button ID="Button1" runat="server" ValidationGroup="GridView1" Text="Benjamin"...Somewhere in your code--%>
<asp:TextBox ID="txtOriginalPrice" runat="server" ValidationGroup="GridView1"></asp:TextBox>
So don't forget these question
What to validate?(a textbox)
When to validate?(after a button click)
After what action try to validate?(a button click)
With what to validate?(a requiredfieldvalidator)
All of these controls must have the same ValidationGroup.
In case you need the validation to be performed then check for something like this
<asp:Button ID="btnAdd" runat='server' ValidationGroup='GridView1' CausesValidation='true'.....
So now when you click the add button it will validate for those controls falling under the validation group you mentioned else the default value is "" hence you won't find any validation triggered.
Add ValidationGroup to TextBox (txtOriginalPrice), Button and other controls.
Related
I have a web application which has a gridview with first column as checkbox.
<asp:TemplateField HeaderText="Select" >
<HeaderTemplate >
<asp:CheckBox ID="chkboxSelectAll" runat="server" AutoPostBack="true" />
</HeaderTemplate>
<ItemTemplate>
<input id="chkSelect" name="chkboxSelect" runat="server" type="checkbox" onclick='CheckedChanged'/>
</ItemTemplate>
</asp:TemplateField>
And also there is a onselect event for input(checkbox) written in code behind where I will highlight the row based on whether the checkbox is checked or not.
My problem is when I check the input checkbox, the onselect event is not getting invoked. Can anyone know whats causing this issue?
Thanks in advance.
Use asp:checkbox with autopostback=true instead of HTML control
use this code.
replace html input to asp:checkbox on itemtemplate and assign new event OnCheckedChanged instead of onclick event
<asp:TemplateField HeaderText="Select" >
<HeaderTemplate >
<asp:CheckBox ID="chkboxSelectAll" runat="server" AutoPostBack="true" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true" OnCheckedChanged='CheckedChanged'/>
</ItemTemplate>
I have a Panel control that contains some control such as text boxes.I want to use asp.net validators to validate text boxes.But if Panle is disabled then text boxes become disabled but validators such as RequiredFieldValidator validate disabled text box.
<asp:Panel ID="Panel1" runat="server" Enabled="false">
<asp:TextBox ID="TextBox2" runat="server" />
<asp:RequiredFieldValidator runat="server" ErrorMessage="RequiredFieldValidator"
ForeColor="#FF3300" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
</asp:Panel>
How I can set for validators that don't validate disabled controls?
if some control is disabled you can set its property CausesValidation="False"
<asp:Button id="Button1" runat="server"
Text="Cancel" CausesValidation="False">
</asp:Button>
EDITED
can you do this way
if (!panel.Enabled)
{
RequiredFieldValidator1.Enabled = false;// disable your all validators
}
Add this line in Page_Load()
RequiredFieldValidator1.Enabled = panel.Enabled;
I want to use the gridview command button (edit) with the jquery not postback. Please help me.
Place an asp button in another item template and set its CommandName property to edit. This will work simillar to default edit button in grid view. Then you can call javascript function and perform your logic.
See the code below:
Remove the following line to avoid default edit button:
<asp:CommandField ShowEditButton="true" ShowCancelButton="true"/>
Add the following instead:
<asp:TemplateField HeaderText="headerName" >
<ItemTemplate>
<asp:Button ID="Button1" CommandName="edit" runat="server" Text="Button" />
</ItemTemplate>
</asp:TemplateField>
Hope this helps you..
I think you can do it in a gridview.What you need is to columns with textbox and display the data in the textbox and needs a button at the end .
<asp:TemplateField >
<HeaderTemplate>
Values
</HeaderTemplate>
<ItemTemplate>
<asp:textbox ID"txt" runat="server" cssclass="abc" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Spares">
<HeaderTemplate>
Edit column
</HeaderTemplate>
<ItemTemplate>
<asp:button id="abc" runat="server" text="save" cssclass="pqr" />
<input type="hidden" runat="server" value="" />
</ItemTemplate>
</asp:TemplateField>
Store the Id in a hidden field and it is possible to get the value of text box and hidden feild via jquery.
gridview will be rendered as html table and using parent() we can able to find the clicked row and after finding the row u can use find() to find the values in the txtbox and hidden feild. Use $ajax() or $post() to send data to server.
I have a validation summary inside a asp.net formview and the validators just don't seem to trigger the validation summary.
Things I already tried:
Enable the ViewState on everything.
Set the ClientID to static.
Set the ValidationGroup to the same group on both all validators and the summary.
Used Google to search for a solution.
Anyone has any ideas on how to handle this?
Code. Formview declaration:
<asp:FormView ID="FormViewPerson" runat="server" DataSourceID="ObjectDataSourcePerson"
DefaultMode="Edit" OnItemUpdating="FormViewPerson_ItemUpdating" OnItemCommand="FormViewPerson_ItemCommand"
OnItemUpdated="FormViewPerson_ItemUpdated" Width="100%">
Any of the textboxes with the validator:
<td> <asp:TextBox ID="NumberTextBox" runat="server" Text='<%# Bind("Number") %>'
TabIndex="10" CausesValidation="True" ClientIDMode="Static" />
<asp:RequiredFieldValidator ID="RequiredFieldValidatorNumber" runat="server" ControlToValidate="NumberTextBox"
ErrorMessage="Number is Required" ForeColor="Red"
ValidationGroup="EditPerson">*</asp:RequiredFieldValidator>
</td>
And the submitbutton:
<asp:ValidationSummary ID="ValidationSummaryPerson" runat="server"
ForeColor="Red" ClientIDMode="Static" CssClass="validation"
ShowMessageBox="True" ValidationGroup="EditPerson" ViewStateMode="Enabled"
/>
<asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Save" ValidationGroup="EditPerson" CssClass="ButtonStyle" TabIndex="90" />
<asp:Button ID="EditCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel" CssClass="ButtonStyle" TabIndex="100"
ValidationGroup="EditPerson" />
Hope the CausesValidation for the button is set to true.
Well, I fixed the issue. If anyone else encounters this problem try the following:
Ensure there is only one (1) validation group on the entire form.
Set "causesvalidation" to "true" on the submitbutton.
Check, double check and triple check the spelling of your validationgroup property on all relevant controls.
Be on the lookout for javascript errors in your client-side scripts. They can cause havoc.
I have a textbox and I have set required validationcontrol on it on click of a button.
<asp:TextBox runat="server" ID="name" Width="120"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvname" runat="server" ControlToValidate="name" ErrorMessage="Name is required" Display="Dynamic" />
</td>
but the problem is when I am clicking on modify shared webpart and when I click on APPLY or OK button it is not saving as my form is empty . and I can't put
CausesValidation="false" on that button as this button is by default in sharepoint.
Any idea how to resolve this...?
You can use the ValidationGroup property to group all the Validators and validation fields together.
Yes using the ValidationGroup tag will help to relate the controls in a single form and will tell the submit button which fields are associated. Also make sure you have a ValidationSummary control on the page with the same ValidationGroup value. Also consider adding an InitialValue="" onto the TextBox control.
<asp:ValidationSummary ID="vs1" ShowMessageBox="true" ShowSummary="false" DisplayMode="List" runat="server" ValidationGroup="Form" HeaderText="There were problems with your submission:" />
<asp:TextBox runat="server" ID="name" Width="120"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvname" ValidationGroup="Form" runat="server" ControlToValidate="name" InitialValue="" ErrorMessage="Name is required" Display="Dynamic" />
<asp:LinkButton ID="lnkSubmit" Text="Submit" OnClick="lnkSubmit_Click" ValidationGroup="Form" runat="server"></asp:LinkButton>