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

How to choose what control will receive action

Dear Friends,

I have the following code that creates dynamic controls at my form.

My dificult is how to correct this code to put distinct AddHandler to each
button and how to choose what label will receive text when Button1 is
clickedor Button2 is clicked.

I want to make possible to change text on Label1 when Button1 is clicked and
change text on Label2 when Button2 is clicked .. and so on...

Regards
Robson Machado

ASPX CODE:
---------------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="dynamic.aspx.vb"
Inherits="corretoresdeseguros.dynamic"%>
<HTML>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>
</form>
</body>
</HTML>
CODEBEHIND:
----------------

Public Class dynamic
Inherits System.Web.UI.Page
Dim myLabel As Label
Dim myRadio As RadioButtonList
Dim myRFV As RequiredFieldValidator
Dim myText As TextBox
Dim myButton As Button
Dim myUnits As System.Web.UI.WebControls.Unit

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
AddControls(1, 1, "Label1", "Label")
AddControls(1, 2, "Label2", "Label")
AddControls(1, 1, "Button1", "Button")
AddControls(1, 2, "Button2", "Button")
End Sub
Sub AddControls(ByVal Index As Integer, ByVal QNum As Long, ByVal
LabelText As String, ByVal Type As String)
If Type = "Label" Then
' Add Label
myLabel = New Label
myLabel.ID = "LabelQ" & QNum
myLabel.Text = LabelText & "<br><br>"
myLabel.BorderStyle = 2
PlaceHolder1.Controls.Add(myLabel)
End If

If Type = "Radio" Then
' Add Radio
myRadio = New RadioButtonList
myRadio.ID = "RadioQ" & QNum
myRadio.Items.Add("0")
myRadio.Items.Add("1")
myRadio.Items.Add("2")
myRadio.Items.Add("3")
myRadio.Items.Add("4")
myRadio.Items.Add("5")
myUnits = New System.Web.UI.WebControls.Unit(402)
myRadio.Width = myUnits
myRadio.RepeatDirection = 0
PlaceHolder1.Controls.Add(myRadio)
End If

If Type = "RFV" Then
' Add RFV
myRFV = New RequiredFieldValidator
myRFV.ID = "RFVQ" & QNum
myRFV.ErrorMessage = "Unanswered"
myRFV.ControlToValidate = "RadioQ" & QNum
PlaceHolder1.Controls.Add(myRFV)
End If

If Type = "Button" Then
myButton = New Button
myButton.ID = "Button" & QNum
myButton.Text = LabelText
PlaceHolder1.Controls.Add(myButton)
With myButton
AddHandler .Click, AddressOf Button1_Click
End With
End If

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
myLabel.Text = "Button Clicked"
End Sub
End Class

Nov 18 '05 #1
0 1030

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

Similar topics

4
by: QQ | last post by:
Hello I am a newbie on network programming. I am trying to receive a packet if((numbytes = recvfrom(udp_fd1, buf, MAXLEN-1, 0,(struct sockaddr*)&register_addr, &addr_len))==-1){ fprintf(stderr,...
4
by: Horatiu Ripa | last post by:
1. I have an image list defined in a control 2. I want to expose trough properties the image list in a manner to be able to change it from the container where the control is used. How do I do...
2
by: rawCoder | last post by:
Hi I am having this InvalidOperationException with message Cannot call Invoke or InvokeAsync on a control until the window handle has been created This is raised when i try to invoke a method...
6
by: Test Message | last post by:
I need to dynamically add an html control to a web form. What I have, thus far, adds the control to the page, but only places it after the closing "</html>" tag. ...
4
by: Ryan Liu | last post by:
TcpClient has a method called GetworkStream GetStream(); So in other words, there is only one stream associate with it for input and output, right? So while it is receiving, it can not send, and...
0
by: palomine1234 | last post by:
PAYPAL MAGIC!!! TURN $5 INTO $15,000 IN ONLY 30 DAYS...HERES HOW! This is a Money Scheme and Not, I repeat... This is Not a Scam!!!
12
by: cj | last post by:
I would like to have menu items a main menu bar that represent the days of the week. When you click on them they alternate from checked to unchecked. Right now I have 7 subs that look like this...
4
by: wardy | last post by:
Hi all, Looking for a bit of help with this one...I have a situation where I need to be able to determine the control that initiated a form's submit action in client-side Javascript. I am...
15
by: squrel | last post by:
Hi everyone.. i need ur help once more time.... i have a form called reminder..in tht form i have: txtid, txtcaseid, txtreminder, cmbremindby(system or user), txtremindto, dtpreminddt,...
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
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?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.