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

firing events

hi all
i need to fire a click events of a button that i add at run time what can i
do??
i need to get a property value of other controls that i add also at runtime
i want to get this property when i click this button
any ideas ??
thanks
Nov 18 '05 #1
2 1188
You need to add an event handler to the click event of the Button, lets say
your button's id is "Button1",

Button1.Click +=new EventHandler(Button1_Click);

where Button1_Click can be substitued with any other method you want, which
has the same signature as the typical button click event handler has

Good Luck

"sara" <sa**@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
hi all
i need to fire a click events of a button that i add at run time what can i do??
i need to get a property value of other controls that i add also at runtime i want to get this property when i click this button
any ideas ??
thanks

Nov 18 '05 #2
Hi Sara,

You need to use AddHandler to create the event and Page.FindControl to get
a reference to the control on the page.

To fire an event, you just call it:
http://msdn.microsoft.com/library/de...rStatement.asp

Some sample code below. Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Public btnOK As Button
Public lblResult As Label
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
btnOK = New Button
btnOK.ID = "btnOK"
btnOK.Text = "OK"
btnOK.ToolTip = "Click Me!"
AddHandler btnOK.Click, AddressOf ClickHandler
PlaceHolder1.Controls.Add(btnOK)

lblResult = New Label
lblResult.ID = "lblResult"
PlaceHolder1.Controls.Add(lblResult)
End Sub

Private Sub ClickHandler _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Dim btnTemp As Button
Dim lblTemp As Label
lblTemp = Page.FindControl("lblResult")
btnTemp = sender
lblTemp.Text = btnTemp.ID
End Sub
<form id="Form1" method="post" runat="server">
<asp:placeholder id="PlaceHolder1"
runat="server"></asp:placeholder>
</form>

"sara" <sa**@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
hi all
i need to fire a click events of a button that i add at run time what can
i
do??
i need to get a property value of other controls that i add also at
runtime
i want to get this property when i click this button
any ideas ??
thanks


Nov 18 '05 #3

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

Similar topics

3
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace...
7
by: Denise | last post by:
I just realized the DataTable_RowChanging events were firing when I called Fill method of the DataAdapter! It fires TWICE for each row loaded. I thought these were only supposed to be called when...
4
by: Woody Splawn | last post by:
I had it happen again today that I needed some code to run upon loading the form but the code that I needed to have run needed to run AFTER all the rest of Visual Studio's events had fired. Due to...
28
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when...
19
by: furiousmojo | last post by:
This is a strange problem. I have a project where the contents of global.asax application_error are not firing. It is an asp.net 2.0 application using web application projects. I have another...
5
by: Joe | last post by:
Hi I am adding a class to a ComboBox - and all is fine except that I fill the combobox on the Form_Load Method and it causes the method private void comboBox2_SelectedIndexChanged(object...
0
by: RobKinney1 | last post by:
Hello, One of our C# apps (2.0) depends on a few events. One of them being DocumentComplete. Well, everything works fine with users that have IE 6 installed on their computers. But we noticed...
2
by: mswlogo | last post by:
I looked high and low for code to do this and finally found some VB code that did it right. This is a C# flavor of it. public event EventHandler<EventArgsMyEventToBeFired; public void...
1
by: TimmyTurner | last post by:
Hi all I'm working on a ASP.NET, C# project on Visual Studio 2005, using a MSDB in _vista_. My problem is that the events for the buttons are not firing. I've searched the web and the solution...
4
by: Joergen Bech | last post by:
I sometimes use delegates for broadcasting "StateChanged" events, i.e. if I have multiple forms and/or controls that need updating at the same time as the result of a change in a global/common...
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
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
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.