R
rn5a
I have created a custom control button which when clicked displays a
message in the JavaScript alert dialog. I could successfully compile
the VB class file into a DLL & also could add it to the Toolbox in
Visual Web Developer 2005 Express Edition but the alert message isn't
popping up when I am implementing this control in an ASP.NET page &
clicking the Button in the ASPX page. This is the class file:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace MessageBox
Public Class ShowMsgBox : Inherits Button
Protected Overrides Sub AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Dim jsScript As String
jsScript = alert("Some Message Here")
Output.AddAttribute(HtmlTextWriterAttribute.OnClick,
jsScript)
End Sub
End Class
End Namespace
This is the second way I tried it but this doesn't work as well
Namespace MessageBox
Public Class ShowMsgBox : Inherits Button
Protected Overrides Sub AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClick,
"ShowMsg()")
End Sub
Protected Overrides Sub RenderContents(ByVal Output As
HtmlTextWriter)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ShowMsg(){")
Output.Write(vbCrLf)
Output.Write("alert('Some Message Here')")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace
When I have a look at the source code, I find that the source code of
the button has 2 'onclick' events i.e. the button code looks like this:
<input type="submit" name="ShowMsgBox1" value="CLICK"
onclick="javascript:WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("ShowMsgBox1", "", true,
"", "", false, false))" id="ShowMsgBox1"
onclick="ShowMsg()" />
Where is the first 'onclick' event coming from? I guess that's the
cause of the problem.
Can someone please help me resolve this issue?
message in the JavaScript alert dialog. I could successfully compile
the VB class file into a DLL & also could add it to the Toolbox in
Visual Web Developer 2005 Express Edition but the alert message isn't
popping up when I am implementing this control in an ASP.NET page &
clicking the Button in the ASPX page. This is the class file:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace MessageBox
Public Class ShowMsgBox : Inherits Button
Protected Overrides Sub AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Dim jsScript As String
jsScript = alert("Some Message Here")
Output.AddAttribute(HtmlTextWriterAttribute.OnClick,
jsScript)
End Sub
End Class
End Namespace
This is the second way I tried it but this doesn't work as well
Namespace MessageBox
Public Class ShowMsgBox : Inherits Button
Protected Overrides Sub AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClick,
"ShowMsg()")
End Sub
Protected Overrides Sub RenderContents(ByVal Output As
HtmlTextWriter)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ShowMsg(){")
Output.Write(vbCrLf)
Output.Write("alert('Some Message Here')")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace
When I have a look at the source code, I find that the source code of
the button has 2 'onclick' events i.e. the button code looks like this:
<input type="submit" name="ShowMsgBox1" value="CLICK"
onclick="javascript:WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("ShowMsgBox1", "", true,
"", "", false, false))" id="ShowMsgBox1"
onclick="ShowMsg()" />
Where is the first 'onclick' event coming from? I guess that's the
cause of the problem.
Can someone please help me resolve this issue?