473,480 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with user control

I'm playing around with a user control that I think might help one of my
projects.

I'm having an issue with it retaining the controls inside a placeholder that
are added dynamically.
Here's the code:

Calling code from the page that contains the control:
----

protected void btnShowHistory_Click(object sender, EventArgs e)
{
hisTest.DataAddHistoryTable(new
CivicWeb.eAgenda.Package.PackageManager(1).AuditLo g(), "History");
hisTest.DataAddHistoryTable(new
CivicWeb.eAgenda.Package.PackageManager(20).AuditL og(), "Test");
}

---

The control layout is:

<Place holder>
<DataGrid>
-----

Here's the control Code:

public void DataAddHistoryTable(DataTable History,string Name)
{
if (dsHistory == null)
dsHistory = new DataSet();

dsHistory.Tables.Add(History);
dsHistory.Tables[dsHistory.Tables.Count - 1].TableName = Name;

Button btnHistory = new Button();
btnHistory.Text = Name;
btnHistory.Click += new EventHandler(btnHistory_Click);
btnHistory.ID = "btnHistory" +
dsHistory.Tables.Count.ToString();

phHistoryButtons.Controls.Add(btnHistory);
}

protected void btnHistory_Click(object sender, EventArgs e)
{
//Find the DT by the name of the button

dgdHistory.DataSource = dsHistory.Tables[((Button)sender).Text];
dgdHistory.DataBind();
}

The control will render the 2 buttons. However, when I press either button,
they both disapear, and nothing happens, it won't hit the History_click
event... but it will hit the on_load on the history control but have no idea
what the sender was. It was like the Buttons just submited as if they were
HTML buttons.

Now on my driver page, I have it set so it only adds 2 datatables on the
first load. If I took that out, it would work, but that is very ineficient.

What I want is a user to add DataTables to the control. With each DataTable
a new button will appear, which the user will then select to render that
code in the DataGrid.

ANy help would be awesome. I'm still new to creating controls, so forgive me
if I'm missing some small detail.

Thanks.
Jan 25 '06 #1
1 1047
if you create a dynamic control, it must be recreated on postback before
onload, say in onint. you need to remember it was created, usually you store
an indicator in viewstate.

-- bruce (sqlwork.com)

"Ryan Ternier" <rt******@icompasstech.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I'm playing around with a user control that I think might help one of my
projects.

I'm having an issue with it retaining the controls inside a placeholder
that are added dynamically.
Here's the code:

Calling code from the page that contains the control:
----

protected void btnShowHistory_Click(object sender, EventArgs e)
{
hisTest.DataAddHistoryTable(new
CivicWeb.eAgenda.Package.PackageManager(1).AuditLo g(), "History");
hisTest.DataAddHistoryTable(new
CivicWeb.eAgenda.Package.PackageManager(20).AuditL og(), "Test");
}

---

The control layout is:

<Place holder>
<DataGrid>
-----

Here's the control Code:

public void DataAddHistoryTable(DataTable History,string Name)
{
if (dsHistory == null)
dsHistory = new DataSet();

dsHistory.Tables.Add(History);
dsHistory.Tables[dsHistory.Tables.Count - 1].TableName = Name;

Button btnHistory = new Button();
btnHistory.Text = Name;
btnHistory.Click += new EventHandler(btnHistory_Click);
btnHistory.ID = "btnHistory" +
dsHistory.Tables.Count.ToString();

phHistoryButtons.Controls.Add(btnHistory);
}

protected void btnHistory_Click(object sender, EventArgs e)
{
//Find the DT by the name of the button

dgdHistory.DataSource =
dsHistory.Tables[((Button)sender).Text];
dgdHistory.DataBind();
}

The control will render the 2 buttons. However, when I press either
button, they both disapear, and nothing happens, it won't hit the
History_click event... but it will hit the on_load on the history control
but have no idea what the sender was. It was like the Buttons just
submited as if they were HTML buttons.

Now on my driver page, I have it set so it only adds 2 datatables on the
first load. If I took that out, it would work, but that is very
ineficient.

What I want is a user to add DataTables to the control. With each
DataTable a new button will appear, which the user will then select to
render that code in the DataGrid.

ANy help would be awesome. I'm still new to creating controls, so forgive
me if I'm missing some small detail.

Thanks.

Jan 25 '06 #2

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

Similar topics

0
3614
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
2
1178
by: bie2 | last post by:
Hi, I need help on how to proceed with a multithreading. I have a main form, which depending on what the user click will load a user control. Some of these user controls will have a database...
13
1563
by: Lloyd Sheen | last post by:
I have now spent 5 hours on google/msdn looking for something useful in the creation of user controls for asp.net. The VS 2003 has very limited support for things such as absolute positioning of...
1
7534
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
5
1492
by: Dan Nash | last post by:
Hi all, I've got a page with a user control on, added via VS. I'm trying to get to a property of the user control (or more precisely, a public var). Here's the code at the top of my aspx...
3
2220
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
1
2609
by: keith.walter | last post by:
My first asp.net app is almost "done" and I am stuck. Here is my situation: I have a "mother" page add_customer.aspx and a"child" user control add_group.ascx. On the mother page is an "add...
3
1491
by: Joe | last post by:
Hello All, I am developing a webform which creates ArrayLists of people's names and addresses (the values are retrieved from an xml file) and dynamically drops a user control onto the webform...
0
3390
by: davidr | last post by:
Hi, I have a panel that I load user Control in no problem. The problem arrises when I do a post back on one of these user controls. I have button it does a click event. In this click event I...
11
2109
by: Brad Baker | last post by:
I'm building a small web application - I started out placing all my code in one file (config.aspx). As I continue to add code though it was becoming very unwieldy. After doing some searching...
0
6904
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
7032
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,...
1
6730
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
6873
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
5321
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
2990
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...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.