473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Custom Control

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.OnClic k,
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.OnClic k,
"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(&quot;ShowMsgBox1&quot;, &quot;&quot;, true,
&quot;&quot;, &quot;&quot;, 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?

Oct 30 '06 #1
1 4728
After shooting a lot of arrows in the dark, I could finally nab the
culprit but still have been unable to resolve the issue.

Actually the ASPX page that uses the Button custom control also makes
use of a user control which encapsulates a few TextBoxes. All the
TextBoxes are accompanied by validation controls & the presence of
these validation controls is causing the Button source code to have 2
'onclick' events which, in turn, is preventing the JavaScript function
named 'ShowMsgBox' from getting invoked when this Button custom control
is clicked. If I get rid of the validation controls, then the source
code of the Button custom control changes to the more conventional one
with just one 'onclick' event:

<input type="submit" name="ShowMsgBox1" value="CLICK" id="ShowMsgBox1"
onclick="ShowMsg()"/>
Now, the JavaScript alert message pops-up when Button custom control is
clicked.

The problem is I just can't do without the validation controls for the
TextBoxes in the user control but at the same time, they are preventing
the JavaScript alert message from popping-up.

Any workaround to this?
rn**@rediffmail.com wrote:
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.OnClic k,
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.OnClic k,
"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(&quot;ShowMsgBox1&quot;, &quot;&quot;, true,
&quot;&quot;, &quot;&quot;, 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?
Oct 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Christian H | last post by:
Hi! I've created a custom control (myDrawControl) that deals with drawing. This control is then added to a form( myMainForm) Now, whenever something is dragged and dropped onto myDrawControl ,...
15
by: Tinus | last post by:
Hello all, I've created a custom control that draws a monthly schedule (using the Draw function in C#). Basically it draws 31 boxes and writes the day number in every box. This works...
21
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a...
1
by: Wannabe_Geek | last post by:
Hi Iam new to MS .Net technology just getting along with it....I created a custom control ,which takes in a query and displays the data in a tabular format....something similar to a datagrid. ...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
4
by: Smokey Grindle | last post by:
What is the best way to write dynamic controls in ASP.NET 2.0?
11
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.