Recaptcha ErrorMessage Property in ASP.NET - asp.net

I am using recaptcha in an ASP.NET 3.5 application and for some odd reason the ErrorMessage property is not working. Below is my code
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="*******************************" PrivateKey="*******************" Theme="white" ErrorMessage="This is an typo error" />
When the typed text doesn't match with the recaptcha image text it still shows the default error message "Incorrect. Try again." instead of my custom error message. What could be the reason for this strange behavior

You put the message in a Literal tag. Here is my code snippet:
<tr>
<td align="center" colspan="2" >
<recaptcha:RecaptchaControl Theme="white" ID="recaptcha" runat="server" PrivateKey="*************"
PublicKey="*************" />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: red">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False" Text="You have not entered the verification words correctly. Please try again."></asp:Literal>
</td>
</tr>
Mike

Related

Hide tr or td in a table using vb.net in codebehind

In my masterpage I have links for users also the authorization is different like admin and regular user.
links under each other and I can hide the hyperlinks depending on authorization status but the problem is i.e when I have 3 links the second link for the admin the link will hide when the user is regular and the link place empty like 123 1 3.
So I have an idea using table each link in one tr but I can`t hide td or tr because Visible is not in properties.
any help?
thank you
According to how to hide a having asp.net control:
you can give ID either to the TD or TR to which you want to hide/show
with the runat="server" and also you can take that tr/td inside the
div tag and give id to that div tag and also runat=server attribute
and after that you can pro grammatically hide/show that div.
like
<pre>
<tr id="trhide" runat="server"> </tr>
</pre>
in code behind write
trhide.visible=true/false
In the master page VB code behind add a public procedure: Then call the public set from your aspx page.
'======================================================================================================
'Set Tab No invisible
'======================================================================================================
Public Sub setTabNumberLabel(visible As Int16)
If visible = 0 Then
td_page.Visible = False
Else
td_page.Visible = True
End If
End Sub
The master aspx would be:
<table style="width:100%">
<!--<tr style="background-color:#565656;">-->
<tr>
<td style="width:15%;text-align:left;vertical-align:bottom;padding-left:20px;">Stategic Energy Assessment ( <asp:Label ID="lbl_year_ended" runat="server" /> )</td>
<td style="text-align:center;vertical-align:bottom;"><asp:Label ID="lbl_utility_name_and_id" runat="server" /></td>
<td id="td_page" runat="server" style="width:15%;text-align:right;vertical-align:bottom;padding-right:20px;">Tab No: <asp:Label ID="lbl_page" runat="server" /></td>
</tr>
<tr><td colspan="3" style="vertical-align:central"><hr /></td></tr>
<tr>
<td style="width:15%;text-align:left;vertical-align:central">
<asp:Label ID="lbl_print_version" runat="server" Text="View Printable Vision" Visible="false" />
</td>
<td style="font-size:larger; font-weight:bold; text-align:center; text-transform:capitalize;vertical-align:central">
<asp:Label ID="lbl_schedule_name" runat="server" />
</td>
<td style="width:15%;text-align:right;vertical-align:central;padding-right:20px;">
<asp:LinkButton ID="btn_footnotes" runat="server" Visible="false">Footnotes</asp:LinkButton>
</td>
</tr>
<%--<tr><td colspan="3" style="vertical-align:central" class="auto-style1"></td></tr>--%>
<tr><td colspan="3" style="vertical-align:central; padding-right:20%;padding-left:20%; ">
<i><asp:Label ID="lbl_headnotes" runat="server" Text="" /></i></td></tr>
<tr><td colspan="3" style="vertical-align:central"><hr /></td></tr>
</table>
The other answer is correct and works fine. Just adding complete piece of code.
It's quite amusing that you don't need to add runat=server for a table but you can still hide tr for that table using runat attribute.
<table>
<tr>
<td>aa</td><td>bb</td>
</tr>
<tr id="trHide1" runat="server">
<td>aa</td><td>bb</td>
</tr>
<tr id="trHide2" runat="server">
<td>aa</td><td>bb</td>
</tr>
<tr>
<td>aa</td><td>bb</td>
</tr>
</table>
Now just set properties in codebehind (hiding the tr)
trHide1.Visible = false;
trHide2.Visible = false;

RadCaptcha error message not included in Validation Summary

I have this code in my page that that has required field validation in the textboxes. The other controls are working fine(I have not included the other controls because its confusing) except for this radcaptcha. I have included it in the validation group but it is still not being displayed in the validation summary when it pops up. Thanks in advance.
<table>
<tr>
<td>
<asp:ValidationSummary ID="vs1" runat="server" BorderStyle="Solid" BorderWidth="1px"
Width="100%" Style="border-color: Black" BackColor="White" ForeColor="Red"
ValidationGroup="Group"></asp:ValidationSummary>
</td>
</tr>
<tr>
<td>
<div class="divContainer">
<telerik:RadCaptcha ID="RadCaptcha1" runat="server" ValidationGroup="Group" EnableRefreshImage="True" Display="Static" CssClass="CaptchaCss" Height="155px" Width="254px" CaptchaAudioLinkButtonText="" CaptchaLinkButtonText="" CaptchaImage-ImageCssClass="CaptchaImageCss" CaptchaImage-Width="231" CaptchaImage-Height="70" CaptchaTextBoxCssClass="rcTextBoxClass" CaptchaImage-EnableCaptchaAudio="True" CaptchaTextBoxLabelCssClass="rcLabelClass" ForeColor="#FFDC72" ErrorMessage="Invalid input"></telerik:RadCaptcha>
</div>
</td>
</tr>
</table>
Note that RadCaptcha performs the validation on the server, while the standard ASP.NET validation controls have client-side validation, which kicks in first, enabled by default. The client-side validation of all control in the validation group has to be disabled so that the error message of the captcha appears with the rest. You can check this in the link above.
Refer following link:
http://demos.telerik.com/aspnet-ajax/captcha/examples/validationsummary/defaultcs.aspx
You should use validationGroup property.

asp.net can only login in firefox

in my asp.net website i can only login in Firefox but not in chrome, internet explorer or safari.
here is my code :
string userName = LoginUserName.Text;
string password = LoginPassword.Text;
if (Page.IsValid)
{
if (Membership.ValidateUser(userName, password))
{
if (RemeberMe.Checked == true)
{
Response.Redirect("~/Home.aspx");
}
}
}
here is the login table :
<table>
<tr>
<td>
<asp:Label Text="Email:" AssociatedControlID="LoginUserName" runat="server"
id="LoginUserNamelabel" CssClass="label"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="LoginUserName" runat="server" Width="250px" CssClass="textbox"/>
<asp:RequiredFieldValidator id="LoginEmailRequired" runat="server" ControlToValidate="LoginUserName"
ErrorMessage="Email is required" ToolTip="Email is required"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label Text="Password:" AssociatedControlID="LoginPassword" runat="server"
ID="LoginPasswordlabel" CssClass="label"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="LoginPassword" runat="server" TextMode="Password" Width="250px" CssClass="textbox" />
<asp:RequiredFieldValidator ID="PassRequired" runat="server" ControlToValidate="LoginPassword"
ErrorMessage="Password is Required" ToolTip="Password is Required"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="RemeberMe" runat="server" Text="Remember me" CssClass="RemeberMe" />
</td>
</tr>
<tr>
<td><br />
<asp:Button ID="LoginButton" runat="server" Text="Login" OnClick="autoLogin" CssClass="Button" />
</td>
</tr>
<tr>
<td><br />
<asp:Label ID="FailureText" runat="server" EnableViewState="false" Visible="false" CssClass="Lfaluire">
Wrong Email or Password</asp:Label>
</td>
</tr>
</table>
using the AspNetSqlMembershipProvider.
i am using asp.net 4.0 , what is the problem
thanks
You always validate the username and password, but then only actually redirect if the user has checked the "Remember me" - This looks wrong. Could there be a co-incidence that you ticked the box in some test sessions but not others? ;)
Also you're not actually storing the fact that the user has logged in anywhere, so won't you have problems later with the User.Identity.IsAuthenticated still being false?
You should be using something like
FormsAuthentication.RedirectFromLoginPage Method whether or not the checkbox is checked...
If you want to do the redirect yourself you should be using FormsAuthentication.SetAuthCookie and then doing the redirect.
EDIT: Something like this
string userName = LoginUserName.Text;
string password = LoginPassword.Text;
if (Page.IsValid)
{
if (Membership.ValidateUser(userName, password))
{
if (RemeberMe.Checked)
{
// Set your own cookie here or something that you will later check for in Page_Load etc
}
// Need to tell ASP.NET authentication was successful
System.Web.Security.FormsAuthentication.SetAuthCookie(userName, True)
Response.Redirect("~/Home.aspx");
}
}
If you are hitting http://localhost then most of the browsers won't save the cookie that's being generated by your membership provider.
If this is the case, access it by a name that has a dot in it. See:
Cookies on localhost with explicit domain
Are cookies enabled in all these browsers? The most common culprit to the out-of-the-box ASP.NET login stuff "not working" is because by default, they have no fallback for when cookies are disabled.

displaying custom message on custom errors in validation summary control on client side?

I am using validation summary control to display error messages of asp.net validation controls.
There are some validations in page for which validation controls are not being used. I am using custom javascript and jquery code for these. Kindly guide how I can display messages of these errors in validation summary control along with asp.net validation controls.
The key is to use the Custom Validation control. This control supports client side scripting (so you can still use your javascript code to do it) but still ties into the validation framework asp.net provides.
From the microsoft article, something like this:
<SCRIPT LANGUAGE="JavaScript">
function validateLength(oSrc, args){
args.IsValid = (args.Value.length >= 8);
}
</SCRIPT>
<asp:Textbox id="text1" runat="server" text="">
</asp:Textbox>
<asp:CustomValidator id="CustomValidator1" runat=server
ControlToValidate = "text1"
ErrorMessage = "You must enter at least 8 characters!"
ClientValidationFunction="validateLength" >
</asp:CustomValidator>
As Patrick said you can add the custom validator controls in place of your custom javascript/jQuery code. And then accordingly you can add the summary validation control. Also you can change the error message in your javascript code. Please check the below code for your reference.
<script type="text/javascript">
function validatetxtLength(source, args)
{
var txtVal=document.getElementById('<%=txtusername.ClientID %>').value;
if(txtVal=="")
{
document.getElementById('<%=custxtValidator.ClientID %>').setAttribute("errormessage","Please Enter the User Name");
args.IsValid=false;
}
else if(txtVal.length>9)
{
document.getElementById('<%=custxtValidator.ClientID %>').setAttribute("errormessage","Username must have less than 10 characters");
args.IsValid=false;
}
else
{
args.IsValid=true;
}
return;
}
</script>
<div>
<table cellpadding="0" cellspacing="0" border="0" width="712px">
<tr>
<td colspan="3" align="center">
Validator Testing
</td>
</tr>
<tr>
<td>
Please Enter your User Name:
</td>
<td>
<asp:TextBox ID="txtusername" runat="server" Width="150px"></asp:TextBox>
</td>
<td>
<asp:CustomValidator ID="custxtValidator" runat="server" ErrorMessage="User Name must have less than 10 characters"
Text="*" ForeColor="Red" ClientValidationFunction="validatetxtLength"></asp:CustomValidator>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<asp:Button ID="btnsubmit" runat="server" Text="Submit" />
</td>
</tr>
</table>
<asp:ValidationSummary ID="ValidationSummary1" HeaderText="Please check below validations:"
runat="server" DisplayMode="BulletList" EnableClientScript="true" />
</div>
This might be useful for you.

Ajax in UserControl

i have a signup page and i want to check username exists or not with ajax
<%# Control Language="C#" AutoEventWireup="true" CodeFile="Simple.ascx.cs" Inherits="UserControls_Simple" %>
<div style="direction:rtl;">
<table style="font-family:Tahoma;font-size:12px;width:200px;">
<tr>
<td>نام کاربری:</td>
<td><asp:TextBox ID="txtUserName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Label ID="lblMessage" runat="server" Text="Username Already Exists" Visible="False"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>کلمه عبور</td>
<td><asp:TextBox ID="txtPassword" runat="server"></asp:TextBox></td>
</tr>
</table>
</div>
i want to show label if user exists
how can i do that?
Using Ajax to check if a user exists in your DB via a User Control (or whatever method you are using) is the same method you would use in a Web Page.
What kind of Ajax do you want to use? MS Ajax, jQuery, what?
Regardless, you will need to Call Web Services from Client Script to perform an AJAX request.

Resources