This is a migrated thread and some comments may be shown as answers.

Problem with Captcha when i used in UserControl Register.ascx file

4 Answers 146 Views
Captcha
This is a migrated thread and some comments may be shown as answers.
tony
Top achievements
Rank 1
tony asked on 23 Jun 2010, 10:55 AM
when i used telerik captcha in normal "aspx" page it works perfectly but when i used in user control "ascx" page its not validating

i used the captcha with asp:button control and validation group ="submitgroup" for both captcha and button

The Code in aspx page:

<

 

rad:RadAjaxPanel ID="rjPnlRegister" runat="server" LoadingPanelID="ajxldpnlRegister">

 

<

 

rad:RadCaptcha ID="rdCaptcha" runat="server" ErrorMessage="You have entered an invalid code." ValidationGroup="SubmitGroup">

 

 

 

 

 

</rad:RadCaptcha>

 

 

 

 

 

<asp:Label ID="lblStatus" runat="server" Text="Label"></asp:Label>

 

 

 

 

 

<asp:Button ID="btnSubmit" runat="server" Text="Button"

 

 

ValidationGroup="SubmitGroup" onclick="btnSubmit_Click" />

 

 

 

 

 

</rad:RadAjaxPanel>

 

<

 

rad:RadAjaxLoadingPanel ID="ajxldpnlRegister" runat="server" Transparency="20" BackColor="#FFFFFF">

 

 

 

 

 

<asp:Image runat="server" ID="imgLoading" SkinID="imageajaxloading" AlternateText="" />

 

</

 

rad:RadAjaxLoadingPanel>

The Code in aspx.cs page:

 

protected

 

void btnSubmit_Click(object sender, EventArgs e)

 

{

 

if (Page.IsValid)

 

{

lblStatus.Text =

"correct!";

 

lblStatus.ForeColor = System.Drawing.

Color.Red;

 

}

}

I tested same code in ascx page and aspx page but in aspx page it works fine in aspx page i.e its validating correctly
but in ascx page its not validating when click on the button

can any tell why its happening like that....

4 Answers, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 23 Jun 2010, 12:05 PM
Hello Tony,

Are you by any chance loading the user control dynamically, because the control should be loaded at Page.Init in order for the RadCaptcha control to work correctly? Please, register the UserControl directly in the .aspx page, or load it at Page.Init, and if the problem persists, send us a fully working sample project that demonstrates the issue.

Sincerely yours,
Pero
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
tony
Top achievements
Rank 1
answered on 23 Jun 2010, 12:38 PM
It works very fine.
Thank you so much for giving the good support...
0
Роберт
Top achievements
Rank 1
answered on 16 Sep 2010, 10:39 AM
I'm load ascx user control with captcha and it's never been validated, even if I enter right code which I can see on a textbox by captcha.CaptchaImage.Text.
Pero, you wrote " register the UserControl directly in the .aspx page, or load it at Page.Init"

How can I do it?

I'm doing 

        Contact contact;
        protected void Page_Load(object sender, EventArgs e)
        {
            contact = (Contact)Page.LoadControl("~/Contact.ascx");
        }

in .aspx file

then, on menu (in aspx) selection, I fill PlaceHolder with
contact by myPlaceHolder.Controls.Add(contact)

I set all elements in my ValidationGroup with SubmitGroup. SubmitButton and captcha as well.
All elements from the resulting page, such as RequiredFieldValidator (3 of them at the form) are working ok, but the captcha IsValid property is always false.

What am I doing wrong? 
0
Pero
Telerik team
answered on 21 Sep 2010, 03:08 PM
Hi Vitali,

In order for the RadCaptcha to work correctly in a UserControl scenario, the UserControl must be loaded in the Page_Init, if created dynamically, or registered directly on the Page. So, please change your source code to load the control in the Page_Init, and see if you still get the same behavior. You can also call RadCaptcha.Validate(), and Page.Validate() methods before, checking the IsValid properties, just to be sure that the Validation has occurred. Here is a sample code:

RadCaptcha1.Validate();
Page.Validate();
 
if(RadCaptcha1.IsValid)
{
///source code
}

We will do our best to improve the control in one of our future releases.

Sincerely yours,
Pero
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Captcha
Asked by
tony
Top achievements
Rank 1
Answers by
Pero
Telerik team
tony
Top achievements
Rank 1
Роберт
Top achievements
Rank 1
Share this question
or