By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,915 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,915 IT Pros & Developers. It's quick & easy.

confirm messagebox, but after onclick firing

P: n/a
I can create Javascript confirm message boxes during page creation, etc
adding them to the button attributes (many good posts on this!). But how can
I add this event after the button is pressed?
I have created an Is_Dirty routine checking for field changes on my page
then if the user clicks on the "exit" button I check for Is_Dirty = true and
want to ask then "do you want to exit without saving?". It's a code behind
where if the value of Is_Dirty = True then I want to display the messagebox
with return confirm. So if the user clicks "cancel" then they are back on the
form.
I've tried:
1.) But return can not be used in front of confirm, I get an error, but
works without confirm.
Dim popupScript As String = "<script language='javascript'>" & _
"confirm(""Are you sure you want to exit without saving
changes?"");" & _
"</script>"
Response.Write(popupScript)

Any ideas? thanx.
Nov 19 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
I would try an if statement inside the onclick event of the ok button and for
the true part of the if statement, I would insert the
page.getpostbackeventreference ....
How does that sound?
Nov 19 '05 #2

P: n/a
The cancel button is "CausesValidation="False" " so there is no post back. I
do this to handle the page validation, thus, removing it.
So I thought there was a way to put it in the stream somehow? HTML Stream?
Is there another page property to access for this?
As I can insert the confirm but without the return? With the return I get
"return statement out of function" Javascript page error??????

thanx.

"vbMental" wrote:
I would try an if statement inside the onclick event of the ok button and for
the true part of the if statement, I would insert the
page.getpostbackeventreference ....
How does that sound?

Nov 19 '05 #3

P: n/a
What about implementing Is_Dirty on client side?

Eliyahu

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:AE**********************************@microsof t.com...
I can create Javascript confirm message boxes during page creation, etc
adding them to the button attributes (many good posts on this!). But how can I add this event after the button is pressed?
I have created an Is_Dirty routine checking for field changes on my page
then if the user clicks on the "exit" button I check for Is_Dirty = true and want to ask then "do you want to exit without saving?". It's a code behind
where if the value of Is_Dirty = True then I want to display the messagebox with return confirm. So if the user clicks "cancel" then they are back on the form.
I've tried:
1.) But return can not be used in front of confirm, I get an error, but
works without confirm.
Dim popupScript As String = "<script language='javascript'>" & _
"confirm(""Are you sure you want to exit without saving
changes?"");" & _
"</script>"
Response.Write(popupScript)

Any ideas? thanx.

Nov 19 '05 #4

P: n/a
I'd prefer doing this on the code-behind (VB) as I am trying to utilize the
..NET capability. I love combining the client/server Windows programming
techniques and web browser client development. Ideally I want to program a
web application as close to that structure as possible. I really like the
control programmically over the controls, etc.
There must be a way to force another event after firing? Since the "return"
statement is error'ing, can I add another Javascript piece to handle the
return?
Can we use any VBScript messagebox objects here? That I can send via the
code-behind?
Thanx.

"Eliyahu Goldin" wrote:
What about implementing Is_Dirty on client side?

Eliyahu

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:AE**********************************@microsof t.com...
I can create Javascript confirm message boxes during page creation, etc
adding them to the button attributes (many good posts on this!). But how

can
I add this event after the button is pressed?
I have created an Is_Dirty routine checking for field changes on my page
then if the user clicks on the "exit" button I check for Is_Dirty = true

and
want to ask then "do you want to exit without saving?". It's a code behind
where if the value of Is_Dirty = True then I want to display the

messagebox
with return confirm. So if the user clicks "cancel" then they are back on

the
form.
I've tried:
1.) But return can not be used in front of confirm, I get an error, but
works without confirm.
Dim popupScript As String = "<script language='javascript'>" & _
"confirm(""Are you sure you want to exit without saving
changes?"");" & _
"</script>"
Response.Write(popupScript)

Any ideas? thanx.


Nov 19 '05 #5

P: n/a
I'm not sure what you mean by putting "it in the stream". What is it you
would like to write into the HTML stream - the client-script? If so, you can
override the OnRender sub and write to the HTMLTextWriter stream, just make
sure to call the base OnRender also.

"Chris" wrote:
The cancel button is "CausesValidation="False" " so there is no post back. I
do this to handle the page validation, thus, removing it.
So I thought there was a way to put it in the stream somehow? HTML Stream?
Is there another page property to access for this?
As I can insert the confirm but without the return? With the return I get
"return statement out of function" Javascript page error??????

thanx.

"vbMental" wrote:
I would try an if statement inside the onclick event of the ok button and for
the true part of the if statement, I would insert the
page.getpostbackeventreference ....
How does that sound?

Nov 19 '05 #6

P: n/a
Can I do an "if then" off of what was chosen in the Javascript messagebox?
Since I can't use a return, all I really need to do is:

if "ok" then redirect, if "cancel" then return to page (really do nothing).

Dim popupScript As String = "<script language='javascript'>" & _
"confirm(""Are you sure you want to exit without saving
changes?"");" & _
"</script>"

like a Javascript returnValue = [window.]confirm(message)
"Ok" would return true, "cancel" would return false.
How could I check that and do my if then statement?

'check for changes on the form
If f_IsDirty = False Then

Response.Redirect("XXXXXX.aspx?c=" & cx & "p=m")

Else

Dim popupScript As String = "<script language='javascript'>" & _
"confirm(""Are you sure you want to exit without saving
changes?"");" & _
"</script>"
Response.Write(popupScript)

Response.Write("form IS dirty<br>")
If ????????.returnValue = true then
Response.Redirect("XXXXXX.aspx?c=" & cx & "p=m")
Else
'Do nothing thus returning to page
End If
End If
"Chris" wrote:
I'd prefer doing this on the code-behind (VB) as I am trying to utilize the
.NET capability. I love combining the client/server Windows programming
techniques and web browser client development. Ideally I want to program a
web application as close to that structure as possible. I really like the
control programmically over the controls, etc.
There must be a way to force another event after firing? Since the "return"
statement is error'ing, can I add another Javascript piece to handle the
return?
Can we use any VBScript messagebox objects here? That I can send via the
code-behind?
Thanx.

"Eliyahu Goldin" wrote:
What about implementing Is_Dirty on client side?

Eliyahu

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:AE**********************************@microsof t.com...
I can create Javascript confirm message boxes during page creation, etc
adding them to the button attributes (many good posts on this!). But how

can
I add this event after the button is pressed?
I have created an Is_Dirty routine checking for field changes on my page
then if the user clicks on the "exit" button I check for Is_Dirty = true

and
want to ask then "do you want to exit without saving?". It's a code behind
where if the value of Is_Dirty = True then I want to display the

messagebox
with return confirm. So if the user clicks "cancel" then they are back on

the
form.
I've tried:
1.) But return can not be used in front of confirm, I get an error, but
works without confirm.
Dim popupScript As String = "<script language='javascript'>" & _
"confirm(""Are you sure you want to exit without saving
changes?"");" & _
"</script>"
Response.Write(popupScript)

Any ideas? thanx.


Nov 19 '05 #7

P: n/a
You can provide a hidden <input> element where you can pass a message from
server to client. In client-side onload event for <body> check the value of
the textbox and if it is not empty use it as a text for a confirm message.

Eliyahu

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
I'd prefer doing this on the code-behind (VB) as I am trying to utilize the .NET capability. I love combining the client/server Windows programming
techniques and web browser client development. Ideally I want to program a
web application as close to that structure as possible. I really like the
control programmically over the controls, etc.
There must be a way to force another event after firing? Since the "return" statement is error'ing, can I add another Javascript piece to handle the
return?
Can we use any VBScript messagebox objects here? That I can send via the
code-behind?
Thanx.

"Eliyahu Goldin" wrote:
What about implementing Is_Dirty on client side?

Eliyahu

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:AE**********************************@microsof t.com...
I can create Javascript confirm message boxes during page creation, etc adding them to the button attributes (many good posts on this!). But how
can
I add this event after the button is pressed?
I have created an Is_Dirty routine checking for field changes on my
page then if the user clicks on the "exit" button I check for Is_Dirty = true and
want to ask then "do you want to exit without saving?". It's a code
behind where if the value of Is_Dirty = True then I want to display the

messagebox
with return confirm. So if the user clicks "cancel" then they are back on the
form.
I've tried:
1.) But return can not be used in front of confirm, I get an error,

but works without confirm.
Dim popupScript As String = "<script language='javascript'>" & _
"confirm(""Are you sure you want to exit without saving
changes?"");" & _
"</script>"
Response.Write(popupScript)

Any ideas? thanx.


Nov 19 '05 #8

P: n/a
And if you to use at button event,
page.RegisterStartUpScript("confirm","<script>conf irm('message');</script>")

Dexter
"Chris" <Ch***@discussions.microsoft.com> escreveu na mensagem
news:AE**********************************@microsof t.com...
I can create Javascript confirm message boxes during page creation, etc
adding them to the button attributes (many good posts on this!). But how
can
I add this event after the button is pressed?
I have created an Is_Dirty routine checking for field changes on my page
then if the user clicks on the "exit" button I check for Is_Dirty = true
and
want to ask then "do you want to exit without saving?". It's a code behind
where if the value of Is_Dirty = True then I want to display the
messagebox
with return confirm. So if the user clicks "cancel" then they are back on
the
form.
I've tried:
1.) But return can not be used in front of confirm, I get an error, but
works without confirm.
Dim popupScript As String = "<script language='javascript'>" & _
"confirm(""Are you sure you want to exit without saving
changes?"");" & _
"</script>"
Response.Write(popupScript)

Any ideas? thanx.

Nov 19 '05 #9

P: n/a
I thought I'd try another approach but am stumped once more.

I modified my "dirty" routine to update the button attributes. Thinking that
the button now will have the onclick routine, i.e.:

Public Sub Is_Dirty(ByVal s As Object, ByVal e As EventArgs)

f_IsDirty = True
btnexit.Attributes.Add("onclick", "return confirm(""Are you sure you
want to exit this without saving?"");")

End Sub
But now once the user clicks the exit button it recongizes that it is
"dirty" if a change was made but the new Onclick doesn't register until the
next time the button is pressed again.
So the question is: if in the code behind there is a Sub for the "Click" and
then you add the attribute for that button for the "click" which is done
first? It appears the Sub that the control has as OnClick="_Click"

control:
<asp:ImageButton id="btnexit" CausesValidation="False"
OnClick="btnexit_Click" ImageURL="images/xxxxx/exit_btn.gif" align="left"
Runat="server" />

so if I press the exit button twice then I get the message box???????? I
rem'd out the redirect to show the "form IS dirty" text so then a can press
the button again to get the message dialog.

Sub btnexit_Click(ByVal s As Object, ByVal e As ImageClickEventArgs)

Dim cnumber As String

'Set concern number
cnumber = txtxxxxxxxx.Text

'check for changes on the form
If f_IsDirty = False Then
'redirect back to concern number
Response.Redirect("xxxxxxxx.aspx?c=" & cnumber & "p=m")
Else

'Response.Redirect("xxxxxxxx.aspx?c=" & cnumber & "p=m")
Response.Write("form IS dirty<br>")

End If

End Sub
"Dexter" wrote:
And if you to use at button event,
page.RegisterStartUpScript("confirm","<script>conf irm('message');</script>")

Dexter
"Chris" <Ch***@discussions.microsoft.com> escreveu na mensagem
news:AE**********************************@microsof t.com...
I can create Javascript confirm message boxes during page creation, etc
adding them to the button attributes (many good posts on this!). But how
can
I add this event after the button is pressed?
I have created an Is_Dirty routine checking for field changes on my page
then if the user clicks on the "exit" button I check for Is_Dirty = true
and
want to ask then "do you want to exit without saving?". It's a code behind
where if the value of Is_Dirty = True then I want to display the
messagebox
with return confirm. So if the user clicks "cancel" then they are back on
the
form.
I've tried:
1.) But return can not be used in front of confirm, I get an error, but
works without confirm.
Dim popupScript As String = "<script language='javascript'>" & _
"confirm(""Are you sure you want to exit without saving
changes?"");" & _
"</script>"
Response.Write(popupScript)

Any ideas? thanx.


Nov 19 '05 #10

P: n/a
not sure I'm following you here? I can create a textbox, but isn't that the
same as making a value equal to booleen? And I can't do this at "onload"
because I need to check to see if one of the form fields that is required has
changed first. Once changed then dirty = true so then if exit is clicked show
message box.
So weather I use the field or set in the code behind the issue still would
be the message box display and return wouldn't it?
thanx.

"Eliyahu Goldin" wrote:
You can provide a hidden <input> element where you can pass a message from
server to client. In client-side onload event for <body> check the value of
the textbox and if it is not empty use it as a text for a confirm message.

Eliyahu

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
I'd prefer doing this on the code-behind (VB) as I am trying to utilize

the
.NET capability. I love combining the client/server Windows programming
techniques and web browser client development. Ideally I want to program a
web application as close to that structure as possible. I really like the
control programmically over the controls, etc.
There must be a way to force another event after firing? Since the

"return"
statement is error'ing, can I add another Javascript piece to handle the
return?
Can we use any VBScript messagebox objects here? That I can send via the
code-behind?
Thanx.

"Eliyahu Goldin" wrote:
What about implementing Is_Dirty on client side?

Eliyahu

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:AE**********************************@microsof t.com...
> I can create Javascript confirm message boxes during page creation, etc > adding them to the button attributes (many good posts on this!). But how can
> I add this event after the button is pressed?
> I have created an Is_Dirty routine checking for field changes on my page > then if the user clicks on the "exit" button I check for Is_Dirty = true and
> want to ask then "do you want to exit without saving?". It's a code behind > where if the value of Is_Dirty = True then I want to display the
messagebox
> with return confirm. So if the user clicks "cancel" then they are back on the
> form.
> I've tried:
> 1.) But return can not be used in front of confirm, I get an error, but > works without confirm.
> Dim popupScript As String = "<script language='javascript'>" & _
> "confirm(""Are you sure you want to exit without saving
> changes?"");" & _
> "</script>"
> Response.Write(popupScript)
>
> Any ideas? thanx.


Nov 19 '05 #11

P: n/a
I figured out that you have to use the autopostback="true" to get the changes
recongized. I don't like the flicker of the page as it posts back to itself
for every field. there must be a better way to do this?????????????
Thanx.

"Chris" wrote:
I thought I'd try another approach but am stumped once more.

I modified my "dirty" routine to update the button attributes. Thinking that
the button now will have the onclick routine, i.e.:

Public Sub Is_Dirty(ByVal s As Object, ByVal e As EventArgs)

f_IsDirty = True
btnexit.Attributes.Add("onclick", "return confirm(""Are you sure you
want to exit this without saving?"");")

End Sub
But now once the user clicks the exit button it recongizes that it is
"dirty" if a change was made but the new Onclick doesn't register until the
next time the button is pressed again.
So the question is: if in the code behind there is a Sub for the "Click" and
then you add the attribute for that button for the "click" which is done
first? It appears the Sub that the control has as OnClick="_Click"

control:
<asp:ImageButton id="btnexit" CausesValidation="False"
OnClick="btnexit_Click" ImageURL="images/xxxxx/exit_btn.gif" align="left"
Runat="server" />

so if I press the exit button twice then I get the message box???????? I
rem'd out the redirect to show the "form IS dirty" text so then a can press
the button again to get the message dialog.

Sub btnexit_Click(ByVal s As Object, ByVal e As ImageClickEventArgs)

Dim cnumber As String

'Set concern number
cnumber = txtxxxxxxxx.Text

'check for changes on the form
If f_IsDirty = False Then
'redirect back to concern number
Response.Redirect("xxxxxxxx.aspx?c=" & cnumber & "p=m")
Else

'Response.Redirect("xxxxxxxx.aspx?c=" & cnumber & "p=m")
Response.Write("form IS dirty<br>")

End If

End Sub
"Dexter" wrote:
And if you to use at button event,
page.RegisterStartUpScript("confirm","<script>conf irm('message');</script>")

Dexter
"Chris" <Ch***@discussions.microsoft.com> escreveu na mensagem
news:AE**********************************@microsof t.com...
I can create Javascript confirm message boxes during page creation, etc
adding them to the button attributes (many good posts on this!). But how
can
I add this event after the button is pressed?
I have created an Is_Dirty routine checking for field changes on my page
then if the user clicks on the "exit" button I check for Is_Dirty = true
and
want to ask then "do you want to exit without saving?". It's a code behind
where if the value of Is_Dirty = True then I want to display the
messagebox
with return confirm. So if the user clicks "cancel" then they are back on
the
form.
I've tried:
1.) But return can not be used in front of confirm, I get an error, but
works without confirm.
Dim popupScript As String = "<script language='javascript'>" & _
"confirm(""Are you sure you want to exit without saving
changes?"");" & _
"</script>"
Response.Write(popupScript)

Any ideas? thanx.


Nov 19 '05 #12

P: n/a
I mean onload event following the postback, after the server side decided
whether to produce the confirmation message or not. If the message should be
produced, the server side will pass the message text (not textbox, it was a
typo, sorry) in the hidden <input> and the client will know whether to call
confirm or not.

Eliyahu

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
not sure I'm following you here? I can create a textbox, but isn't that the same as making a value equal to booleen? And I can't do this at "onload"
because I need to check to see if one of the form fields that is required has changed first. Once changed then dirty = true so then if exit is clicked show message box.
So weather I use the field or set in the code behind the issue still would
be the message box display and return wouldn't it?
thanx.

"Eliyahu Goldin" wrote:
You can provide a hidden <input> element where you can pass a message from server to client. In client-side onload event for <body> check the value of the textbox and if it is not empty use it as a text for a confirm message.
Eliyahu

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
I'd prefer doing this on the code-behind (VB) as I am trying to utilize
the
.NET capability. I love combining the client/server Windows
programming techniques and web browser client development. Ideally I want to program a web application as close to that structure as possible. I really like the control programmically over the controls, etc.
There must be a way to force another event after firing? Since the

"return"
statement is error'ing, can I add another Javascript piece to handle the return?
Can we use any VBScript messagebox objects here? That I can send via the code-behind?
Thanx.

"Eliyahu Goldin" wrote:

> What about implementing Is_Dirty on client side?
>
> Eliyahu
>
> "Chris" <Ch***@discussions.microsoft.com> wrote in message
> news:AE**********************************@microsof t.com...
> > I can create Javascript confirm message boxes during page creation, etc
> > adding them to the button attributes (many good posts on this!).
But how
> can
> > I add this event after the button is pressed?
> > I have created an Is_Dirty routine checking for field changes on
my page
> > then if the user clicks on the "exit" button I check for Is_Dirty
= true
> and
> > want to ask then "do you want to exit without saving?". It's a
code behind
> > where if the value of Is_Dirty = True then I want to display the
> messagebox
> > with return confirm. So if the user clicks "cancel" then they are
back on
> the
> > form.
> > I've tried:
> > 1.) But return can not be used in front of confirm, I get an
error, but
> > works without confirm.
> > Dim popupScript As String = "<script language='javascript'>" & _
> > "confirm(""Are you sure you want to exit without

saving > > changes?"");" & _
> > "</script>"
> > Response.Write(popupScript)
> >
> > Any ideas? thanx.
>
>
>


Nov 19 '05 #13

P: n/a
Hi,

If you want to go to extreme level, try this.

If you are only using IE, then try XMLHttpRequest Object on client side
javascript. You just pass the value and get the result from the server,
without postback.

Prakash.C

"Chris" wrote:
I figured out that you have to use the autopostback="true" to get the changes
recongized. I don't like the flicker of the page as it posts back to itself
for every field. there must be a better way to do this?????????????
Thanx.

"Chris" wrote:
I thought I'd try another approach but am stumped once more.

I modified my "dirty" routine to update the button attributes. Thinking that
the button now will have the onclick routine, i.e.:

Public Sub Is_Dirty(ByVal s As Object, ByVal e As EventArgs)

f_IsDirty = True
btnexit.Attributes.Add("onclick", "return confirm(""Are you sure you
want to exit this without saving?"");")

End Sub
But now once the user clicks the exit button it recongizes that it is
"dirty" if a change was made but the new Onclick doesn't register until the
next time the button is pressed again.
So the question is: if in the code behind there is a Sub for the "Click" and
then you add the attribute for that button for the "click" which is done
first? It appears the Sub that the control has as OnClick="_Click"

control:
<asp:ImageButton id="btnexit" CausesValidation="False"
OnClick="btnexit_Click" ImageURL="images/xxxxx/exit_btn.gif" align="left"
Runat="server" />

so if I press the exit button twice then I get the message box???????? I
rem'd out the redirect to show the "form IS dirty" text so then a can press
the button again to get the message dialog.

Sub btnexit_Click(ByVal s As Object, ByVal e As ImageClickEventArgs)

Dim cnumber As String

'Set concern number
cnumber = txtxxxxxxxx.Text

'check for changes on the form
If f_IsDirty = False Then
'redirect back to concern number
Response.Redirect("xxxxxxxx.aspx?c=" & cnumber & "p=m")
Else

'Response.Redirect("xxxxxxxx.aspx?c=" & cnumber & "p=m")
Response.Write("form IS dirty<br>")

End If

End Sub
"Dexter" wrote:
And if you to use at button event,
page.RegisterStartUpScript("confirm","<script>conf irm('message');</script>")

Dexter
"Chris" <Ch***@discussions.microsoft.com> escreveu na mensagem
news:AE**********************************@microsof t.com...
>I can create Javascript confirm message boxes during page creation, etc
> adding them to the button attributes (many good posts on this!). But how
> can
> I add this event after the button is pressed?
> I have created an Is_Dirty routine checking for field changes on my page
> then if the user clicks on the "exit" button I check for Is_Dirty = true
> and
> want to ask then "do you want to exit without saving?". It's a code behind
> where if the value of Is_Dirty = True then I want to display the
> messagebox
> with return confirm. So if the user clicks "cancel" then they are back on
> the
> form.
> I've tried:
> 1.) But return can not be used in front of confirm, I get an error, but
> works without confirm.
> Dim popupScript As String = "<script language='javascript'>" & _
> "confirm(""Are you sure you want to exit without saving
> changes?"");" & _
> "</script>"
> Response.Write(popupScript)
>
> Any ideas? thanx.

Nov 19 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.