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

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.CommandArgument = 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 2860
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="Remove";

btn.CommandName = "RemoveSW";

btn.CommandArgument = list.Count;

btn.Command +=new CommandEventHandler(btn_Command);

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

private void btn_Command(object sender, CommandEventArgs e)

{

//Add your code here

}

Hope this helps.

Prodip

"Matthew MacDonald" <ma******@hotmail.com> wrote in message news:Oj**************@TK2MSFTNGP12.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.CommandArgument = 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**************@TK2MSFTNGP15.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="Remove";

btn.CommandName = "RemoveSW";

btn.CommandArgument = list.Count;

btn.Command +=new CommandEventHandler(btn_Command);

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

private void btn_Command(object sender, CommandEventArgs e)

{

//Add your code here

}

Hope this helps.

Prodip

"Matthew MacDonald" <ma******@hotmail.com> wrote in message news:Oj**************@TK2MSFTNGP12.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.CommandArgument = 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
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...
4
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:...
2
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...
6
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...
1
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
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...
2
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...
0
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....
6
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
0
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...

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.