There MUST be a better way!

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
 
B

bruce barker

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)
 
M

Michael Ramey

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');")
 
D

dwa

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
 
M

Martin

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.
 
M

Marauderz

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top