Hi this is my code ;protectedvoid CreateUserWizard1_CreatingUser(object sender,LoginCancelEventArgs e)
{
MSCaptcha.CaptchaControl loginCAPTCHA = (MSCaptcha.CaptchaControl)LoginCredentials.FindControl("ccJoin");
TextBox txtCap = (TextBox)LoginCredentials.FindControl("txtJoin");Label captchalabel = (Label)LoginCredentials.FindControl("Captcha");loginCAPTCHA.ValidateCaptcha(txtCap.Text);
if (!loginCAPTCHA.UserValidated){
captchalabel.Text ="Please Try Again ";
return;}
}
I am getting Object reference not set to an instance of an object error. at the following line.
loginCAPTCHA.ValidateCaptcha(txtCap.Text);
Could someone tell me what the problem is.
Thank You
Kind of hard to say without knowing which Captcha control you're using. I googled on MSCaptcha.CaptchaControl but came up blank. If i google for MSCaptcha, I only come up with this:
http://www.mondor.org/soft/captcha.htm
If that's what you're using, did you enter the code to your web.config file, and then put the following into your registration page?
(this goes at the top)
<%@.RegisterAssembly="MSCaptcha"Namespace="MSCaptcha"TagPrefix="cc1" %>
(this goes where you want to show the captcha)
<cc1:CaptchaControlID="ccJoin"runat="server"CaptchaBackgroundNoise="none"CaptchaLength="5"CaptchaHeight="60"CaptchaWidth="200"CaptchaLineNoise="None"CaptchaMinTimeout="5"CaptchaMaxTimeout="240"/>
If you did all that, you shouldn't have to do the three lines of code you entered first. txtCap is just a Textbox where the user has to type the value shown by the Captcha.
I've recently implemented a Captcha myself, and I used the one from
http://www.codeproject.com/aspnet/CaptchaControl.asp. If you want a C# version, check the comments. There's a translated version in there. Also be sure to check the reply to the comment.
Also, just out of curiosity, did you mark your post as an answer because you managed to figure it out, or do you still require help?
HTH.
Peter
Hi Thanks for your reply.
I fixed that problem my controls were inside a contenttemplatecontainer. So I should have usedMSCaptcha.CaptchaControl loginCAPTCHA = (MSCaptcha.CaptchaControl)LoginCredentials.ContentTemplateContainer .FindControl("ccJoin");
instead of
MSCaptcha.CaptchaControl loginCAPTCHA = (MSCaptcha.CaptchaControl)LoginCredentials.FindControl("ccJoin");
But now I am up against another task displaying the Duplicateusernameerrormessage label.
If I enter a duplicate username or email the create user wizard doesn't create the user that is fine . But I want it to display the error message in a label. How can I do this?
Thanks
Dont know how is you captcha located but use this--If you show your UI code I can tell you specifics but following should solve it..
firstly you should modify the code to check for null...
secondly this is how you can find it.
MSCaptcha.CaptchaControl CreateUserWizard1CAPTCHA = (MSCaptcha.CaptchaControl)CreateUserWizardStep1.ContentTemplateContainer.FindControl("CAPTCHA");
if the stuff is increate user step 1.
bendJoe:
Hi Thanks for your reply.
I fixed that problem my controls were inside a contenttemplatecontainer. So I should have usedMSCaptcha.CaptchaControl loginCAPTCHA = (MSCaptcha.CaptchaControl)LoginCredentials.ContentTemplateContainer .FindControl("ccJoin");
instead of
MSCaptcha.CaptchaControl loginCAPTCHA = (MSCaptcha.CaptchaControl)LoginCredentials.FindControl("ccJoin");
But now I am up against another task displaying the Duplicateusernameerrormessage label.
If I enter a duplicate username or email the create user wizard doesn't create the user that is fine . But I want it to display the error message in a label. How can I do this?
Thanks
Set the error message of validators inside create user wizard.
I'm not sure if it is set automatically, but you can always use the
CreateUserWizard1.DuplicateEmailErrorMessage
property. You most likely will be able to set it in the aspx file, and from the codebehind, you can catch any errors, and assign them to a hidden label that you unhide when the error pops up.
HTH
Peter
It is set automatically, by default its just a *, you can set it both in cb or in aspx file
I just started testing with a sample createuserwizard and found these. There is a literal which displays a message saying please enter a different user name. I need a similar mechanism for e-mail also. How can I do this?
0 comments:
Post a Comment