473,396 Members | 2,092 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,396 software developers and data experts.

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 7686
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yvan J. Gagnon | last post by:
I am currenly developing a web site using Macromedia fireworks, and am trying to figure out a way (through hand-coding) of attaching a javascript function (onClick="doit=false") to each of the...
10
by: Eric-Sebastien Lachance | last post by:
Hey there, I decided to just create a 100% height and width div that filled the space over a background header image, and add an onclick event to redirect to the my index... Doesn't seem to work...
0
by: karunakar | last post by:
Hi All Here i want to show in datagrid Broder color as like image showed i attaching images pls check and help me out "Onlclick" i want to show red border color each row in DATAGRID in ASP.NET...
2
by: GD | last post by:
I have an ImageButton in a Repeater, and in the Repeater's OnItemDataBound event, I'd like to add some code that will let the ImageButton open a URL in a new window. This is what I have in my...
1
by: Anup | last post by:
In my form I and doing validations using 'Javascript' as I m using ASP1.1 and there is very less support for Validators there. //Code Behind private void Page_Load(object sender,...
2
by: sck10 | last post by:
Hello, Is there an equivalent to using "Handles" in the codebehind for c#? Or do I have to declare every event in the GridView control like the following: <asp:GridView ID="gvSearchList"...
1
by: Big George | last post by:
Hello, Controls on webpage: - Datagrid - TextBox Datagrid has Delete button: <asp:TemplateColumn HeaderText="Borrar"> <HeaderStyle Width="10%"></HeaderStyle>
4
by: pbd22 | last post by:
Hi. I am trying to add an "onclick" 'event to an anchor tag and this is proving harder than I imagined. The anchor HAS NO ID. And, there will be tons of them on the page. So, I cannot access...
3
by: PVACC | last post by:
I have a line of code thus: w3('<input type=radio name=rad onclick="parent.mySub('+i+')">'); The function w3() writes the code in an iframe. I need to set a variable "start" to the value "1"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.