469,616 Members | 1,792 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

Issues Using Javascript confirmation box in conjunction with a button. Attributes.Add("onclick"...) event and GetPostBackEventReference

Hi, I have an internal ASP.NET application that I'm are using to send
e-mails out based on a single milepost or milepost range entered.

I'm trying to do two things when a user clicks on the submit button
to submit a form that contains one or two Mileposts:

1) If a Milepost range larger than 5 miles is entered, I would
like to
pop up a confirmation box to confirm the range.

2) If the user hit's OK to the confirmation box, or there was only
1
milepost entered, or the range is less than 5 miles, I would like the
button click event to process the sending of the email AND disable the
button. Otherwise they may submit the form several times.

The way the code is listed below, the button will get disabled, but the
button..Click function never gets executed. If I remove the
this.disabled=true; statement from the statement below, the button does
not get disabled, but the button..click event does run through. Any
idea if I can get this to work?

Here is the behind .VB code located in the Page_Load event -

btn_email_event.Attributes.Add("onclick", "javascript:
this.disabled=true; return mpRangeOK();" &
GetPostBackEventReference(btn_email_event).ToStrin g)

Then I have the email function:

Private Sub btn_email_event_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btn_email_event.Click
....

Here is the Javascript function I have in the .aspx page

function mpRangeOK()
{
//This function will be called when a user clicks on
the button to
submit an email and it
//will pop up a confirmation box IF two MP's were
entered AND IF
their difference is
//greater than 5.
//The function returns false if they want to modify
their range
//It will return nothing (UNDEFINED) otherwise
(allowing the VB
button_click code to run.)
//NOTE - THE VB button_click will have additional
validation as well
//THIS is called from the email-publish.aspx.vb
btn_email_event.Attributes.Add("onclick"... Event

var mpstart, mpend, mpdiff;
mpstart = document.Form1.textboxMPStart.value;
mpend = document.Form1.textboxMPEnd.value;
//document.Form1.btn_email_event.disabled=true;

//IF BOTH mp's fields were entered and they are
both numeric values
if ((mpend.length 0) && (!isNaN(mpend)) &&
(mpstart.length 0) &&
(!isNaN(mpstart)) )
{
//Get absolute value of the difference
- we have to round it up,
convert it to
//an integer, and then reconvert to an
integer - otherwise would
get a values like .0000100005
mpdiff = (Math.round(Math.abs(mpstart -
mpend)* 100))/100;
if (mpdiff 5)
{
if (!confirm(" Are you sure
you want this event to cover a range
of " + mpdiff + " MILES?" +
"\n\nYou entered a starting
Milepost " +
"of " + mpstart + " and an " +
"ending Milepost of " + mpend +
".\n\n
Hit OK to ACCEPT this range" +
".\n\n Hit
CANCEL to MODIFY this range."))
{

document.Form1.btn_email_event.disabled=false;
return false;

}
}
}
}

Thanks

Nov 6 '06 #1
2 7500
if you disable a control, the browser will not post its value. thus if you
disable a button n the submit, it will not be posted. you need to disable
the button after the submit, use a window.setTimeout() to do this. You
should return true from the onclick. if you are using validation (or command
arg), your return is short circuiting the postback.

-- bruce (sqlwork.com)
<ba*****@yahoo.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Hi, I have an internal ASP.NET application that I'm are using to send
e-mails out based on a single milepost or milepost range entered.

I'm trying to do two things when a user clicks on the submit button
to submit a form that contains one or two Mileposts:

1) If a Milepost range larger than 5 miles is entered, I would
like to
pop up a confirmation box to confirm the range.

2) If the user hit's OK to the confirmation box, or there was only
1
milepost entered, or the range is less than 5 miles, I would like the
button click event to process the sending of the email AND disable the
button. Otherwise they may submit the form several times.

The way the code is listed below, the button will get disabled, but the
button..Click function never gets executed. If I remove the
this.disabled=true; statement from the statement below, the button does
not get disabled, but the button..click event does run through. Any
idea if I can get this to work?

Here is the behind .VB code located in the Page_Load event -

btn_email_event.Attributes.Add("onclick", "javascript:
this.disabled=true; return mpRangeOK();" &
GetPostBackEventReference(btn_email_event).ToStrin g)

Then I have the email function:

Private Sub btn_email_event_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btn_email_event.Click
...

Here is the Javascript function I have in the .aspx page

function mpRangeOK()
{
//This function will be called when a user clicks on
the button to
submit an email and it
//will pop up a confirmation box IF two MP's were
entered AND IF
their difference is
//greater than 5.
//The function returns false if they want to modify
their range
//It will return nothing (UNDEFINED) otherwise
(allowing the VB
button_click code to run.)
//NOTE - THE VB button_click will have additional
validation as well
//THIS is called from the email-publish.aspx.vb
btn_email_event.Attributes.Add("onclick"... Event

var mpstart, mpend, mpdiff;
mpstart = document.Form1.textboxMPStart.value;
mpend = document.Form1.textboxMPEnd.value;
//document.Form1.btn_email_event.disabled=true;

//IF BOTH mp's fields were entered and they are
both numeric values
if ((mpend.length 0) && (!isNaN(mpend)) &&
(mpstart.length 0) &&
(!isNaN(mpstart)) )
{
//Get absolute value of the difference
- we have to round it up,
convert it to
//an integer, and then reconvert to an
integer - otherwise would
get a values like .0000100005
mpdiff = (Math.round(Math.abs(mpstart -
mpend)* 100))/100;
if (mpdiff 5)
{
if (!confirm(" Are you sure
you want this event to cover a range
of " + mpdiff + " MILES?" +
"\n\nYou entered a starting
Milepost " +
"of " + mpstart + " and an " +
"ending Milepost of " + mpend +
".\n\n
Hit OK to ACCEPT this range" +
".\n\n Hit
CANCEL to MODIFY this range."))
{

document.Form1.btn_email_event.disabled=false;
return false;

}
}
}
}

Thanks

Nov 6 '06 #2
Thank you, this solved my problem.

In my javascript function, I
placed window.setTimeout('document.Form1.btn_email_event. disabled=true',
100); if they confirmed OK, or no confirmation was needed.
bruce barker (sqlwork.com) wrote:
if you disable a control, the browser will not post its value. thus if you
disable a button n the submit, it will not be posted. you need to disable
the button after the submit, use a window.setTimeout() to do this. You
should return true from the onclick. if you are using validation (or command
arg), your return is short circuiting the postback.

-- bruce (sqlwork.com)
<ba*****@yahoo.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Hi, I have an internal ASP.NET application that I'm are using to send
e-mails out based on a single milepost or milepost range entered.

I'm trying to do two things when a user clicks on the submit button
to submit a form that contains one or two Mileposts:

1) If a Milepost range larger than 5 miles is entered, I would
like to
pop up a confirmation box to confirm the range.

2) If the user hit's OK to the confirmation box, or there was only
1
milepost entered, or the range is less than 5 miles, I would like the
button click event to process the sending of the email AND disable the
button. Otherwise they may submit the form several times.

The way the code is listed below, the button will get disabled, but the
button..Click function never gets executed. If I remove the
this.disabled=true; statement from the statement below, the button does
not get disabled, but the button..click event does run through. Any
idea if I can get this to work?

Here is the behind .VB code located in the Page_Load event -

btn_email_event.Attributes.Add("onclick", "javascript:
this.disabled=true; return mpRangeOK();" &
GetPostBackEventReference(btn_email_event).ToStrin g)

Then I have the email function:

Private Sub btn_email_event_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btn_email_event.Click
...

Here is the Javascript function I have in the .aspx page

function mpRangeOK()
{
//This function will be called when a user clicks on
the button to
submit an email and it
//will pop up a confirmation box IF two MP's were
entered AND IF
their difference is
//greater than 5.
//The function returns false if they want to modify
their range
//It will return nothing (UNDEFINED) otherwise
(allowing the VB
button_click code to run.)
//NOTE - THE VB button_click will have additional
validation as well
//THIS is called from the email-publish.aspx.vb
btn_email_event.Attributes.Add("onclick"... Event

var mpstart, mpend, mpdiff;
mpstart = document.Form1.textboxMPStart.value;
mpend = document.Form1.textboxMPEnd.value;
//document.Form1.btn_email_event.disabled=true;

//IF BOTH mp's fields were entered and they are
both numeric values
if ((mpend.length 0) && (!isNaN(mpend)) &&
(mpstart.length 0) &&
(!isNaN(mpstart)) )
{
//Get absolute value of the difference
- we have to round it up,
convert it to
//an integer, and then reconvert to an
integer - otherwise would
get a values like .0000100005
mpdiff = (Math.round(Math.abs(mpstart -
mpend)* 100))/100;
if (mpdiff 5)
{
if (!confirm(" Are you sure
you want this event to cover a range
of " + mpdiff + " MILES?" +
"\n\nYou entered a starting
Milepost " +
"of " + mpstart + " and an " +
"ending Milepost of " + mpend +
".\n\n
Hit OK to ACCEPT this range" +
".\n\n Hit
CANCEL to MODIFY this range."))
{

document.Form1.btn_email_event.disabled=false;
return false;

}
}
}
}

Thanks
Nov 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Eric-Sebastien Lachance | last post: by
2 posts views Thread by sck10 | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.