Skip to content Skip to sidebar Skip to footer

Calling A Code-behind Function From Javascript That May Return Another Javascript Function

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 UpdatePane

Solution 1:

OnClientClick="Click_Alquilar(); return false"
instead of this useOnClientClick="returnClick_Alquilar();


and in javascript
usereturnfalse;
in functions like

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

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

Solution 2:

OK, for those who are interested in it, the problem was with the _doPostBack calls. Since the arguments I passed (_EVENTARGUMENT) were dynamic, I could never register those events through the RegisterForEventValidation method, becuase it asks for two constant strings (AFAIK): the control's UniqueID and the argument it will be passed with it.

So, I stopped passing arguments to the doPostBack other than the button's UniqueID, and passed the variables I was interested in through other media (cheifly, hidden fields values to global variables inside the Page class).

That solved the problem and made the program work as intended. I wrapped the buttons inside the same update panel than the GridView so as to not generate an AutoPostBack and change the Grid's values without having to refresh.

If anybody is interested in the code, I can provide.

Post a Comment for "Calling A Code-behind Function From Javascript That May Return Another Javascript Function"