473,401 Members | 2,127 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,401 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 1373

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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.