473,734 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button & TextBox Custom Control

I want to create a custom control that encapsulates a Button & a
TextBox. When the Button is clicked, the user is asked a question using
JavaScript confirm (which shows 2 buttons - 'OK' & 'Cancel'). Till this
point, no problem. Initially, the TextBox is empty. The Button has a
property named 'ConfirmMessage ' so that the developer using this custom
control can modify the question in the confirm dialog.

If the user clicks 'OK', I want the text in the TextBox to change to
True. If the user clicks 'Cancel', the text in the TextBox should
change to False. This is where I am getting stuck. First of all, how do
I add a TextBox to the custom control & secondly, how do I change the
text in the TextBox depending upon whether the user has clicked 'OK' or
'Cancel' in the JavaScript confirm dialog.

I have come this far (this code exists in a VB class file):

Namespace Confirm
Public Class ShowConfirm : Inherits Button
Private strConfirmMsg As String
Public WriteOnly Property ConfirmMessage( ) As String
Set(ByVal value As String)
strConfirmMsg = value
End Set
End Property

Protected Overrides Sub AddAttributesTo Render(ByVal Output As
HtmlTextWriter)
MyBase.AddAttri butesToRender(O utput)
Output.AddAttri bute(HtmlTextWr iterAttribute.O nClick,
"ConfirmMsg ()")
End Sub

Protected Overrides Sub RenderContents( ByVal Output As
HtmlTextWriter)
Output.Write(vb CrLf)
Output.Write("< script language='JavaS cript'>")
Output.Write(vb CrLf)
Output.Write("f unction ConfirmMsg(){")
Output.Write(vb CrLf)
Output.Write(vb Tab)
Output.Write("v ar answer = confirm('")
If (strConfirmMsg <"") Then
Output.Write(st rConfirmMsg)
Else
Output.Write("A re You Sure You Want To Exit?")
End If
Output.Write("' )")
Output.Write(vb CrLf)
Output.Write("} ")
Output.Write(vb CrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace

Can someone please tell me how do I add a TextBox in the above custom
control & change the text in the TextBox depending upon whether the
user has clicked 'OK' or 'Cancel' in the JavaScript confirm dialog?

Oct 31 '06 #1
1 3227
Well I have resolved the problem I was facing (as described in post
#1). This is how I did it:

Namespace Confirm
Public Class ShowConfirm : Inherits Button
Private strConfirmMsg As String
Public WriteOnly Property ConfirmMessage( ) As String
Set(ByVal value As String)
strConfirmMsg = value
End Set
End Property

Protected Overrides Sub AddAttributesTo Render(ByVal Output As
HtmlTextWriter)
MyBase.AddAttri butesToRender(O utput)
Output.AddAttri bute(HtmlTextWr iterAttribute.O nClick,
"ConfirmMsg ()")
End Sub

Protected Overrides Sub RenderContents( ByVal Output As
HtmlTextWriter)
Dim pnlConfirm As Panel
Dim txtConfirm As TextBox

pnlConfirm = New Panel
txtConfirm = New TextBox
txtConfirm.ID = "txtConfirm "
txtConfirm.Enab leViewState = True

pnlConfirm.Cont rols.Add(txtCon firm)
Controls.Add(pn lConfirm)
pnlConfirm.Rend erControl(Outpu t)

Output.Write(vb CrLf)
Output.Write("< script language='JavaS cript'>")
Output.Write(vb CrLf)
Output.Write("f unction ConfirmMsg(){")
Output.Write(vb CrLf)
Output.Write(vb Tab)
Output.Write("v ar answer = confirm('")
If (strConfirmMsg <"") Then
Output.Write(st rConfirmMsg)
Else
Output.Write("A re You Sure You Want To Exit?")
End If
Output.Write("' )")
Output.Write(vb CrLf)
Output.Write(vb Tab)
Output.Write("d ocument.forms[0].txtConfirm.val ue = answer")
Output.Write(vb CrLf)
Output.Write("} ")
Output.Write(vb CrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace

The above custom control changes the text in the TextBox to True &
False when the user clicks 'OK' & 'Cancel' in the JavaScript confirm
dialog respectively. That serves my purpose but I have encountered a
new problem.

As already mentioned, when the user clicks 'OK' or 'Cancel' in the
confirm dialog, the text in the TextBox changes to True & False
respectively but when the page gets posted, the TextBox loses its value
immediately after post back though I have set the 'EnableViewStat e'
property of the TextBox to true. How do I resolve this problem?

rn**@rediffmail .com wrote:
I want to create a custom control that encapsulates a Button & a
TextBox. When the Button is clicked, the user is asked a question using
JavaScript confirm (which shows 2 buttons - 'OK' & 'Cancel'). Till this
point, no problem. Initially, the TextBox is empty. The Button has a
property named 'ConfirmMessage ' so that the developer using this custom
control can modify the question in the confirm dialog.

If the user clicks 'OK', I want the text in the TextBox to change to
True. If the user clicks 'Cancel', the text in the TextBox should
change to False. This is where I am getting stuck. First of all, how do
I add a TextBox to the custom control & secondly, how do I change the
text in the TextBox depending upon whether the user has clicked 'OK' or
'Cancel' in the JavaScript confirm dialog.

I have come this far (this code exists in a VB class file):

Namespace Confirm
Public Class ShowConfirm : Inherits Button
Private strConfirmMsg As String
Public WriteOnly Property ConfirmMessage( ) As String
Set(ByVal value As String)
strConfirmMsg = value
End Set
End Property

Protected Overrides Sub AddAttributesTo Render(ByVal Output As
HtmlTextWriter)
MyBase.AddAttri butesToRender(O utput)
Output.AddAttri bute(HtmlTextWr iterAttribute.O nClick,
"ConfirmMsg ()")
End Sub

Protected Overrides Sub RenderContents( ByVal Output As
HtmlTextWriter)
Output.Write(vb CrLf)
Output.Write("< script language='JavaS cript'>")
Output.Write(vb CrLf)
Output.Write("f unction ConfirmMsg(){")
Output.Write(vb CrLf)
Output.Write(vb Tab)
Output.Write("v ar answer = confirm('")
If (strConfirmMsg <"") Then
Output.Write(st rConfirmMsg)
Else
Output.Write("A re You Sure You Want To Exit?")
End If
Output.Write("' )")
Output.Write(vb CrLf)
Output.Write("} ")
Output.Write(vb CrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace

Can someone please tell me how do I add a TextBox in the above custom
control & change the text in the TextBox depending upon whether the
user has clicked 'OK' or 'Cancel' in the JavaScript confirm dialog?
Oct 31 '06 #2

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

Similar topics

2
1747
by: Joseph | last post by:
Hi everyone, Is is possible and how would I implemente dragging and dropping a value in a textbox so that it would clear the existing value in the textbox, if it has one already? TIA Joseph philippeoget at hotmail dot com
2
15726
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New Record button is clicked. The code checks the table for the highest value and then assigns 1 and inserts the value. I have a second text box which needs the same type of custom auto-number which has to be generated from a second command button. ...
1
2629
by: Martin | last post by:
Hi, I have produced a custom server control that simple outputs a row of 26 buttons, one button for each letter of the english alphabet. now what I would like to do is catch the button click inside the server control when it is clicked on. however when I click on a button at present I get an error saying that the An error has occurred because a control with auto-generated id
2
2786
by: melanieab | last post by:
Hi, Before I go into detail, is there any way to force a button to get that dotted box on it that shows it's in focus? Just saying btn1.Focus(); isn't working for me. Btn1 is definitely the thing being focused on, but you wouldn't know by just looking at it. And it seems that the only way to get a button to show highlight is to Tab into it. So, the weird details... Say I put a custom button on my form (and gave it tabstop 1). I then add...
0
1049
by: campwes | last post by:
I am trying to simulate multiple web pages by putting the content within panel controls, and then changing the visibility as needed: panel1.Visible = False panel2.Visible = True In panel1, there is a user control with a textbox and submit button. After entering text and clicking the button, a custom event is fired that causes the textbox data to be used in an SQL query in the 2nd control in panel2. Panel2 then shows the results...
3
5516
by: Jay | last post by:
I am on the 2.0 framework and have run the c:\windows\microsoft.net \framework\v1.1.4322\aspnet_regiis.exe -c and had no success. About half of the buttons on my webforms are firing and the other half are not, primarily anything on the Master is firing but those in the content pane are not. This was working fine yesterday!! I've reviewed all the code changes and can't seem to find a culprit. Here's one example of what I'm trying to...
1
1646
by: Forumtroll | last post by:
I have a Web User Control that parses an XML file and renders a Form based on the XML. The problem is that I create a button on the bottom of the form that will fire off a subscribeable event, but somehow the button never seem to fire that particular event. The code is attached below. using System; using System.Collections;
6
3762
by: Tom P. | last post by:
I'm trying to make one of our perennial favorites - The Syntax Color Editor. (Mostly as a learning exercise). I'm wondering if there is a way to capture the Paint event of a textbox so I can render the text myself. I've tried to replicate the functionality of a textbox, but I think it would be easier to simply take over the painting of a plain textbox. Then I wouldn't have to deal with several problem areas I'm currently running into.
7
3088
by: adiel_g | last post by:
Hello Everyone, I created a custom control. On the CreateChildControls, I added a textbox to the control as follows: // TextBox TextBox txtValue = new TextBox(); txtValue.ID = "txtValue"; protected override void CreateChildControls() { // Add the control to the form
0
9310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.