473,233 Members | 1,569 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,233 software developers and data experts.

Custom Control Again

A custom control is derived from the WebControl class & encapsulates a
TextBox & a Button. When the Button is clicked, the user is shown the
JavaScript confirm dialog with the 'OK' & 'Cancel' buttons. If the user
clicks 'OK', the TextBox gets populated with 'true' & if 'Cancel' is
clicked, the TextBox gets populated with 'false'. Note that when the
user first comes to the ASPX page that uses this custom control, the
TextBox is empty. This is the code in the VB class file:

Namespace MyNS
Public Class MyCls : Inherits WebControl
Protected Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
Dim txt1 As TextBox
Dim btn1 As Button

txt1 = New TextBox
btn1 = New Button

txt1.ID = "txt1"
Me.Controls.Add(txt1)

btn1.ID = "btn1"
btn1.Text = "CLICK"
btn1.Attributes.Add("OnClick", "ConfirmMsg(); return
false;")
Me.Controls.Add(btn1)

ChildControlsCreated = True
End Sub

Protected Overrides Sub RenderContents(ByVal Output As
HtmlTextWriter)
MyBase.RenderContents(Output)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg()")
Output.Write(vbCrLf)
Output.Write("var answer = confirm('Are U Sure?'))
Output.Write(vbCrLf)
Output.Write("document.forms[0].txt1.value = answer")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace

The above custom control, when used in a ASPX page, does pop-up the
JavaScript confirm dialog & depending upon whether the user has clicked
'OK' or 'Cancel', the TextBox gets populated with 'true' & 'false'
respectively.

The problem I am facing is how do I make the ASPX page get the value of
the TextBox. Any ideas on how do I go about it?

Another problem I am facing is when the ASPX page has validation
controls. If the ASPX page does not have any validation controls, then
when I have a look at the HTML source code of the ASPX page, the source
of the Button control looks like this:

<input type="submit" name="btn1" value="QUIT" onclick="ConfirmMsg();
return false;" id="btn1" />

But if the ASPX page has validation controls, when the Button is
clicked, the JavaScript confirm dialog doesn't pop-up. The source code
of the Button control also shows 2 OnClick events:

<input type="submit" name="btn1" value="QUIT"
onclick="javascript:WebForm_DoPostBackWithOptions( new
WebForm_PostBackOptions(&quot;btn1&quot;, &quot;&quot;, true,
&quot;&quot;, &quot;&quot;, false, false))" id="btn1"
onclick="ConfirmMsg();return false;"/>

How do I make the Button in the custom control work in the norwal way
when the ASPX page has got validation controls?

Nov 4 '06 #1
0 1367

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

Similar topics

8
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn...
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...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
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...
5
by: Alan Silver | last post by:
Hello, I have a products page that takes a product ID in the query string. Based on the product details (from a database), the page then loads up one of a number of custom controls, calls a...
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...
1
by: rizwanahmed24 | last post by:
Hello i have created a custom control. i have placed two template controls on it. One is check box and second is picture box. The custom control also contain two picture boxes as property. These...
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...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.