I have a custom ASP.NET control that was created by inheriting from WebControls.ImageButton. In my markup I have the following
<td>
<CustomControlLibrary:CustomIcon ID="icnSave" CausesValidation="true" OnClick="DoSomething"
runat="server" Enabled="true" IconUse="Add" AutoSkin="true" SupportsEvents="true" ValidationGroup="ValidationGroupA" />
<asp:LinkButton ID="lbSave" OnClick="DoSomething" CausesValidation="true"
runat="server" ValidationGroup="ValidationGroupA">SAVE</asp:LinkButton>
</td>
When I click the "SAVE" link, the validation works as expected, however when I click on the CustomIcon, the validation does not work, and the DoSomething wired to the OnClick fires off.
Is there anything special that needs to be added to the custom controls to get ValidationGroups to work? Note: The CustomIcon control itself does not have any special validation that it does/
Sorry i don't know this line .
<CustomControlLibrary:CustomIcon ID="icnSave" CausesValidation="true" OnClick="DoSomething"
runat="server" Enabled="true" IconUse="Add" AutoSkin="true" SupportsEvents="true" ValidationGroup="ValidationGroupA" />
If you want to image button ,please try this sample
<asp:textbox id="tb1" runat=Server />
<asp:requiredfieldvalidator id="ReqField1" controltovalidate="tb1"
validationgroup="valGroup1" errormessage="Required" runat=Server />
<asp:ImageButton id="Button2" causesvalidation=true
validationgroup="valGroup2" ImageUrl="img.gif" runat=Server />
Demo
Related
I have calendarextender for a textbox. I need do the requiredfiled validation after lost focus. But the code below doesn't show red * after lost focus.
<asp:TextBox ID="txtDateS" runat="server" Width="80px"/>
<cc1:calendarextender ID="ceDateS" runat="server" CssClass="cal" Enabled="True" TargetControlID="txtDateS" />
<asp:RequiredFieldValidator ID="rfvDates" runat="server" ErrorMessage="RequiredFieldValidator" Text="*" ControlToValidate="txtDateS"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="rfvDates_ValidatorCalloutExtender" runat="server" Enabled="True" TargetControlID="rfvDates"></cc1:ValidatorCalloutExtender>
The RequiredFieldValidator doesn't fire when the control loses focus (unless you've previously entered text and then removed it), what you can try is to add the following to the page load event:
txtDateS.Attributes.Add("onblur", "ValidatorOnChange(event);")
I have several panels in my page,and each panel has a submit and clearall buttons.
I am trying to set focus of enter to my submit button.
I have an image button in my logo,and everytime user hits enter,its downloading file on imageclick.
Can someone suggest how do i set focus of enter to my submit button.Any ideas?
<asp:Panel ID="Panel2" runat="server" Width="100%" ForeColor="Black" DefaultButton="btnSubmit">
<telerik:RadButton ID="btnSubmit" runat="server" TabIndex="1" OnClick="OnSubmitClick" CausesValidation="true" />
<telerik:RadButton ID="btnclearall" runat="server" OnClick="OnClearAllClick" CausesValidation="false" />
</asp:Panel>
try defaultfocus attribute in <form> tag ,
<form id="form1" runat="server" defaultfocus="btnSubmit" >
Have you tried the UseSubmitBehavior attribute?
<telerik:RadButton ID="btnSubmit" runat="server" TabIndex="1" OnClick="OnSubmitClick" CausesValidation="true" UseSubmitBehavior="true" />
Set the other buttons to false. Technically you shouldn't have to set UseSubmitBehavior to true since it is default but setting all others to false might help.
i have the following code
<asp:Panel ID="searchPanel" DefaultButton="searchButton" runat="server">
<asp:TextBox ID="searchBox" runat="server" value=" Search..."></asp:TextBox>
<asp:Button ID="searchButton" runat="server" Style="display: none" OnClick="searchInput" />
</asp:Panel>
<asp:Panel ID="loginPanel" DefaultButton="submitButton" runat="server">
<asp:TextBox ID="username" runat="server" required="required"></asp:TextBox>
<asp:TextBox runat="server" ID="password" required="required"></asp:TextBox>
<asp:Button ID="submitButton" runat="server" Text="Log in" OnClick="login" />
</asp:Panel>
whenever i press 'enter' key when searchBox is focused, in the other panel fields are highlighted and says "Please fill the field".
How can I solve this?
I believe you are using HTML 5 "required" attribute. This will cause validation when you try to do a postback.
You can use a form specific for search control and use "novalidate" attribute in the form element.
Or
You can use validation groups to achieve this.
solved the issue by using validation group
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ControlToValidate="username"
ValidationGroup="emailValidationGroup"
runat="Server">
</asp:RequiredFieldValidator>
ValidationGroup="emailValidationGroup" //goes to button
also don't forget to add
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
to webconfig
I have an ASP.NET page with the following code.
<asp:TextBoxEx ID="CompSCEmail" MaxLength="100" runat="server"></asp:TextBoxEx> <asp:RegularExpressionValidator Display="Dynamic" ID="RegSubmitCompSCEmail" runat="Server" ControlToValidate ="CompSCEmail" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="(*)"></asp:RegularExpressionValidator>
<asp:ImageButton ID="SubmitButton" SkinID="submitButton" OnClick="SubmitButton_Click"
Action="Submit" ValidationGroup="submit" runat="server" VisibleOnRecall="false" />
<asp:ImageButton ID="SaveButton" SkinID="saveButton" OnClick="SaveButton_Click" Action="Save" runat="server" Visible="true" VisibleOnRecall="makerfirst" />
I want to validate the format of the email when the user click both "Submit" and "Save" button. Does anyone know how to do that?
Thank You.
Give your RegularExpressionValidator ValidationGroup Property.
On click of both of your Buttons call Page.Validate("yourvalidationgroup").
This way you can validate email on click of both the buttons.
Ajax Control Toolkit provides too many useful control and I've use them in a multi language application, nothings bad and everything's fine.
the question is that , How can I change the Ajax Control Toolkit Buttons Text, for example in Confirm Button Extender and vice versa .
any help appreciated
I misunderstood what you were after. To customize the button text, you have to create your own modal and instruct the extender to use it with the DisplayModalPopupID property, like this:
<asp:Button ID="btnCancel" ruat="server" Text="Cancel With Confirm" />
<cc1:ConfirmButtonExtender ID="ConfirmButtonExtender" runat="server"
TargetControlID="btnCancel"
OnClientCancel="cancelClick"
DisplayModalPopupID="MyCustomModal" />
<cc1:ModalPopupExtender ID="MyCustomModal" runat="server"
TargetControlID="btnCancel"
PopupControlID="PNL"
OkControlID="ButtonOk"
CancelControlID="ButtonCancel"
BackgroundCssClass="modalBackground" />
<asp:Panel ID="PNL" runat="server">
Are you sure you want to cancel?
<br /><br />
<div class="buttons">
<asp:Button ID="ButtonOk" runat="server" Text="Yes (Custom!)" />
<asp:Button ID="ButtonCancel" runat="server" Text="No (Custom!)" />
</div>
</asp:Panel>