473,396 Members | 1,860 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.

Wiring up dynamic control

I load a dynamic control once a button is clicked. In the control is
another button. However, I can't get its click event to fire. Here's
the pattern:

Page1.aspx
---------
SomeButton_Click()
{
Control control = LoadControl("mycontrol.ascx");
control.ID = "thecontrolID";
panel1.Controls.Add(control);
}
mycontrol.ascx
----------------------
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
this.mybutton.Click += new
mybuttonClickEventHandler(btnmybutton_Click);
}
Once SomeButton is clicked, the user control loads via AJAX and
appears. I see btnmybutton from the user control. Once I click it,
the click event doesn't fire. Any ideas?

Thanks.

Feb 14 '07 #1
4 1375
you are not hooking up the event handler on postback, so there is no way
for it to fire.

-- bruce (sqlwork.com)

brett wrote:
I load a dynamic control once a button is clicked. In the control is
another button. However, I can't get its click event to fire. Here's
the pattern:

Page1.aspx
---------
SomeButton_Click()
{
Control control = LoadControl("mycontrol.ascx");
control.ID = "thecontrolID";
panel1.Controls.Add(control);
}
mycontrol.ascx
----------------------
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
this.mybutton.Click += new
mybuttonClickEventHandler(btnmybutton_Click);
}
Once SomeButton is clicked, the user control loads via AJAX and
appears. I see btnmybutton from the user control. Once I click it,
the click event doesn't fire. Any ideas?

Thanks.
Feb 14 '07 #2
I am now hooking it up in Init() but still nothing.

Feb 14 '07 #3
On Feb 14, 4:09 am, "brett" <acco...@cygen.comwrote:
I am now hooking it up in Init() but still nothing.
You've probably forgotten to set it's ID property...

Check out this one:
http://ajaxwidgets.com/AllControlsSa...aceHolder.aspx
Click "Show code"...

Though this is for an Ajax Framework it should be no different in
"conventional" ASP.NET...

..t

Feb 15 '07 #4
On Feb 15, 12:39 am, "Thomas Hansen" <polter...@gmail.comwrote:
On Feb 14, 4:09 am, "brett" <acco...@cygen.comwrote:
I am now hooking it up in Init() but still nothing.

You've probably forgotten to set it's ID property...
Not quite. I creat the control on button_click(). That initiates a
postback. The control must be created again after postback. That
leaves room to make a mistake in assigning the same ID, which is where
I went wrong.

Feb 20 '07 #5

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

Similar topics

1
by: Scott M | last post by:
I'm building a smart client application based off of the example that is posted on windowsforms.com (and shown on the .NET show). A windows form calls a webservice that itterates through a...
1
by: Bill | last post by:
I'm trying to dynamically build several linkbuttons and wire them up to a method called OnLinkClick . . . For the life of me, I don't understand why the code below isn't firing the event. ...
0
by: Robert W. | last post by:
Though I'm new to C#, I've successfully built an MVC (Model-View-Controller) Framework - with much thanks to the help of the great people on here! Anyhow, my MVC Framework, which I call "ASM" for...
7
by: Oisin Grehan | last post by:
Hi, I have a UserControl derived class: <ns:votingbutton runat="server" id="btn1" onclick="votingbuttonclick" /> My question is, what code do I need in place in the codebehind for this to...
0
by: Homam | last post by:
To wire a Click event handler to a dynamically-added control (e.g. LinkButton), you need to do so during the Load event of the parent (e.g. a PlaceHolder). The problem is, the Click event...
4
by: Jordan | last post by:
I need to dynamically add an ImageButton control to a user control and and do some server-side processing when the user clicks it. While I the ImageButton is added to the user control at runtime,...
5
by: Sosh | last post by:
Hi, I can't seem to find much information on this. Please could someone explain to me how to wire up events (selectedIndexChanged) to a bunch of dynamically created controls (Dropdownlists),...
5
by: Andrew Robinson | last post by:
I have a page that can load a number of different user controls. Each of these user controls inherits from a common base class and the controls are loaded based on application state, status, etc...
12
by: dbuchanan | last post by:
Hello, (Is this the proper newsgroup?) === Background === I am building a solution with two projects. One project is my data access layer which contains my DataSet as an xsd file. The XSD...
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
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
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.