Why does the GridView's Command Buttons not fire properly when there are validation controls embedded in the ItemTemplate?
What is the point in allowing an EditItemTemplate if you can't even validate the user's input on the client side?!!!
The headache is not hard to reproduce, just create a simple GridView with at least one column that is an TemplateField. Place a text box and a RequiredFieldValidator on the EditItemTemplate.
Does anyone have a workaround for this issue/problem/headache?
I guess you don't have ValidationGroup for the Buttons. please try something like this:
<asp:Button ID="Button1" runat="server" ValidationGroup='GridView1' CausesValidation='true' Text="Button" />
You need to set ASPxTextBox ValidationGroup like this:
<EditItemTemplate>
<dx:ASPxTextBox ValidationSettings-ValidationGroup='<%# Container.ValidationGroup %>' ../>
</EditItemTemplate>
Look here for detailed explanation.
I just solved this problem.
when you want to put validation in certain column in gridview, you change that column to template. add your validator as usual, give it validationgroup name (as usual). then at the commandfield edit update column, convert that column also to template field, then set validationgroup name for "update" textlink.
hope that helps.
I ran into a similar problem. QA reported the update command was not firing on a DatGrid we had set up for user settings. Outside of the DataGrid, we happened to have two hidden input fields that were only visible when certain settings were in place. However, I noticed in my testing that clicking update increased the overall height of the divs these fields were in; i.e. the validation controls for those fields were firing.
The issue definitely seems to be related to the ValidationGroup setting for the validation controls.
Wan's answer was somewhat helpful, however I did not have to convert the EditCommandColumn to a template field, and merely had to add the ValidationGroup attribute to it along with the Validation control in the EditItemTemplate. The sample below is based on the implementation that worked for me:
<div class="row">
<div runat="server" id="divConfirm">
<div class="formfields float-off form-group">
<div class="col-xs-4 text-right">
<p class="align-middle">Field 1</p>
</div>
</div>
<div class="formfields float-off form-group">
<div class="col-xs-4">
<input runat="server" id="confirm1" name="confirm1" />
<!-- this control was firing prior to adding the validation group -->
<asp:RequiredFieldValidator runat="server" ID="valConfirmReq"
Display="Dynamic" ControlToValidate="confirm1"
ErrorMessage="*You must confirm etc. message">
</asp:RequiredFieldValidator>
</div>
</div>
</div>
</div>
<asp:DataGrid ID="DataGrid1" runat="server" OnEditCommand="DataGrid_EditCommand"
OnCancelCommand="DataGrid1_CancelCommand"
OnUpdateCommand="DataGrid1_UpdateCommand">
<Columns>
<asp:EditCommandColumn EditText="Edit" HeaderText="Edit"
UpdateText="Update" CancelText="Cancel" ValidationGroup="DataGrid1">
<%-- DataGrid code --%>
<asp:TemplateColumn>
<EditItemTemplate>
<asp:DropDownList ID="ddl1" runat="server"></asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvDDL" runat="server"
ErrorMessage="*Please Select"
ValidationGroup="DataGrid1"
Display="Dynamic"
ControlToValidate="ddl1"
InitialValue="Select">
</asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Related
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" />
Working on an asp.net page I created a custom ajax web user control that displays the contents of a list value (which is loaded via database calls). The control includes "next" and "previous" buttons, as well as a couple text boxes. My initial version used a session variable (iterator) to keep track of where the user is while clicking the buttons and filling the text boxes with values from the List[].
In my next iteration, I need to be able to use this custom control, which will be presented many times in a table (or more probably grid), but I'm having trouble figuring out how to handle the iterator, since the session variable will obviously no longer work.
Does anyone have a suggested approach, or a recommended article?
I solved the problem by creating a second form on my user control that is segregated from the controls contained within the UpdatePanel. Before those controls are refreshed, the segregated control (a label in this case) is programmatically assigned a value and when the control Page_Load event fires it references the segregated label value to keep track of it's current position. I also had to move the ScriptManager out of my control and place it on the page(s) the control will be used on, since there will be several of these custom user controls on the page and only one ScriptManager is permitted per page.
<form id="NaviControl" >
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Panel ID="controlsPanel" runat="server" HorizontalAlign="Center" >
<asp:Panel ID="Panel1" runat="server" >
<asp:Button ID="btnLast" runat="server" Text="Previous" Height="25px" Width="75px" OnClick="btnLast_Click" />
<asp:TextBox ID="tbStatusCode" runat="server" ></asp:TextBox>
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" HorizontalAlign="Center" >
<asp:TextBox ID="tbDescription" runat="server" ></asp:TextBox>
<asp:Button ID="btnNext" runat="server" Text="Next" Height="25px" Width="75px" OnClick="btnNext_Click" />
</asp:Panel>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
<form>
<asp:Label ID="lblCounter" runat="server" visible="false" />
</form>
Hope some other nubs find this approach useful.
I have a user control with three Views inside MultiView, first two views contains different controls and each have a button to submit the form, both are working as expected. Third one has two asp image button both are not attached with any validation group, causes validation is also false but post back is not happening on clicking the button, there is no javascript error i already checked that, any help is appreciated. Following is markup.
<asp:View runat="server" ID="vwPayAsGuest">
<asp:Panel ID="divButtons" runat="server" CssClass="creditcardbuttons-container">
<div class="creditcardbuttons-container-left">
</div>
<div id="divRegularPayment" class="f-left">
<asp:ImageButton runat="server" ID="lbtnRegularCheckout" ToolTip="Pay with credit card"
AlternateText="Pay with credit card" OnClick="lbtnRegularCheckout_OnClick" CausesValidation="false"/>
</div>
<div id="divPayByPayPal" class="f-left padding-left15">
<asp:ImageButton runat="server" ID="submit" CausesValidation="false"
ImageUrl="https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image&buttontype=ec-mark"
AlternateText="Pay via PayPal" ToolTip="Pay via PayPal (Express Checkout)" OnClick="lnkButPayPal_Click" />
</div>
</asp:Panel>
</asp:View>
Considering the fact that I was not able to find a single instance of someone else needing this functionality anywhere else, this might be an off the wall requirement. That said:
A website that I am working on uses several dozen different validator controls (everything from RequiredFieldValidaotrs to CustomValidators) throughout for form validation. As part of our Section 508 compliance, we have to support users who disable CSS, which is problematic because the validators render the error text to the page and use the CSS display property to hide it. When CSS is disabled all of the error messages are both visible and read by screen readers.
Short of using labels and postbacks to show and hide said labels, is there any known method for using ASP.Net validator controls with CSS disabled?
Use the Display="None" attribute on the FieldValidator control and a ValidationSummary tag to contain the messages.
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="TextBox1" /> <br />
<asp:TextBox runat="server" ID="TextBox2" /> <br />
<asp:Button runat="server" Text="Go" />
<div class="messages">
<asp:ValidationSummary id="summery1" runat="server"/>
</div>
<div>
<asp:Panel ID="Panel1" runat="server" >
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Required Field Validator1 empty" ControlToValidate="TextBox1" Display="None" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="Required Field Validator2 empty" ControlToValidate="TextBox2" Display="None" />
</asp:Panel>
</div>
</form>
HOWEVER....(there's always a catch)... with this method, the Validation Messages themselves are stored in the JavaScript only. Meaning that it won't work if Javascript is disabled. I'm assuming that's not a huge problem since you are working in WebForms (which rely on JS), but I figure it's worth mentioning.
And for the record, accessibility concerns are mostly a crock of horse-crap. I THOUGHT I knew about accessibility until I actually worked with a visually impaired programmer (100% blind). Then, I learned that JS works just fine (assuming they know to look for new content...) and that they just skip around the page from link to link until they find what they are after. And table-based layouts didn't slow them down for 1 second. Boy that was a tough pill to swallow after being SOOO unbearably preachy about CSS for a few years....
Our problem/question revolves around an upload control that loses the selected file (goes blank) when a postback control is used (in this case, the dropdown list posts). Any insight into what we are doing wrong or how we can fix this? Below is our code and a summary of the problem.
Any help would be greatly appreciated.
Thank you!
<asp:updatepanel id="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="row">
<asp:DropDownList runat="server" AutoPostBack="true" ID="CategorySelection" OnSelectedIndexChanged="CategorySelection_IndexChanged" CssClass="drop-down-list" />
</div>
<div id="SubCategory" class="row" runat="server" visible="false">
<asp:DropDownList runat="server" ID="SubCategorySelection" CssClass="drop-down-list" />
</div>
<div class="row">
<asp:FileUpload runat="server" ID="FileUpload" CssClass="file-upload" />
</div>
<div class="row">
<asp:Button ID="submit" runat="server" Text="Submit" CssClass="button" OnClick="submit_ButtonClick" />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="submit" />
</Triggers>
</asp:updatepanel>
In this form we have 2 DropDownList, 1 FileUpload and 1 submit button. Every time that the user selects one category, the subcategories are loaded (AutoPostBack=”true”).
The primary user flow works fine: User selects one category, subcategory and selects a file to be uploaded (submitted). HOWEVER, if the user selects a file first, and then selects a category, the screen will do a partial refresh and the selected file will disappear (field goes blank). As a result, the user needs to select the file again. This causes an issue because the fact that the file is no longer selected can easily be overlooked.
Seems straighforward --- but causing us a lot of grief. Any experts out there that can help?
BIG thanks!
That is the behavior of the input type=file i.e. it can't be pre-populated. Move the FileUpload outside of the UpdatePanel. In your markup, you could move both FileUpload and the submit Button outside of the UpdatePanel.