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

5 posts, 0 answers
  1. tony
    tony avatar
    2 posts
    Member since:
    Oct 2006

    Posted 23 Jun 2010 Link to this post

    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....

  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 23 Jun 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. tony
    tony avatar
    2 posts
    Member since:
    Oct 2006

    Posted 23 Jun 2010 Link to this post

    It works very fine.
    Thank you so much for giving the good support...
  5. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 16 Sep 2010 Link to this post

    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? 
  6. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 21 Sep 2010 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017