ASP.Net Script Controls Returning False from OnClick and FireFox
Brief explanation:
I have a script control that handles a click event in a script file. The Click handler invokes the confirmation prompt and returns the prompt value.
Problem:
IE sees a return of False (Cancel selected in the confirmation field) and no postback. Firefox ignores this and triggers postbacks.
Decision:
I read that if I was doing it the old way, I would need:
onClick="return SomeMethod();"
In the markup. Hopefully this is a way to do it using script controls?
Example:
This is what I have in the script file:
//THIS IS THE METHOD CLICK CALLS
handleLnkDeleteButtonClick: function(e)
{
var confirmed = confirm('This will delete the current Message category and move all messages to the Oprhan cataegory. Continue?');
return confirmed;
},
initialize: function()
{
this._lnkDeleteButton = $get(this._lnkDeleteButtonID);
this._lnkDeleteButton.idpicker = this;
//HOOK BEGINS HERE
this._lnkDeleteButtonClick = Function.createDelegate(this, this.handleLnkDeleteButtonClick);
$addHandler(this._lnkDeleteButton, "click", this._lnkDeleteButtonClick);
//END HOOK HERE
NDI.WebControls.Client.PersonalMessageTypePicker.callBaseMethod(this, 'initialize');
},
dispose: function()
{
$removeHandler(this._lnkDeleteButton, "click", this._lnkDeleteButtonClick);
NDI.WebControls.Client.PersonalMessageTypePicker.callBaseMethod(this, 'dispose');
}
source to share
Ok so figured it out myself after trying too long to get things right for google. It turns out there is a call method, so you don't have to worry about returning true or false.
handleLnkDeleteButtonClick: function(e)
{
var confirmed = confirm('This will delete the currery Message category and move all messages to the Oprhan cataegory. Allow?');
if (!confirmed)
{
e.preventDefault();
}
},
So instead of returning a confirmation, I just had to check its value and call the e.preventDefault method to stop the click when firing.
source to share