Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7868147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:54:31+00:00 2026-06-03T00:54:31+00:00

I have a problem with this that works for one button and not for

  • 0

I have a problem with this that works for one button and not for another.

The one that works is a button that calls a ModalPopup to add a new row to a GridView inside an UpdatePanel. If it’s successful, it pops up an alert with a message, else another alert with the Exception message. The code is very similar to the other one’s, except it’s in a ModalPopupExtender.

The button that throws the known exception about the EventValidation goes as follow:

Web:

<asp:Button ID="btnAlquilar" runat="server" Text="Alquilar" CssClass="AdminButtons"
                                 OnClientClick="Click_Alquilar(); return false"/>

The JavaScript function it calls

function Click_Alquilar() {
        if (index == '') {
            alert("Debe elegir una película para alquilar");
        }
        else {

            if (confirm("¿Quiere alquilar la película '" + selected.childNodes[2].innerText + "'?")) {
                __doPostBack('<%= btnAlquilar.UniqueID %>', index);
            }
        }
    }

Where index is the index of the selected row in the GridView (done with a similar architecture, and works fine).

The code-behind starts in the Page_Load method, and calls the function I’m having trouble with:

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {...}
            else
            {
                ProcessAjaxPostBack(sender, e);
            }
        }
private void ProcessAjaxPostBack(object sender, EventArgs e)
        {
            if ((Request.Params["__EVENTTARGET"] != null) && (Request.Params["__EVENTARGUMENT"] != null))
            {
                ...

                if (Request.Params["__EVENTTARGET"] == this.btnAlquilar.UniqueID)
                {
                    index = Convert.ToInt32(Request.Params.Get("__EVENTARGUMENT").TrimStart('r', 'o', 'w'));
                    btnAlquilar_Click(Request.Params.Get("__EVENTARGUMENT"));
                }    

            }
        }

protected void btnAlquilar_Click(string id)
        {
            string message = "";
            if (BAC.BAC.CheckUserAge(lblUserId.Text) < Convert.ToInt32(dgvPeliculas.Rows[index].Cells[7].Text))
            {
                btnBorrar.Visible = false;
                btnEditar.Visible = false;
                btnNuevo.Visible = false;
                System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('No tiene la edad mínima para alquilar la película.')", true);
            }
            else
            {
                try
                {
                    BAC.BAC.NewAlquiler(lblUserId.Text, dgvPeliculas.Rows[index].Cells[0].Text, dgvPeliculas.Rows[index].Cells[9].Text);
                }
                catch (Exception ex)
                {
                    message = Change_ExceptionMessage(ex.Message);
                    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('No se pudo alquilar la película: " + message + "')", true);
                }
            }

        }

The RegisterClientScriptBlock method is THE SAME I use for the other button (which doesn’t do anything more complex than this one: if things are wrong, it changes the text of a label in the Popup and shows the alert; if it’s right, it loads the GridView and shows the success alert), and works there. Here, it throws the exception “EnableEventValidation is true so…”. I have this button registered for Event Validation on Render:

protected override void Render(HtmlTextWriter writer)
        {
            this.Page.ClientScript.RegisterForEventValidation(btnAlquilar.UniqueID);
            base.Render(writer);
        }

So why does this happen here? Why it doesn’t work this time?

EDIT: Now that I check, the label changed by the working button in the ModalPopup is wrapped in an UpdatePanel. I don’t know if it matters, but just to note it.

EDIT2: The page also works within a Master page. Don’t know if it’s of any use. I have tried wrapping both the Edit button and the GridView with UpdatePanels and using AsyncPostBackTrigger, but still I get the same exception.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:54:32+00:00Added an answer on June 3, 2026 at 12:54 am
    OnClientClick="Click_Alquilar(); return false"
    instead of this use
    OnClientClick="return Click_Alquilar();
    
    
    and in javascript
    use return false;
    in functions like
    
    function Click_Alquilar() {
            if (index == '') {
                alert("Debe elegir una película para alquilar");
    return false;
            }
            else {
    
                if (confirm("¿Quiere alquilar la película '" + selected.childNodes[2].innerText + "'?")) {
                    __doPostBack('<%= btnAlquilar.UniqueID %>', index);
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem that my sites uses alot of ajax and when a
Ok I have this problem that I've never had before, it's really bugging me.
So we have this problem that we are trying to figure out. Heres what
I have this problem decomposing a relation schema into a set of schemas that
I have this problem, in a form I have a list of customers that
I've seen that a few instances of this problem have been raised already. However,
I am wondering how you would approach this problem I have two Taxrates that
I have a problem with IE. I have a layer that has this style
I have this code: <a href=index.asp onclick=<%Session(example) = True%>>LINK</a> The problem is that this
(I have a problem that I illustrated in this question but had no correct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.