Showing posts with label namespace. Show all posts
Showing posts with label namespace. Show all posts

Thursday, March 22, 2012

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):

<%@dotnet.itags.org. 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?Anyone?

rn5a@.rediffmail.com wrote:

Quote:

Originally Posted by

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?

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.OnClick, "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 intoConfirm.dll. This is how I am using the above custom control in an ASPX page (assume that the ASPX page is namedConfirm.aspx):

<%@dotnet.itags.org. 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 (which is highlighted) 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 JavaScriptconfirm dialog pops-up with 2 buttons -OK &Cancel. IfOK is clicked, the value of the JavaScript variableanswer istrue & ifCancel is clicked, the value of the variableanswer isfalse.

What I want is irrespective of whether a user clicks theOK orCancel button in theconfirm dialog, instead of posting back to itself using the conventional POST method, I want the ASPX page to post to itself BUT with a querystringProceed=<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 theOK button or theCancel button in theconfirm dialog. If the user clicksOK, he will be taken to

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

On the other hand, if the user clicksCancel in theconfirm dialog, he will be taken to

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

Can this be done in anyway?

Output.AddAttribute(HtmlTextWriterAttribute.OnClick, "ConfirmMsg();return false;")


Thanks, mate, your suggestion turned out to be a great one. Could you please tell me what role doesreturn=false; which you have appended afterConfirmMsg(), play here?

Going by your suggestion does add the querystringProceed=<value> at the end of the URL but there's a *** here. Suppose when a user clicks the server-side Button; he is shown the JavaScriptconfirm dialog with theOK &Cancel buttons. If the user clicksOK, then he is taken to

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

That's fine but if the user clicks the server-side Button once again & clicksCancel in theconfirm dialog, then he is taken to

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

i.e. the querystring gets appended twice. In other words, a querystringProceed=<value> will go on getting appended at the URL wheneverOK &Cancel is clicked in the JavaScriptconfirm dialog. For e.g. if a user clicks eitherOK orCancel in theconfirm dialog 5 times, then the querystring will get appended one after the other 5 times.

Any workaround to overcome this?

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.OnClick,
"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):
<%@dotnet.itags.org. 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?Anyone?
rn5a@.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.OnClick,
> "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?

SuppressUnmanagedCodeSecurity

I'm having trouble using the SuppressUnmanagedCodeSecurity attribute.
When I try to compile, I get an error saying that the namespace is not
known.
Any ideas please ?
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.comSeems odd, Michael. The following compiles fine, so I'm guessing some
other problem exists.
using System.Security;
[SuppressUnmanagedCodeSecurity]
public class NativeMethods
{
// ...
}
Scott
http://www.OdeToCode.com/blogs/scott/
On Sat, 3 Dec 2005 22:08:15 -0800, "Michael Tissington"
<mtissington@.newsgroups.nospam> wrote:

>I'm having trouble using the SuppressUnmanagedCodeSecurity attribute.
>When I try to compile, I get an error saying that the namespace is not
>known.
>Any ideas please ?
Hi Michael,
As for the "namespace not known..." error when you try using the
SuppressUnmanagedCodeSecurity Attribute , I think it may be caused by the
namespace of the SuppressUnmanagedCodeSecurity class is not imported in
your code file. Have you add the folloing line in your code file:
using System.Security;
or Imports System.Security for VB.NET
The SuppressUnmanagedCodeSecurity class is under the "System.Security
namespace" so we have to import the namspace if we don't specify the full
class name like:
System.Security.SuppressUnmanagedCodeSecurity
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
| From: "Michael Tissington" <mtissington@.newsgroups.nospam>
| Subject: SuppressUnmanagedCodeSecurity
| Date: Sat, 3 Dec 2005 22:08:15 -0800
| Lines: 13
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <e9i4ckJ#FHA.2176@.TK2MSFTNGP14.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 65.249.55.7
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:362561
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I'm having trouble using the SuppressUnmanagedCodeSecurity attribute.
|
| When I try to compile, I get an error saying that the namespace is not
| known.
|
| Any ideas please ?
|
| --
| Michael Tissington
| http://www.oaklodge.com
| http://www.tabtag.com
|
|
|