473,396 Members | 2,024 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.

Registering onclick of a programatically created button

Hi,
I programmatically create a/some buttons:

private TableCell GenerateButtonInCell(XmlNode NodeItem)
{
Button ChoosePlanButton = new Button();
ChoosePlanButton.CommandArgument = NodeItem.OuterXml;
ChoosePlanButton.UseSubmitBehavior = false;
ChoosePlanButton.ToolTip = "Request this plan";
ChoosePlanButton.Text = String.Concat("Apply");
TableCell InnerTableCell = new TableCell();
InnerTableCell.Controls.Add(ChoosePlanButton);
return InnerTableCell;
}
I attach it/them all to the same handler:

void ChoosePlanButton_Click(object sender, EventArgs e)
{
//PERSIST THE CHOSEN PLANS ATTRIBUTES TO VIEWSTATE
Button temp = (Button)sender;
ViewState.Add("ChosenPlan", temp.CommandArgument);

}

then I try to register them pre page render thus:

override protected void OnInit(EventArgs e)
{

if (ChoosePlanButton != null)
{ ChoosePlanButton.Click += new
EventHandler(ChoosePlanButton_Click); }

base.OnInit(e);

}

but obviously I cant reference the ChoosePlanButton instance outside the
method.

How do accomplish this?

Many thanks.
Feb 17 '08 #1
2 1678
you could simply register the event/handler in your GenerateButtonInCell
function

--
Misbah Arefin

"CyberMan_(MCDST!)" wrote:
Hi,
I programmatically create a/some buttons:

private TableCell GenerateButtonInCell(XmlNode NodeItem)
{
Button ChoosePlanButton = new Button();
ChoosePlanButton.CommandArgument = NodeItem.OuterXml;
ChoosePlanButton.UseSubmitBehavior = false;
ChoosePlanButton.ToolTip = "Request this plan";
ChoosePlanButton.Text = String.Concat("Apply");
TableCell InnerTableCell = new TableCell();
InnerTableCell.Controls.Add(ChoosePlanButton);
return InnerTableCell;
}
I attach it/them all to the same handler:

void ChoosePlanButton_Click(object sender, EventArgs e)
{
//PERSIST THE CHOSEN PLANS ATTRIBUTES TO VIEWSTATE
Button temp = (Button)sender;
ViewState.Add("ChosenPlan", temp.CommandArgument);

}

then I try to register them pre page render thus:

override protected void OnInit(EventArgs e)
{

if (ChoosePlanButton != null)
{ ChoosePlanButton.Click += new
EventHandler(ChoosePlanButton_Click); }

base.OnInit(e);

}

but obviously I cant reference the ChoosePlanButton instance outside the
method.

How do accomplish this?

Many thanks.
Feb 18 '08 #2
I tried that, it doesnt get called...

Perhaps I am missing something obvious???

I will try it again.
--
If I can help, I will.
Do the same for a stranger today.
"Misbah Arefin" wrote:
you could simply register the event/handler in your GenerateButtonInCell
function

--
Misbah Arefin

"CyberMan_(MCDST!)" wrote:
Hi,
I programmatically create a/some buttons:

private TableCell GenerateButtonInCell(XmlNode NodeItem)
{
Button ChoosePlanButton = new Button();
ChoosePlanButton.CommandArgument = NodeItem.OuterXml;
ChoosePlanButton.UseSubmitBehavior = false;
ChoosePlanButton.ToolTip = "Request this plan";
ChoosePlanButton.Text = String.Concat("Apply");
TableCell InnerTableCell = new TableCell();
InnerTableCell.Controls.Add(ChoosePlanButton);
return InnerTableCell;
}
I attach it/them all to the same handler:

void ChoosePlanButton_Click(object sender, EventArgs e)
{
//PERSIST THE CHOSEN PLANS ATTRIBUTES TO VIEWSTATE
Button temp = (Button)sender;
ViewState.Add("ChosenPlan", temp.CommandArgument);

}

then I try to register them pre page render thus:

override protected void OnInit(EventArgs e)
{

if (ChoosePlanButton != null)
{ ChoosePlanButton.Click += new
EventHandler(ChoosePlanButton_Click); }

base.OnInit(e);

}

but obviously I cant reference the ChoosePlanButton instance outside the
method.

How do accomplish this?

Many thanks.
Feb 19 '08 #3

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

Similar topics

4
by: Dipin | last post by:
Hi All; I have this javascript which is adding a new button to the column in the row which is created dynamically, the innerhtml shows that the onclick event is correctly added but it never gets...
17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
2
by: John | last post by:
Hi, heres a brief description of what I'm trying to do. I have a sql table named colors that looks like this: color_id color_name 1 blue 2 red 3......... and so...
1
by: Hrvoje Vrbanc | last post by:
Hello all! My question is the following: I add buttons (server controls) programatically into a table cell. Example: Dim btObnovi As Button = New Button() celija25.Controls.Add(btObnovi) ...
2
by: Richard Morse | last post by:
Hi! I have an aspx that I've created which has an asp:Button in it. I would like to be able to change the OnClick handler at runtime (basically, I want this form to either edit or create a...
2
by: Sedef | last post by:
Hi, i'm trying to create a custom Button user control which will be derived from System.Web.UI.WebControls.Button. the normal server side Button class creates some client side javascript code for...
2
by: Helen | last post by:
I've got some clientside script that runs when the selected index of a select box changes. Now I need to swap my selectbox with an ASP.NET radiobuttonlist (to solve some layout issues). I still...
7
by: rsaffy | last post by:
I am having trouble with my dynamically created button's event handling. I read that the buttons need to be recreated on every trip to the server, but how exactly do you do that when the datagrid...
3
by: ccordero | last post by:
Hi! I am working with asp.net 1.1 and javascript. I have a client side checkbox, a client side button, and an asp.net image button. When I check the checkbox, I want the client side button...
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
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: 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
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
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
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
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.