I have a dropdown list on my aspx page on which I have a RequiredFieldValidator applied over it. DropDown code is:
<asp:DropDownList ID="ddlglCategoryId" runat="server" CssClass="textEntry2"
AutoPostBack="true" ValidationGroup="Save" DataSourceID="dtsglCategoryId" DataTextField="LookupItem"
DataValueField="Id" AppendDataBoundItems="true">
<asp:ListItem Text="All" Selected="True" Value="0"></asp:ListItem>
</asp:DropDownList>
RequiredFieldValidator code is:
<asp:RequiredFieldValidator ID="rfvddlglCategoryId" InitialValue="0" runat="server"
ErrorMessage="Please select category" CssClass="Validations" ControlToValidate="ddlglCategoryId"
ValidationGroup="Save" Display="Dynamic" SetFocusOnError="true">
</asp:RequiredFieldValidator>
I have a post back trigger as well on my aspx page and when I change the category from the dropdown, page posts back and a grid on my page gets updated. But due to post back, the validator message appears and then disappears. I want this to appear only when "All" is selected from dropdown and user clicks save button.
Any guidelines?
Trigger:
</ContentTemplate>
<Triggers>
<%--<asp:AsyncPostBackTrigger ControlID="lbFileName" />--%>
<asp:PostBackTrigger ControlID="btnFileUploadSave" />
</Triggers>
</asp:UpdatePanel>
Button:
<asp:ImageButton ID="btnFileUploadSave" runat="server" ValidationGroup="Save"
ImageUrl="~/App_Themes/Default/images/update.png" ToolTip="Save"
Height="18px" onclick="btnFileUploadSave_Click"/>
You may need to set the AutoPostBack property of the dropdownlist to false. It sounds like a postback is getting fired with the OnSelectedIndexChanged event handler.
Set the ValidationGroup Property Of all Validaters same which you want to validate on button click and then set buttons ValidationGroup property same as Your Validators
For Example:
<asp:RequiredFieldValidator ID="rfvDoc" runat="server" ControlToValidate="FileUpload1"
ErrorMessage="Please Select A Document" ValidationGroup="OnSave">
</asp:RequiredFieldValidator>
Related
I have such a Checkbox and DropDownList with Validator
<asp:CheckBox ID="chkIncludeLogin" runat="server" Text='MyCheckBox' Font-Size="9pt"/>
<asp:DropDownList ID="ddlLanguage" runat="server" ViewStateMode="Enabled" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldLanguage" runat="server" ControlToValidate="ddlLanguage"
InitialValue="-1" SetFocusOnError="True" ForeColor="Red" ValidationGroup="check"
Display="Dynamic" Text='*'></asp:RequiredFieldValidator>
I have this problem:
When I do not check CheckBox and do further actions, Validator does not start and everything works fine
When I check CheckBox and uncheck it, Validator works and does not allow to perform other actions.
How to make the validator not take this field into account when I check and uncheck the CheckBox?
I have the following ModalPopupExtender that contains an AJAX ComboBox, RequiredFieldValidator, and ValidatorCalloutExtender. Outside of the ModalPopup this exact code works. Also, ValidatorCalloutExtender's in the ModalPopup work on other controls like TextBoxes. However the following does not work. The value '0' (default) can be selected and the validator does not display.
However if I take out the AJAX ComboBox and put in a traditional ASP.NET DropDownList instead, it works as expected and shows the ValidatorCalloutExtender. I have used the developer toolbar and can't see anything out of the ordianry.
What do I need to do to make the ValidatorCalloutExtender work with the AJAX ComboBox inside the ModalPopup?
Thanks!
Not working:
<asp:Panel ID="pnlData" runat="server" >
<table>
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<act:ComboBox ID="cbx1" runat="server" Width="278px" DropDownStyle="DropDownList" AutoCompleteMode="SuggestAppend" CaseSensitive="false" AppendDataBoundItems="true" ToolTip="Select the Name.">
<asp:ListItem Text="(Please Select the Name)" Value="0" />
</act:ComboBox>
<asp:RequiredFieldValidator ID="cbx1Req" runat="server" ControlToValidate="cbx1"
SetFocusOnError="true" ErrorMessage="Please Select the Name."
InitialValue="0" Display="None" />
<act:ValidatorCalloutExtender ID="cbx1ReqE" runat="server"
TargetControlID="cbx1Req" PopupPosition="Right" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</asp:Panel>
<act:ModalPopupExtender ID="DataMPE" runat="server"
TargetControlID="="btnHidden"
PopupControlID="pnlData" />
<asp:Button ID="btnHidden" runat="server" Text="Modal Display (Hidden)" style="display:none" />
Works (if I replace the AJAX ComboBox control in code above with a traditonal ASP.NET DropDownList):
<asp:DropDownList ID="cbx1" runat="server" Width="300px" AppendDataBoundItems="true">
<asp:ListItem Text="(Please Select A Name)" Value="0" />
</asp:DropDownList>
Don't know if this can help, I had this problem with a required validator.
If found a solution here: http://ajaxcontroltoolkit.codeplex.com/workitem/24417
Had to add javascript to change the controltovalidate property for the internal textbox.
string script = string.Format(#"if({0}) {0}.controltovalidate = ""{1}_TextBox"";", this.reqValidator.ClientID, this.ddlCombo.ClientID);
ScriptManager.RegisterStartupScript(this, this.GetType(), string.Format("validator trick for {0}", this.ClientID), script, true);
I am annoyed with a problem I have repeater control in updatepanel like this.
<asp:UpdatePanel ID="UpdPnlConstituentRepeater" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<asp:Repeater ID="repConstituentInformation" runat="server" OnItemDataBound="repConstituentInformation_ItemDataBound">
<ItemTemplate>
<asp:DropDownList ID="dropRegistrantDownCostType" runat="server" AppendDataBoundItems="true"
AutoPostBack="true" OnSelectedIndexChanged="dropRegistrantDownCostType_SelectedIndexChanged"
EnableViewState="true">
<asp:ListItem Text="Select Type" Value="0" Selected="True" />
</asp:DropDownList>
<asp:CheckBoxList ID="chkBoxListRegistrantBenefits" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="chkBoxListRegistrantBenefits_SelectedIndexChanged">
</asp:CheckBoxList>
</itemTemplate>
</ContentTemplate>
</asp:UpdatePanel>
The problem I face that whenever I select any value from dropdown all the page gets refreshed After spending hours on the google I found a solution i.e, on itemdatabound event of repeater we just need to add the following code after finding the dropdown,
Dim sm As ScriptManager = ScriptManager.GetCurrent(Page)
sm.RegisterAsyncPostBackControl(objDropdownlist)
It worked very well for the dropdown but same is not working for checkboxlist like using the scripmanager instance if I write sm.RegisterAsyncPostBackControl(chkBoxListRegistrantBenefits), it is not working :(
Add ClientIDMode="AutoID" to the Repeater control.
You should not have to add any triggers and you should not even have to call RegisterAsyncPostBackControl. The ChildrenAsTriggers should take care of that.
on Repeater ItemDataBound event
use screiptmanager method RegisterAsyncPostBackControl
this.ScriptManager1.RegisterAsyncPostBackControl(
e.Item.FindControl(" put here your checkbox ID "));
Add this Before start of <ContentTemplate>:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="objDropdownlist" EventName="OnSelectedIndexChanged" />
</Triggers>
I said in my last question and will say in this one too, basically my username reflects my experience!
I currently have a page with 2 listviews, one of which has a number of controls in the InsertItem template.
One of these controls in particuilar is a DDL and I have a Modal Popup Extender hooked up to it. I want to trigger the MPE only when a particular value(not index) is selected. Here is where I am up to now!
DropDownList ExpenseTypeDDL =
(DropDownList) Expenses.InsertItem.FindControl("ExpenseTypeDDL");
int ExpenseType = (Int32.Parse(ExpenseTypeDDL.SelectedValue.ToString()));
if (ExpenseType == 1)
{
AjaxControlToolkit.ModalPopupExtender mpeMiles =
(AjaxControlToolkit.ModalPopupExtender)Expenses.InsertItem.
FindControl("mpeMiles");
mpeMiles.Show();
}
Above are the contents of the DDL SelectedIndexChanged event. This DDL is based on expense types, I want to target a particular value (db primary key) and then display the modal popup so the user can enter their mileage then do some other stuff after.
Here is my mpe
<cc1:ModalPopupExtender ID ="mpeMiles" TargetControlID ="ExpenseTypeDDL"
runat="server" DropShadow="true" PopupControlID="pnlMiles"
BackgroundCssClass="modalBackground" />
<asp:Panel CssClass="modalPopup" ID="pnlMiles" runat="server"
Height="170px">
<div style="padding: 5px; text-align:center">
<asp:Label ID="lblStart" runat="server">Start location.</asp:Label>
<asp:TextBox ID="txtLocationStart" runat="server" />
<asp:RequiredFieldValidator ID="reqLocation" runat="server"
ErrorMessage="You must enter a start location"
ControlToValidate="txtLocationStart" Display="Dynamic" Text="*" >
</asp:RequiredFieldValidator>
<asp:Label ID="lblDestination" runat="server">Destination.</asp:Label>
<asp:TextBox ID="txtDestination" runat="server" />
<asp:RequiredFieldValidator ID="reqDestination" runat="server"
ErrorMessage="You must enter a destination"
ControlToValidate="txtDestination" Display="Dynamic" Text="*" >
</asp:RequiredFieldValidator>
<asp:Label ID="lblMiles" runat="server">Please enter your Mileage</asp:Label>
<asp:RequiredFieldValidator ID="reqMileage" runat="server"
ErrorMessage="You must enter your mileage" ControlToValidate="txtMiles"
Display="Dynamic" Text="*" ></asp:RequiredFieldValidator>
<asp:TextBox ID="txtMiles" runat="server" />
<br />
<br />
<asp:Button ID="btnMiles_OK" runat="server" Text="Save"
CausesValidation="false" />
<asp:Button ID="btnMiles_Cancel" runat="server" Text="Cancel"
CausesValidation="false"/>
</div>
</asp:Panel>
At the moment the mpe shows as soon as the DDL is clicked, but I want that to happen only for the selected value of 1.
Can someone please tell me what I am doing wrong?
TIA
dotnetnewb
This is happening because you have set up the DDL as target of your modal popup extender - so whenever target index is changed, the dialog is shown. The solution is to have an hidden button and make that a target control for modal popup extender - if your DDL has auto-postback as true then your server side code will check the selected index and popup the dialog.
From user experience perspective, unless you have UpdatePanel on page, this would mean on DDL change, page will refreshed and a dialog will be shown. You can also use modal pop-up javascript API to show/hide on DDL selected index change w/o doing post-back. For example,
$find('mpeMiles').show();
How to show asp.net validation on button click event if i have 200 checkboxes and some of the checkboxes would be disabled and some are unchecked ... if user doesn't check any of the checkbox then asp.net validation control will display and user will be stay at the same page until they check any of the unchecked checkbox ...
How to do this ?
Use ValidationGroup property.
<asp:DropDownList ID="DropDownList1" ValidationGroup="Save" runat="server"> </asp:DropDownList>
<asp:DropDownList ID="DropDownList2" ValidationGroup="Save" runat="server"> </asp:DropDownList>
<asp:Button runat="server" ID="Button1" Text="Save" ValidationGroup="Save" OnClick="btnSave_Click" />