Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2005, 04:44 PM
Authorized User
 
Join Date: Dec 2004
Location: Mexico City, , Mexico.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default Troubles with dynamically created WUC

I have a web form, which has a place holder named Example when, Page_Load happens in my web form. I’m creating dynamically a WUC named WebUserControl3 into my place holder.
WebUserControl3 has several text boxes, a button and a label, when user click button I’m executing some calculation which result I’m placing into label. But when user click button occurs Page_Load in web form that contains my place holder and I need recreate my WUC plus data was contained therein, I have tried with ViewState and Session variables but still I can’t pass data from WUC to web form to recreate WUC and its data. Obviously WUC is created again without data. Notwithstanding if I re-enter data in WUC and click button again data are displayed OK.
Why first time it isn’t working and begin second try it’s working fine?
My code is:

private void Page_Load(object sender, System.EventArgs e)
{
    if(!Page.IsPostBack)
    {
    }
    else
    {
        Example.Controls.Clear();
        Control control = this.Page.LoadControl("WebUserControl3.ascx");
        Example.Controls.Add(control);
    }
}

Thanks in advance

A.L.


El Hombre que tiene Amigos ha de mostrarse Amigo
__________________
El Hombre que tiene Amigos ha de mostrarse Amigo
 
Old March 7th, 2005, 01:08 PM
Authorized User
 
Join Date: Dec 2004
Location: Mexico City, , Mexico.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please does somebody know about this topic?

El Hombre que tiene Amigos ha de mostrarse Amigo
 
Old March 7th, 2005, 02:24 PM
Authorized User
 
Join Date: Dec 2004
Location: Mexico City, , Mexico.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello:
At last I found a solution.
For some reason the page does not create it with the same control Id. the first time as every other time.
To solve it I inserted this line:
control.ID="WebUserCotrol3"; as it shows:

Example.Controls.Clear();
Control control = this.Page.LoadControl("WebUserControl3.ascx");
control.ID="WebUserCotrol3";
Example.Controls.Add(control);

I hope this be useful for newbie person as I am.

Greetings.

A.L.


El Hombre que tiene Amigos ha de mostrarse Amigo




Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me about dynamically created controls vingo_mail ASP.NET 2.0 Basics 1 March 24th, 2008 12:54 PM
Problems with Dynamically created controls Preeti_Singh .NET Framework 1.x 1 March 7th, 2007 01:30 PM
Dynamically created code Puck312 Pro VB 6 3 September 7th, 2005 01:21 PM
Dynamically created controls katsarosj ASP.NET 1.0 and 1.1 Basics 4 February 4th, 2004 09:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.