There MUST be a better way!

  • Thread starter Thread starter dwa
  • Start date Start date
D

dwa

When we want to confirm a user action before a post back occurs, we've been
writing code like this:

function onClickDelete()
{
var aResponse = window.confirm("Delete this record?");
if ( aResponse )
__doPostBack('theLayout$_ctl1$buttonDelete','') ;
return 0;
}

This seems like an "un-natural" act - is there a better way?

-- dwa
 
the OOP approach would be to subclass the button, and add a confim property,
that can be set in the designer, or in the code behind. the new control
would then handle rendering the required javascript.

-- bruce (sqlwork.com)
 
You can do this from code to the button, i'm not quite sure yet how you can
set onClick attributes to a web control from the designer.

Button1.Attributes.Add("onClick", "javascript:return confirm('are you
sure');")
 
bruce barker said:
the OOP approach would be to subclass the button, and add a confim property,
that can be set in the designer, or in the code behind. the new control
would then handle rendering the required javascript.

Yes. OOP as in: "Oooooops! This took a lot longer to complete than it
should have (2 hours as opposed to 2 minutes), and now we've got another
component to unit test..."

<ggg>

There ought to be a 5 *second* approach to solve such a problem. It's
throw-away.

-- dwa
 
If the button is called btn1, add the following code to the Page_load: (in
vb)

Dim btn as button = btn1

btn.Attributes.Add("onClick")="javascript: return etc. ...."

The code in the onclick event of the button will only fire when the
javascript returns TRUE.
 
Problem with doing this sort of client side rerouting is that.. sometimes
the client has script accessed turned off, using a low level browser, etc.
etc. all sorts of problems. Therefore I decided to just make a simple server
sideded dialog box.... STILL an ugly hack though. =P
 
Back
Top