I'm kind of baffled. Can someone help me point out why my validation summary is not showing the custom validators? When I step through the code in the custom validators the args.IsValid is set to false.
<asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="alert alert-danger" DisplayMode="List" ShowSummary="true" ValidationGroup="ValidateUser" />
<fieldset class="form-horizontal">
<legend><asp:Literal runat="server" ID="litFirstName" /> <asp:Literal runat="server" ID="litLastName" /><asp:Literal runat="server" id="litLockedBadge" /></legend> <div class="control-group">
<label class="control-label" for="inputEmail">
<asp:CustomValidator ID="cvEmailAddress" runat="server" ValidationGroup="ValidateUser" Text="*" CssClass="required" ControlToValidate="txtEmailAddress" Display="Dynamic" OnServerValidate="cvValidateEmail" />
<asp:RequiredFieldValidator runat="server" CssClass="required" Display="Dynamic" ControlToValidate="txtEmailAddress" Text="*" ErrorMessage="Email Address Required" ValidationGroup="ValidateUser" /> Email Address</label>
<div class="controls">
<asp:Textbox Text="test" runat="server" id="txtEmailAddress" ClientIDMode="Static" CssClass="span3" />
</div>
</div>
<div class="control-group input-append">
<label class="control-label" for="txtUserName"><asp:CustomValidator runat="server" ID="cvUserName" Text="*" CssClass="required" Display="Dynamic" OnServerValidate="cvValidateUserName" ValidationGroup="ValidateUser" /><asp:RequiredFieldValidator runat="server" Display="Dynamic" CssClass="required" ControlToValidate="txtUserName" Text="*" ErrorMessage="Username Required" ValidationGroup="ValidateUser" /> Username</label>
<div class="controls">
<asp:Textbox Text="test" runat="server" id="txtUserName" ClientIDMode="Static" CssClass="span3" />
<asp:LinkButton data-attr="email" ID="lnkEmailUsername" runat="server" CssClass="btn" OnClick="btn_ClickEmailUsername" ClientIDMode="Static"><i class="icon-envelope"></i></asp:LinkButton>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail"></label>
<div class="controls">
<div class="btn-group">
<asp:Button runat="server" ID="btnUnlockAccount" CssClass="btn" Text="Unlock Account" />
<asp:Button runat="server" ID="btnResetPassword" CssClass="btn" Text="Reset Password" />
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail"></label>
<div class="controls">
<asp:Button runat="server" ID="btnSubmit" CssClass="btn btn-primary" Text="Update User Account" OnClick="btn_UpdateUserAccount" ValidationGroup="ValidateUser" />
</div>
</div>
</fieldset>
Here is the code behind
//Validate the Username
protected void cvValidateUserName(object source, ServerValidateEventArgs args)
{
string userName = txtUserName.Text;
cvUserName.ErrorMessage = "";
args.IsValid = true;
if (userName.Contains(" "))
{
cvUserName.ErrorMessage = "Username cannot contain spaces. ";
cvUserName.IsValid = false;
}
if (userName.Length > 100 || userName.Length < 8)
{
cvUserName.ErrorMessage += "Username must be between 8 and 100 characters. ";
cvUserName.IsValid = false;
return;
}
}
//Validate Email Address
protected void cvValidateEmail(object source, ServerValidateEventArgs args)
{
var emailAddress = txtEmailAddress.Text;
try
{
new MailAddress(emailAddress);
}
catch (Exception)
{
args.IsValid = false;
return;
}
}
In order for the Validator's error message to display in the ValidationSummary, you need to set the Validators Display="none". I also set Text="".
Related
My goal here is to build a field that will basically make one or the other textbox required. I.E. If one textbox has some value that is not null, whitespace. or empty, I want the submit button to proceed. Else I want the standard red error to stop the submit from postingback and launching the insert function. I have tried writing this, but so far no good. What can I do to make this work?
<script type="text/javascript">
function validateText(sender, args) {
if (args.value !== "") {
var textBoxB = document.getElementById('TextBox12');
args.IsValid = (TextBox12.value !== "");
}
return;
/*
if (!string.IsNullOrEmpty(TextBox12.Text + TextBox13.Text)) {
args.IsValid = true;
}
else {
if (string.IsNullOrEmpty(TextBox12.Text) && !string.IsNullOrEmpty(TextBox13.Text)) {
args.IsValid = true;
}
else if (string.IsNullOrEmpty(TextBox13.Text) && !string.IsNullOrEmpty(TextBox12.Text)) {
args.IsValid = true;
}
else {
args.IsValid = false;
}
}
*/
}
</script>
<div>
<div class="left">
<asp:Label ID="Label13" runat="server" Text="Advanced Cancellation:"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="TextBox12" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="Required"
ValidationGroup='valGroup1'
ClientValidationFunction="validateText"
OnServerValidate="ServerValidation"
ForeColor="Red"
ValidateEmptyText="true">
</asp:CustomValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="Advanced Cancellation must be an integer."
ControlToValidate="TextBox12"
ValidationExpression="^\+?(0|[1-9]\d*)$"
ForeColor="Red">
</asp:RegularExpressionValidator>
</div>
</div>
<div>
<div class="left">
<asp:Label ID="Label14" runat="server" Text="Action Required (yyyy-MM-dd):"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="TextBox13" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator2" runat="server"
ValidationGroup='valGroup1'
ValidateEmptyText="true"
ErrorMessage="Required"
ClientValidationFunction="validateText"
OnServerValidate="ServerValidation"
ForeColor="Red">
</asp:CustomValidator>
<asp:CompareValidator
ID="CompareValidator1" runat="server"
Type="Date"
Operator="DataTypeCheck"
ControlToValidate="TextBox13"
ErrorMessage="Please enter a valid date."
ForeColor="Red">
</asp:CompareValidator>
</div>
</div>
protected void ServerValidation(object source, ServerValidateEventArgs args)
{
if (!string.IsNullOrEmpty(TextBox12.Text))
args.IsValid = !string.IsNullOrEmpty(TextBox13.Text);
}
That's what I have so far.
I have remove javascript code.Now your design part is
<div>
<div class="left">
<asp:Label ID="Label13" runat="server" Text="Advanced Cancellation:"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="TextBox12" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="Required"
ValidationGroup="valGroup1"
OnServerValidate="ServerValidation"
ForeColor="Red"
ValidateEmptyText="true">
</asp:CustomValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="Advanced Cancellation must be an integer."
ControlToValidate="TextBox12"
ValidationExpression="^\+?(0|[1-9]\d*)$"
ForeColor="Red">
</asp:RegularExpressionValidator>
</div>
</div>
<div>
<div class="left">
<asp:Label ID="Label14" runat="server" Text="Action Required (yyyy-MM-dd):"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="TextBox13" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator2" runat="server"
ValidationGroup="valGroup1"
ValidateEmptyText="true"
ErrorMessage="Required"
OnServerValidate="ServerValidation"
ForeColor="Red">
</asp:CustomValidator>
<asp:CompareValidator
ID="CompareValidator1" runat="server"
Type="Date"
Operator="DataTypeCheck"
ControlToValidate="TextBox13"
ErrorMessage="Please enter a valid date."
ForeColor="Red">
</asp:CompareValidator>
</div>
</div>
<div>
<asp:Button ID="btnok" runat="server" ValidationGroup="valGroup1" />
</div>
and code behind is
protected void ServerValidation(object source, ServerValidateEventArgs args)
{
if (!string.IsNullOrEmpty(TextBox12.Text) || !string.IsNullOrEmpty(TextBox13.Text))
args.IsValid = true;
else
{
args.IsValid = false;
}
}
I have tested its work for me
I have an asp.net webforms c# application that has a FileUpload control inside the InsertItemTemplate of a FormView. When inserting the new record the correct path + filename is saved to the appropriate field in the database, but the file isn't saved to the Data folder. Here is the code behind:
protected void fv_ven_doc_det_DataBound(object sender, EventArgs e)
{
if (fv_ven_doc_det.CurrentMode == FormViewMode.Insert)
{
//Set the fk
TextBox venIdFkTxt = (TextBox)fv_ven_doc_det.FindControl("venIdFkTextBox");
if (venIdFkTxt != null)
{
venIdFkTxt.Text = hdn_ven_id.Value;
}
//Get the upload date - current date and time
hdn_doc_upload_dt_txt.Value = DateTime.Now.ToString();
string docuplddt = fv_ven_doc_det.FindControl("docUpldDtTextBox").ToString();
docuplddt = hdn_doc_upload_dt_txt.Value;
TextBox docuplddttxt = (TextBox)fv_ven_doc_det.FindControl("docUpldDtTextBox");
if (docuplddttxt != null)
{
docuplddttxt.Text = hdn_doc_upload_dt_txt.Value;
}
//Set the current status
TextBox crntDocStatTxt = (TextBox)fv_ven_doc_det.FindControl("docStatTextBox");
if (crntDocStatTxt != null)
{
crntDocStatTxt.Text = "4";
}
//Set the filename and save the file
int i = 0;
FileUpload fu = (FileUpload)(fv_ven_doc_det.FindControl("fu_doc_upld"));
string filename = fu.FileName;
if (fu.HasFile == true)
{
while (System.IO.File.Exists(Server.MapPath("~/Data/") + filename))
{
i++;
filename = fu.FileName + " (" + i.ToString() + ")";
}
fu.PostedFile.SaveAs(Server.MapPath("~/Data/") + filename);
}
TextBox filenameTxt = (TextBox)fv_ven_doc_det.FindControl("docPathTextBox");
{
filenameTxt.Text = (Server.MapPath("~/Data/") + filename);
}
}
}
Here is the InsertItemTemplate of the FormView:
<InsertItemTemplate>
<asp:TextBox Text='<%# Bind("venIdFk") %>' runat="server" ID="venIdFkTextBox" Visible="false" />
<asp:TextBox Text='<%# Bind("docPath") %>' runat="server" ID="docPathTextBox" Visible="false" />
<asp:TextBox Text='<%# Bind("docStat") %>' runat="server" ID="docStatTextBox" Visible="false" />
<asp:TextBox Text='<%# Bind("docUpldDt") %>' runat="server" ID="docUpldDtTextBox" Visible="false" />
<div class="row">
<div class="form-group col-md-3">
<strong>Title</strong><br />
<asp:TextBox Text='<%# Bind("docTitle") %>' runat="server" ID="docTitleTextBox" CssClass="form-control widecontrol" /><br />
</div>
<div class="form-group col-md-3">
<strong>Type</strong><br />
<asp:DropDownList ID="ddlVenDocType" runat="server" DataSourceID="sdc_doc_type" DataTextField="dtype" DataValueField="dtypeId" SelectedValue='<%# Bind("docType") %>' AppendDataBoundItems="true" CssClass="form-control widecontrol"><asp:ListItem Value="">--Please Select--</asp:ListItem></asp:DropDownList><br />
</div>
<div class="form-group col-md-3">
<strong>Organization</strong><br />
<asp:DropDownList ID="ddlVenDocOrg" runat="server" DataSourceID="sdc_orgs" DataTextField="org" DataValueField="orgId" SelectedValue='<%# Bind("docOrg") %>' AppendDataBoundItems="true" CssClass="form-control widecontrol"><asp:ListItem Value="">--Please Select--</asp:ListItem></asp:DropDownList><br />
</div>
<div class="form-group col-md-3">
<strong>Department</strong><br />
<asp:DropDownList ID="ddlVenDocDept" runat="server" DataSourceID="sdc_depts" DataTextField="dept" DataValueField="deptId" SelectedValue='<%# Bind("docDept") %>' AppendDataBoundItems="true" CssClass="form-control widecontrol"><asp:ListItem Value="">--Please Select--</asp:ListItem></asp:DropDownList><br />
</div>
</div>
<div class="row">
<div class="form-group col-md-3">
<strong>Prior Contract Code</strong><br />
<asp:TextBox Text='<%# Bind("PriorContCd") %>' runat="server" ID="PriorContCdTextBox" CssClass="form-control widecontrol" /><br />
</div>
<div class="form-group col-md-3">
<strong>Legal / Compliance Contract ID</strong><br />
<asp:TextBox Text='<%# Bind("LegCompContId") %>' runat="server" ID="LegCompContIdTextBox" CssClass="form-control widecontrol" /><br />
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<strong>Description</strong><br />
<asp:TextBox Text='<%# Bind("docDesc") %>' runat="server" ID="docDescTextBox" CssClass="form-control widecontrol" Rows="5" TextMode="MultiLine" /><br />
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<asp:FileUpload ID="fu_doc_upld" runat="server" />
<asp:RequiredFieldValidator ID="rfv_fu_doc_upld" runat="server" ErrorMessage="A file must be chosen to upload." ControlToValidate="fu_doc_upld" ForeColor="#ff0000" Font-Bold="true">*</asp:RequiredFieldValidator>
</div>
</div>
<asp:LinkButton runat="server" Text="Insert" CommandName="Insert" ID="InsertButton" CausesValidation="True" CssClass="cmdlinkpdg" /> <asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="InsertCancelButton" CausesValidation="False" CssClass="cmdlinkpdg" />
</InsertItemTemplate>
I'm not getting any errors, it just doesn't save the file.
OK, it helps to stop and think about what actually needs to happen. I moved the filename / path and upload to OnItemInserting and it all works now.
In my whole project I have several events and surprising thing is that sometime some event fire up and sometime doesnot.I don't know hat is going on. I have tried many option after seraching from google. Please someone help me. I am in very bad situation.
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (Session["userid"] != null)
{
if (FileUpload1.HasFile)
{
string str = FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath(".")
+ "//images//" + str);
string path = "~//images//" + str.ToString();
con.Open();
Label1.Text = "File uploaded successfully";
main addinfo = new main();
string Id = Request.QueryString["id"];
string SQL = "insert into
mandir(with_user,name,place,with_district,with_religion,
with_religion_category,description,photo)
values('" + Session["userid"] + "','" + txttemplename.Text.Trim()
+ "','" + txtaddress.Text.Trim() + "','" +
ddldistrict.SelectedItem.Value + "','" +
ddlreligion.SelectedItem.Value + "','" +
ddlreligioncategory.SelectedItem.Value +
"','" + txtdescription.Value + "','" + path + "')";
addinfo.saveData(SQL);
con.Close();
txttemplename.Text = "";
txtaddress.Text = "";
txtdescription.Value = "";
string message1 = "Thank you for providing the information";
Page.ClientScript.RegisterStartupScript(this.GetType(),
"Popup", "ShowPopup('" + message1 + "');", true);
// lblenquirymsg.Text = "";
}
else
{
Label1.Text = "File not uploaded successfully";
}
}
else
{
// lblinfo.Text = "You Must Login Or Register To give information";
string message = "You Must Login Or Register To Comment";
Page.ClientScript.RegisterStartupScript(this.GetType(),
"Popup", "ShowPopup('" + message + "');", true);
}
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
<div class="weltext">
<h2>Add information</h2>
<div>
<div class="txt-st4" style="margin-bottom:8px; margin-top:10px;">Please fill the form below to provide information.</div>
<div style="padding:0px 0 10px 0;">
<form method="post">
<div style="margin-bottom:3px;"></div>
<div style="margin-bottom:7px;">
<div style="margin-bottom:3px;">Temple Name <span style="color:#F00">*<br />
</span><asp:TextBox ID="txttemplename" class="input_field1 verifyText" runat="server" style="margin-left: 0px" ></asp:TextBox>
</div>
<%-- <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="please input alphabets." ControlToValidate="txtfullname"
ValidationExpression="^[a-zA-Z]+$" Height="19px" Width="165px"></asp:RegularExpressionValidator>--%>
<asp:RequiredFieldValidator ID="rfvtemplelname" runat="server"
ControlToValidate="txttemplename" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revtemplelname" runat="server"
ControlToValidate="txttemplename" ErrorMessage="Only alphabets are allowed"
ForeColor="Red" ValidationExpression="^[a-zA-Z ]+$" > </asp:RegularExpressionValidator>
</div>
<div style="margin-bottom:4px;">
<div class="field required">
<div style="margin-bottom:3px;">
Address<span style="color:#F00">*<br /></span>
<asp:TextBox ID="txtaddress" class="input_field1 verifyText" runat="server" style="margin-left: 0px" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvaddress" runat="server"
ControlToValidate="txtaddress" ErrorMessage="Please enter valid address"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revaddress" runat="server"
ControlToValidate="txtaddress" ErrorMessage="Only alphabets are allowed"
ForeColor="Red" ValidationExpression="^[a-zA-Z ]+$" > </asp:RegularExpressionValidator>
</div>
</div>
</div>
<div style="margin-bottom:4px;">
<div class="field required">
<div style="margin-bottom:3px;"> Choose district <span style="color:#F00">*<br />
</span><asp:DropDownList ID="ddldistrict" runat="server" class="input_field1 verifyText" OnLoad="ddldistrict_Load" style="margin-left: 0px"></asp:DropDownList></div><div style="margin-bottom:4px;">
<div class="field required">
<br />
</div></div>
<div style="margin-bottom:3px;"> Choose religion<span style="color:#F00">*<br />
</span><asp:DropDownList ID="ddlreligion" class="input_field1 verifyText" runat="server" OnLoad="ddlreligion_Load" style="margin-left: 0px"></asp:DropDownList></div><div style="margin-bottom:4px;">
<div class="field required">
<br />
</div></div>
<div style="margin-bottom:3px;"> Choose religion category <span style="color:#F00">*<br />
</span><asp:DropDownList ID="ddlreligioncategory" class="input_field1 verifyText" runat="server" OnLoad="ddlreligioncategory_Load" style="margin-left: 0px" ></asp:DropDownList>
</div><div style="margin-bottom:4px;">
<div class="field required">
<br />
</div></div>
<%--<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="please input alphabets." ControlToValidate="txtaddress"
ValidationExpression="^[a-zA-Z]+$" Height="19px" Width="165px"></asp:RegularExpressionValidator>--%>
</div>
</div>
<div style="margin-bottom:3px;">Description<span style="color:#F00">*</span></div>
<div style="margin-bottom:4px;">
<div class="field required">
<textarea id="txtdescription" runat="server" name="description" class="text_area" style="width: 532px; height: 180px"></textarea>
<%-- <asp:RequiredFieldValidator ID="rfvdescription" runat="server" ControlToValidate="txtdescription"
ErrorMessage="*" InitialValue="Select"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revdescription" Runat="server"
ErrorMessage="ERROR: Please enter a valid description<br/>" SetFocusOnError="true" Display="Dynamic"
ControlToValidate="txtdescription" ValidationGroup="MandatoryContent"
ValidationExpression="^[A-Za-z'\-\p{L}\p{Zs}\p{Lu}\p{Ll}\']+$"
ForeColor="Red"></asp:RegularExpressionValidator>--%>
</div>
</div>
Choose picture:<br />
<asp:FileUpload ID="FileUpload1" runat="server" style="margin-left: 0px" /><br />
<%-- <asp:Button ID="Button1" runat="server" Text="Upload Image" onclick="Button1_Click" /><br >--%>
<br />
<span style="color:#F00">
<asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
<span style="color:#F00">
<div id="dialog" style="display: none">
</div>
<asp:Button id="btnSubmit" Text="Submit " runat="server" class="btn" OnClick="btnSubmit_Click" />
<%--<asp:Button ID="btnSubmit" Text="Submit" runat="server" value="Submit Now" class="btn" CausesValidation="False" style="margin-left: 13px" OnClick="btnSubmit_Click" />--%>
<br />
</span>
</span>
<br />
<div>
<%-- <asp:Button ID="btnReset" Text="Reset Form" runat="server" value="Reset Form" class="btn" OnClick="btnReset_Click" />--%>
<asp:Label ID="lblenquirymsg" runat="server"></asp:Label>
</div>
</form>
</div>
</div>
<p>
<asp:Label ID="lblenquirymsg1" runat="server"></asp:Label>
</p>
The above event is also not firing.
I'm trying to user recaptcha control in my application. For some reason it's all the time valid. no matter what values I put in recaptcha field it's all the time valid. Any idea what I'm missing?
here is my code
<%# Control Language="C#" CodeBehind="RegisterControl.ascx.cs" AutoEventWireup="true"
Inherits="UserControls.RegisterControl" %>
<%# Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
<asp:Panel ID="PlReg" runat="server" DefaultButton="CreateUserButton">
<div class="Reg_Wrapper">
<span class="failureNotification">
<asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
</span>
<div class="Clear">
</div>
<div class="Reg_ControlName">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label></div>
<div class="Reg_Control">
<asp:TextBox ID="TxtUserName" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator Display="Dynamic" ID="UserNameRequired" runat="server"
ControlToValidate="TxtUserName" CssClass="failureNotification" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
</div>
<div class="Clear">
</div>
<div class="Reg_ControlName">
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label></div>
<div class="Reg_Control">
<asp:TextBox ID="TxtEmail" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator Display="Dynamic" ID="EmailRequired" runat="server" ControlToValidate="TxtEmail"
CssClass="failureNotification" ErrorMessage="E-mail is required." ToolTip="E-mail is required."
ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RevEmail" ControlToValidate="TxtEmail" runat="server"
ErrorMessage="*" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">
<img src="/Images/required.png" alt="Required" />
</asp:RegularExpressionValidator>
</div>
<div class="Clear">
</div>
<div class="Reg_ControlName">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label></div>
<div class="Reg_Control">
<asp:TextBox ID="TxtPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator Display="Dynamic" ID="PasswordRequired" runat="server"
ControlToValidate="TxtPassword" CssClass="failureNotification" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
</div>
<div class="Clear">
</div>
<div class="Reg_ControlName">
<asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Conf. Password:</asp:Label></div>
<div class="Reg_Control">
<asp:TextBox ID="TxtConfirmPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="TxtConfirmPassword" CssClass="failureNotification"
Display="Dynamic" ErrorMessage="Confirm Password is required." ID="ConfirmPasswordRequired"
runat="server" ToolTip="Confirm Password is required." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:RequiredFieldValidator>
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="TxtPassword"
ControlToValidate="TxtConfirmPassword" CssClass="failureNotification" Display="Dynamic"
ErrorMessage="The Password and Confirmation Password must match." ValidationGroup="RegisterUserValidationGroup"><img src="/Images/required.png" alt="Required" /></asp:CompareValidator>
</div>
<div class="Clear">
</div>
<div class="Reg_ControlName">
</div>
<div class="Reg_Control">
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="my public key"
PrivateKey="my private key" Theme="white" />
</div>
<div class="Clear">
</div>
<div class="Reg_ControlName">
</div>
<div class="Reg_Control">
<asp:Button ID="CreateUserButton" role="button" runat="server" CommandName="MoveNext"
Text="Create User" ValidationGroup="RegisterUserValidationGroup" CssClass="Reg_Button"
OnClick="CreateUserButton_Click" /></div>
<div class="Clear">
</div>
</div>
</asp:Panel>
serverside
protected void CreateUserButton_Click(object sender, EventArgs e)
{
if(Page.IsValid)
{
ErrorMessage.Text = "page is valid";
}
else
{
ErrorMessage.Text = "page is not valid";
}
}
Here's one that works for me. Be sure to insert correct keys on server:
<recaptcha:RecaptchaControl ID="recaptcha" Theme="clean" runat="server"
PublicKey="hiddenxxx" TabIndex="7" ToolTip="Accessible CAPTCHA"
privateKey="hiddenxxx" />
<asp:Label CssClass="captchaLabel" ID="lblResult" runat="server" />
As you can see, I usually keep the CAPTCHA error message separate from the other messages.
Code-behind:
if(Page.IsValid)
{
...
}
else
{
lblResult.Text = "Incorrect!";
lblResult.ForeColor = System.Drawing.Color.Red;
}
i dont think check captcha validation out on page load there should be submit button that you have and you check it out in click event of the button, this is how i use. i think you should check links blove...
http://code.google.com/intl/tr-TR/apis/recaptcha/docs/aspnet.html
http://www.codeproject.com/KB/custom-controls/CaptchaControl.aspx
I making an add form in my modal. The modal contains 2 dropdownlists, 4 textboxes (1 hidden) and a button for adding.
I bind my dropdown list for the item category then bind my other dropdown list for the item name. However when I change my Item Category in my dropdown list the dropdown list for my item name is not responding or it not binding. Can anyone help me?
<div id="addModal" class="modal fade">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add Item</h4>
</div>
<div class="modal-body">
<div class="form-inline form-group">
<asp:Label ID="Label1" CssClass="control-label col-xs-3" runat="server" Text="Category:"></asp:Label>
<div class="col-xs-offset-3">
<asp:DropDownList ID="drpCategory" runat="server" CssClass="form-control col-xs-5" OnTextChanged="drpCategory_TextChanged" />
</div>
</div>
<div class="form-inline form-group">
<asp:Label ID="Label2" CssClass="control-label col-xs-3" runat="server" Text="Item Name:"></asp:Label>
<div class="col-xs-offset-3">
<asp:TextBox ID="txtitem" runat="server" CssClass="form-control col-xs-5" Visible="false" />
<asp:DropDownList ID="drpItem" runat="server" CssClass="form-control col-xs-5" Visible="true" />
</div>
</div>
<div class="form-inline form-group">
<asp:Label ID="Label3" CssClass="control-label col-xs-3" runat="server" Text="Unit:"></asp:Label>
<div class="col-xs-offset-3">
<asp:TextBox ID="txtUnit" runat="server" CssClass="form-control col-xs-5" Enabled="false" />
</div>
</div>
<div class="form-inline form-group">
<asp:Label ID="Label4" CssClass="control-label col-xs-3" runat="server" Text="Quantity:"></asp:Label>
<div class="col-xs-offset-3">
<asp:TextBox ID="txtQty" runat="server" CssClass="form-control col-xs-3" type="number" min="1" onkeypress="return isNumberKey(event)" />
</div>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button runat="server" ID="btnADD" CssClass="btn btn-sm" OnClick="btnADD_Click" Text="Add" />
</div>
</div>
</div>
then this is the code behind:
public void drpCategory_TextChanged(object sender, EventArgs e)
{
if (drpCategory.Text == "Others")
{
drpItem.Visible = false;
txtitem.Visible = true;
}
else
{
byCateg();
DataBind();
drpItem.Visible = true;
txtitem.Visible = false;
}
}
Is there a problem in my code?