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.W ebControls
Namespace MessageBox
Public Class ShowMsgBox : Inherits Button
Protected Overrides Sub AddAttributesTo Render(ByVal Output As
HtmlTextWriter)
MyBase.AddAttri butesToRender(O utput)
Dim jsScript As String
jsScript = alert("Some Message Here")
Output.AddAttri bute(HtmlTextWr iterAttribute.O nClick,
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 AddAttributesTo Render(ByVal Output As
HtmlTextWriter)
MyBase.AddAttri butesToRender(O utput)
Output.AddAttri bute(HtmlTextWr iterAttribute.O nClick,
"ShowMsg()" )
End Sub
Protected Overrides Sub RenderContents( ByVal Output As
HtmlTextWriter)
Output.Write("< script language='JavaS cript'>")
Output.Write(vb CrLf)
Output.Write("f unction ShowMsg(){")
Output.Write(vb CrLf)
Output.Write("a lert('Some Message Here')")
Output.Write(vb CrLf)
Output.Write("} ")
Output.Write(vb CrLf)
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="ShowMsgBo x1" value="CLICK"
onclick="javasc ript:WebForm_Do PostBackWithOpt ions(new
WebForm_PostBac kOptions(" ShowMsgBox1&quo t;, "" , true,
"" , "" , false, false))" id="ShowMsgBox1 "
onclick="ShowMs g()" />
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?