Radcaptcha refresh image causes invalid postback or callback argument..

5 posts, 0 answers
  1. suresh
    suresh avatar
    30 posts
    Member since:
    Apr 2011

    Posted 21 Mar 2012 Link to this post

    Hi there,
    I have two textboxes and a Button in my aspx page..I have dynamically create a radcaptcha with enablerefreshimage=true in Onint event...I have to do some stuff in my button click..After clicking "Get New Image" link,unknown error occured after I clicked my Button..But everything was fine without clicking "Get new Image"..Here is the error,,

    Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %>in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation

    Here is my code,,
    <table>
     <tr>
     <td ><asp:TextBox ID="tb1" Width="300" runat="server"></asp:TextBox>
       </td>
       </tr>
     <tr>
     <td >
      <asp:TextBox ID="tb2" Width="300" runat="server"></asp:TextBox>
       </td>
        </tr>
         <tr>
        <td> <asp:Panel ID="pnlCaptcha" runat="server">
        </asp:Panel>
         </td>
          </tr>
            <tr>
          <td align="center">
         <asp:Label ID="Label1" runat="server" 
              Text="Type the above code in text box"></asp:Label>
              </td>
                </tr>
                  <tr>
               <td align="center">
          <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
          </td>
          </tr>
    <tr>
    <td>
     <asp:Button ID="btnEnroll" runat="server" ValidationGroup="vgAudio" Text="Enroll"
                                        OnClientClick="this.disabled=true" Visible="false" OnClick="btnEnroll_Click"
                                        UseSubmitBehavior="false" /><br />
    </td>
    </tr>
           </table>

    Backend Code::
    protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                RadCaptcha radCaptch = new RadCaptcha();
                radCaptch.ID = "RadCaptcha1";
                radCaptch.ValidationGroup = "vgAudio";
                radCaptch.ValidatedTextBoxID = TextBox1.ID;
                radCaptch.EnableRefreshImage = true;
                radCaptch.CaptchaImage.RenderImageOnly = true;
                radCaptch.ForeColor = Color.Red;
                radCaptch.Attributes.Add("meta:resourcekey", "radCaptchaResource1");
                radCaptch.ErrorMessage = "Please type the valid code";
                 
               //Add the captcha to panel
                pnlCaptcha.Controls.Add(radCaptch);
     
            }
             protected void btnEnroll_Click(object sender, EventArgs e)
            {
                //Do some stuff
            }
    What mistake I have done in the above code...

    Thanks,
    S.Suresh
  2. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 23 Mar 2012 Link to this post

    Hi Suresh,

    I tried to reproduce the described problem, but to no avail. You can find attached my test page, as well as a screen capture that displays the behavior of the RadCaptcha control on my end. Please compare the sample with your actual project and check if there are differences in the setup or if I have missed something.

    It appears that the problem is specific to your scenario and its cause is related to parts of your code that are not included in the sample. Please describe the changes that should be made to the attached page, so that I can reproduce the issue in order to inspect it and to provide a working solution.

    Regards,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. suresh
    suresh avatar
    30 posts
    Member since:
    Apr 2011

    Posted 24 Mar 2012 Link to this post

    Thanks Slav..Attached file that you provide was working fine..I cant find any issue . For stand alone project everything was working fine. But unfortunately in my project that is caused error that I mentioned earlier.. I searched in google for a long time, many of them said, EnableEventValidation="false" in a page tag,everything should be fine.But I aware of EnableEventValidation must be true for page security..I have no idea about this issue. I attached a image that I received a exception after refreshing image in radcaptcha for your reference..
  5. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 28 Mar 2012 Link to this post

    Hi Suresh,

    Please examine this article and check if the described scenarios are similar to your case. What is the exact functionality of the Button control on the page, as it is most probably related to the problem at hand? Do you make any changes to the Button on Page_Load, as described in the linked article?

    Please compare your actual project with the sample, attached to my previous post. Are there differences in the setup? Reproducing the issue in the sample page will be very useful for inspecting the problematic behavior and determining its cause.

    Regards,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. suresh
    suresh avatar
    30 posts
    Member since:
    Apr 2011

    Posted 30 Mar 2012 Link to this post

    Thanks Slav,
     In page load event I set the properties for Radcaptcha..(noise level,character length etc....)..For my scenario I'm not able to put every settings into !postback event as you said.

     After I came to know , postback after clicking refreshimage caused a problem. Because in that postback the properties for radcaptcha are set  again.

    So I need to restrict postback on refreshimage click. Instead I skipped the RadCaptcha properties set method with the check !string.Equals( Request.Form["__EVENTTARGET"],"RadcaptchaUniqueID"), and that is working fine..In that case I find the UniqueID of refreshImage from my page source( page viewsource).

    Here is the solution,
    protected void Page_Load(object sender, EventArgs e)
    {      
         if (!string.Equals("ctl00$ContentPlaceHolder1$RadCaptcha1$CaptchaLinkButton",Request.Form["__EVENTTARGET"])
               {
                  //Set some Properties for Radcaptcha1
               }
          if(!Page.Postback)
              {
                 //Do some Stuff...
              }
    }
    protected override void OnInit(EventArgs e)
           {
               base.OnInit(e);
               RadCaptcha radCaptch = new RadCaptcha();
               radCaptch.ID = "RadCaptcha1";
               radCaptch.ValidationGroup = "vgAudio";
               radCaptch.ValidatedTextBoxID = TextBox1.ID;
               radCaptch.EnableRefreshImage = true;
               radCaptch.CaptchaImage.RenderImageOnly = true;
               radCaptch.ForeColor = Color.Red;
               radCaptch.ErrorMessage = "Please type the valid code";
               captchaRow.Visible = false;
               pnlCaptcha.Controls.Add(radCaptch);
           }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017