469,329 Members | 1,503 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Suppress Form Action

A custom server control has a Button.

Namespace Confirm
Public Class ShowConfirm : Inherits Button
Private strConfirmMsg As String
Public Property ConfirmMessage() As String
Get
ConfirmMessage = strConfirmMsg
End Get
Set(ByVal value As String)
strConfirmMsg = value
End Set
End Property

Protected Overrides Sub AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClic k,
"ConfirmMsg()")
End Sub

Protected Overrides Sub RenderContents(ByVal Output As
HtmlTextWriter)
Output.Write(vbCrLf)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg(){")
Output.Write(vbCrLf)
Output.Write("var answer = confirm('")
Output.Write(strConfirmMsg)
Output.Write("')")
Output.Write(vbCrLf)

Output.Write("location.href = window.location.href +
'?Proceed=' + answer")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace

Using VBC, I compiled the above into 'Confirm.dll'. This is how I am
using the above custom control in an ASPX page (assume that the ASPX
page is named Confirm.aspx):

<%@ Register Assembly="Confirm" Namespace="Confirm" TagPrefix="CC" %>

<form EnableViewState="true" runat="server">
<CC:ShowConfirm ID="ShowConfirm1" ConfirmMessage="WANNA EXIT?"
Text="EXIT" runat="server"/>
</form>

Note the

Output.Write("location.href = window.location.href + '?Proceed=' +
answer")

line in the VB class file code. When the ASPX page gets rendered, it
displays a Button. Conventionally, when a Button is clicked in an ASPX
page, it posts back to itself using the POST method. When the Button in
the above custom control is clicked, a JavaScript confirm dialog
pops-up with 2 buttons - 'OK' & 'Cancel'. If 'OK' is clicked, the value
of the JavaScript variable 'answer' is true & if 'Cancel' is clicked,
the value of the variable 'answer' is false.

What I want is irrespective of whether a user clicks the 'OK' or
'Cancel' button in the confirm dialog, instead of posting back to
itself using the conventional POST method, I want the ASPX page to post
to itself BUT with a querystring 'Proceed=<value>' appended i.e. I want
to suppress the conventional post & instead add the querystring so that
I can find out whether the user has clicked the 'OK' button or the
'Cancel' button in the confirm dialog. If the user clicks 'OK', he will
be taken to

http://myserver/aspx/Confirm.aspx?Proceed=true

If the user clicks 'Cancel' in the confirm dialog, he will be taken to

http://myserver/aspx/Confirm.aspx?Proceed=false

Can this be done in anyway?

Oct 31 '06 #1
1 1459
Anyone???

rn**@rediffmail.com wrote:
A custom server control has a Button.

Namespace Confirm
Public Class ShowConfirm : Inherits Button
Private strConfirmMsg As String
Public Property ConfirmMessage() As String
Get
ConfirmMessage = strConfirmMsg
End Get
Set(ByVal value As String)
strConfirmMsg = value
End Set
End Property

Protected Overrides Sub AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClic k,
"ConfirmMsg()")
End Sub

Protected Overrides Sub RenderContents(ByVal Output As
HtmlTextWriter)
Output.Write(vbCrLf)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg(){")
Output.Write(vbCrLf)
Output.Write("var answer = confirm('")
Output.Write(strConfirmMsg)
Output.Write("')")
Output.Write(vbCrLf)

Output.Write("location.href = window.location.href +
'?Proceed=' + answer")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace

Using VBC, I compiled the above into 'Confirm.dll'. This is how I am
using the above custom control in an ASPX page (assume that the ASPX
page is named Confirm.aspx):

<%@ Register Assembly="Confirm" Namespace="Confirm" TagPrefix="CC" %>

<form EnableViewState="true" runat="server">
<CC:ShowConfirm ID="ShowConfirm1" ConfirmMessage="WANNA EXIT?"
Text="EXIT" runat="server"/>
</form>

Note the

Output.Write("location.href = window.location.href + '?Proceed=' +
answer")

line in the VB class file code. When the ASPX page gets rendered, it
displays a Button. Conventionally, when a Button is clicked in an ASPX
page, it posts back to itself using the POST method. When the Button in
the above custom control is clicked, a JavaScript confirm dialog
pops-up with 2 buttons - 'OK' & 'Cancel'. If 'OK' is clicked, the value
of the JavaScript variable 'answer' is true & if 'Cancel' is clicked,
the value of the variable 'answer' is false.

What I want is irrespective of whether a user clicks the 'OK' or
'Cancel' button in the confirm dialog, instead of posting back to
itself using the conventional POST method, I want the ASPX page to post
to itself BUT with a querystring 'Proceed=<value>' appended i.e. I want
to suppress the conventional post & instead add the querystring so that
I can find out whether the user has clicked the 'OK' button or the
'Cancel' button in the confirm dialog. If the user clicks 'OK', he will
be taken to

http://myserver/aspx/Confirm.aspx?Proceed=true

If the user clicks 'Cancel' in the confirm dialog, he will be taken to

http://myserver/aspx/Confirm.aspx?Proceed=false

Can this be done in anyway?
Nov 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Krishna Srinivasan | last post: by
2 posts views Thread by theintrepidfox | last post: by
3 posts views Thread by John Michael | last post: by
7 posts views Thread by Marco Roberto | last post: by
4 posts views Thread by =?Utf-8?B?UmljaA==?= | last post: by
8 posts views Thread by thelma | last post: by
1 post views Thread by chromis | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.