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

events, prerender and LoadControl()

I'm loading a user control using the method:

uc = Page.LoadControl("../UC.ascx");

Afterwards I set some variables in uc. For instance

uc.Count = 10;

Count is the number of link buttons which should be generated in uc. The
Pre_Render method of uc looks like this:

private void UC_PreRender(object sender, System.EventArgs e)
{
for(int i = 0; i < Count; i++)
{
LinkButton lb = new LinkButton();
lb.Text = ""+i;
lb.Click += new EventHandler(lbClick);
SomePlaceHolder.Controls.Add(lb);
}
}
The code is placed in the PreRender method because i need to be able to set
variable Count before the buttons are created. However it seems that I cannot
cathc any events on buttons which are not added in the Page_Load or before.

How do I solve this problem in a nice way?
If I could only create the usercontrol with some sort of constructer with
some arguments instead of using the LoadControl method, then my problems
would be solved.

Thanks for your help.

Nikolaj
Nov 18 '05 #1
1 5821
I'm not sure why you are putting your code in PreRender..simply put it in
Page_Load and you should be good to go:

private void Page_Load(object sender, System.EventArgs e){
for (int i = 0; i < count; ++i) {
LinkButton lb = new LinkButton();
lb.Text = ""+i;
lb.Click +=new EventHandler(lb_Click);
SomePlaceHolder.Controls.Add(lb);
}
}

and in the page:
private void Page_Load(object sender, EventArgs e) {
c1 c = (c1) Page.LoadControl("c1.ascx");
c.count = 10;
Form1.Controls.Add(c);
...
}

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Nikolaj" <Ni*****@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
I'm loading a user control using the method:

uc = Page.LoadControl("../UC.ascx");

Afterwards I set some variables in uc. For instance

uc.Count = 10;

Count is the number of link buttons which should be generated in uc. The
Pre_Render method of uc looks like this:

private void UC_PreRender(object sender, System.EventArgs e)
{
for(int i = 0; i < Count; i++)
{
LinkButton lb = new LinkButton();
lb.Text = ""+i;
lb.Click += new EventHandler(lbClick);
SomePlaceHolder.Controls.Add(lb);
}
}
The code is placed in the PreRender method because i need to be able to set variable Count before the buttons are created. However it seems that I cannot cathc any events on buttons which are not added in the Page_Load or before.
How do I solve this problem in a nice way?
If I could only create the usercontrol with some sort of constructer with
some arguments instead of using the LoadControl method, then my problems
would be solved.

Thanks for your help.

Nikolaj

Nov 18 '05 #2

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

Similar topics

4
by: blue | last post by:
I have a drop-down list, a radio button list and a submit button. I'm adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't...
2
by: luca | last post by:
I'm trying to build a Server Control, it's a calendar to manage sellers appointments (don't answer me to use and custumize Calendar Control because unluckily it's not possible for this specific...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
7
by: Dominique Vandensteen | last post by:
I have a Table to which I add a LinkButton in the PreRender event The LinkButton is visible on the webpage but when I click it, the LinkButton_Click method is not called and the page just "reloads"...
2
by: Charles A. Lackman | last post by:
Hello, I have a UserControl that I am added to a page. In the User Control I created a Public Event: Public Event DoDelete (ByVal TheIndex as integer) In a button click of the control I...
1
by: Louis-Philippe Dumoulin | last post by:
Hi, I have the following problem in asp 1.1. On my web page, when I click on a menu, a postback is generated. On the post back, I create dynamically with LoadControl a WebGrid (from InterSoft)...
0
by: seigo | last post by:
Hello, I faced with the following problem. I have a PlaceHolder on a page and a few UserControls which have custom events, for instance: public delegate void SelectHandler(object sender,...
1
by: Dave A | last post by:
I have a problem that I have boiled down to a very simple example. I have a user control that displays a some data from a business object. On one screen I have a collection of these business...
2
by: =?UTF-8?B?16jXnteZ?= | last post by:
Hey, I'm loading a webusercontrol dynamically using The following code: Control newCtrl = LoadControl("MyCtrl.ascx"); newCtrl.ID = "MyCONTROL"; container.Control.Add(newCtrl); My...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.