473,327 Members | 2,094 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,327 software developers and data experts.

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 AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClic k,
"ConfirmMsg()")
End Sub

Protected Overrides Sub RenderContents(ByVal Output As
HtmlTextWriter)
Output.Write(vbCrLf)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg(){")
Output.Write(vbCrLf)
Output.Write(vbTab)
Output.Write("var answer = confirm('")
If (strConfirmMsg <"") Then
Output.Write(strConfirmMsg)
Else
Output.Write("Are You Sure You Want To Exit?")
End If
Output.Write("')")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
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 3161
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 AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClic k,
"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.EnableViewState = True

pnlConfirm.Controls.Add(txtConfirm)
Controls.Add(pnlConfirm)
pnlConfirm.RenderControl(Output)

Output.Write(vbCrLf)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg(){")
Output.Write(vbCrLf)
Output.Write(vbTab)
Output.Write("var answer = confirm('")
If (strConfirmMsg <"") Then
Output.Write(strConfirmMsg)
Else
Output.Write("Are You Sure You Want To Exit?")
End If
Output.Write("')")
Output.Write(vbCrLf)
Output.Write(vbTab)
Output.Write("document.forms[0].txtConfirm.value = answer")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
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 'EnableViewState'
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 AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClic k,
"ConfirmMsg()")
End Sub

Protected Overrides Sub RenderContents(ByVal Output As
HtmlTextWriter)
Output.Write(vbCrLf)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg(){")
Output.Write(vbCrLf)
Output.Write(vbTab)
Output.Write("var answer = confirm('")
If (strConfirmMsg <"") Then
Output.Write(strConfirmMsg)
Else
Output.Write("Are You Sure You Want To Exit?")
End If
Output.Write("')")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
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
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...
2
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...
1
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...
2
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...
0
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,...
3
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...
1
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...
6
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...
7
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"; ...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.