473,545 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

oncommand of dynamically generated button

Hi all,

I am adding controls to a table dynamically. I have a list that I am putting into the session to keep track of them on postback. What I need to know though, is how to add the oncommand method to the buttons as I create them? For example:

btn.ID = "btnDelete" & list.Count

btn.Text = "Remove"

btn.CommandName = "RemoveSW"

btn.CommandArgu ment = list.Count

btn.oncommand = "Command"

list.add(btn)

Doesn't work because the oncommand method is protected.

Any thoughts?

Thanks,

Matt

Nov 18 '05 #1
2 2866
Create the control and attach an event handler to it. The btn_Command method(private) must be predefined in order for the deligate to work.
Button btn=new Button();

btn.ID="id";

btn.Text="Remov e";

btn.CommandName = "RemoveSW";

btn.CommandArgu ment = list.Count;

btn.Command +=new CommandEventHan dler(btn_Comman d);

............... ....

private void btn_Command(obj ect sender, CommandEventArg s e)

{

//Add your code here

}

Hope this helps.

Prodip

"Matthew MacDonald" <ma******@hotma il.com> wrote in message news:Oj******** ******@TK2MSFTN GP12.phx.gbl...
Hi all,

I am adding controls to a table dynamically. I have a list that I am putting into the session to keep track of them on postback. What I need to know though, is how to add the oncommand method to the buttons as I create them? For example:

btn.ID = "btnDelete" & list.Count

btn.Text = "Remove"

btn.CommandName = "RemoveSW"

btn.CommandArgu ment = list.Count

btn.oncommand = "Command"

list.add(btn)

Doesn't work because the oncommand method is protected.

Any thoughts?

Thanks,

Matt

Nov 18 '05 #2
OK that works,
The only problem I'm having now is that after I click the newly created button (whose job is to remove some controls from the table row) I need to refresh the browser manually to see the changes correctly. Is there any way to force the browser to refresh?
"Prodip Saha" <ps***@bear.com > wrote in message news:uS******** ******@TK2MSFTN GP15.phx.gbl...
Create the control and attach an event handler to it. The btn_Command method(private) must be predefined in order for the deligate to work.
Button btn=new Button();

btn.ID="id";

btn.Text="Remov e";

btn.CommandName = "RemoveSW";

btn.CommandArgu ment = list.Count;

btn.Command +=new CommandEventHan dler(btn_Comman d);

............... ...

private void btn_Command(obj ect sender, CommandEventArg s e)

{

//Add your code here

}

Hope this helps.

Prodip

"Matthew MacDonald" <ma******@hotma il.com> wrote in message news:Oj******** ******@TK2MSFTN GP12.phx.gbl...
Hi all,

I am adding controls to a table dynamically. I have a list that I am putting into the session to keep track of them on postback. What I need to know though, is how to add the oncommand method to the buttons as I create them? For example:

btn.ID = "btnDelete" & list.Count

btn.Text = "Remove"

btn.CommandName = "RemoveSW"

btn.CommandArgu ment = list.Count

btn.oncommand = "Command"

list.add(btn)

Doesn't work because the oncommand method is protected.

Any thoughts?

Thanks,

Matt

Nov 18 '05 #3

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

Similar topics

1
1152
by: PeteBr | last post by:
I am dynamically generating a number of button controls based on the results returned from a search carried out on another machine. When one of these buttons is selected I want to be able to go through the same event handler for each button but I can't seem to get to happen unless I regenerate all my previously dynamically generated buttons every...
4
2555
by: hb | last post by:
Hi, When I add an asp:button (ex: id=btnLog) on home.aspx, I need to create btnLog_Click() event in home.aspx.cs, and also link this event and the button in OnInit() method by adding: this.btnLog.Click +=new System.EventHandler(this.btnLog_Click); Now, I need to generate some asp:button dynamically in an asp:table, and assign the event...
2
2897
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to avoid the problem by avoiding the table control or resorting to databound controls that better manage state for me. I hope to understand how to solve the...
6
3357
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all the usual stuff of recreating the usercontrol in the Page Init event. The 'failure' sequence is as follows: - select web form button to display...
1
2463
by: Sheryl Landon | last post by:
Is there a way to set the OnCommand or OnClick attributes when adding a LinkButton dynamically through code? These attributes are available when adding on design-time... Thanks, Sheryl
6
436
by: Nathan Sokalski | last post by:
I am trying to dynamically add controls to my page, but am having trouble with controls such as buttons. I have been able to add simple controls such as Label controls, because they can be placed anywhere. I have managed to add Labels using the following code: Dim extralabel As Label = New Label extralabel.Text = "Generated Label" ...
2
11940
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put them each in a GroupBox. All the examples I saw from the books or from the web show me how to add static radio buttons at design, or dynamically at...
0
1121
by: clintonG | last post by:
A Matter of Design: OnCommand or OnClick Event Handler? Attributing a control using OnCommand supports the use of other attibutes such as CommandName and CommandArgument. AFIK OnClick does not. Where it matters when using OnCommand for example is the value of the CommandArgument seems to be easier to use to indicate some behavior in that...
6
1483
by: Bjorn Sagbakken | last post by:
Hello In VS2005: I am adding buttons and textboxes dynamically into a table, that also dynamically expands. So far, so good, actually very nice. But I am having trouble starting the desired subroutine on postback. To me it seems like the button click event looks for a client script instead of going to the aspx codepage and execute the sub...
0
7475
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
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...
0
7771
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...
0
5982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4958
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...
0
3465
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...
1
1900
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
1
1023
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.