473,322 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

There MUST be a better way!

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

Nov 18 '05 #1
5 996
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)

"dwa" <da@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #2
dwa

"bruce barker" <no***********@safeco.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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
Nov 18 '05 #3
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');")

"dwa" <da@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #4
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.

"Michael Ramey" <raterus@localhost> schreef in bericht
news:Ov**************@TK2MSFTNGP10.phx.gbl...
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');")

"dwa" <da@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
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


Nov 18 '05 #5
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
"Martin" <an****@mail2world.com> wrote in message
news:40***********************@news.wanadoo.nl...
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.

"Michael Ramey" <raterus@localhost> schreef in bericht
news:Ov**************@TK2MSFTNGP10.phx.gbl...
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');")

"dwa" <da@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
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



Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
6
by: Michael | last post by:
Hi, I'm fairly new at Python, and have the following code that works but isn't very concise, is there a better way of writing it?? It seems much more lengthy than python code i have read..... :-)...
6
by: Nick Dreyer | last post by:
In VB.NET I would like to not have to create property get/set procedures for every class variable I want to expose to Excel VBA projects in COM builds. Can anyone tell me if that is possible, or...
43
by: Rob R. Ainscough | last post by:
I realize I'm learning web development and there is a STEEP learning curve, but so far I've had to learn: HTML XML JavaScript ASP.NET using VB.NET ..NET Framework ADO.NET SSL
6
by: Nick Dreyer | last post by:
In VB.NET I would like to not have to create property get/set procedures for every class variable I want to expose to Excel VBA projects in COM builds. Can anyone tell me if that is possible, or...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.