Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
|
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 February 2nd, 2005, 02:39 PM
Authorized User
 
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default Loading and Destroying web user controls into a pa

Hello:
I’ve a web form containing a web user control and a panel, this web user control have 2 buttons, when user push 1st button I need load a 2nd web user control into panel of web form. When user push 2nd button of 1st web user control I need destroy 2nd web user control which is into panel and place therein a 3rd web user control.
I’ll appreciate some ideas to attain it.
A.L.


El Hombre que tiene Amigos ha de mostrarse Amigo
__________________
El Hombre que tiene Amigos ha de mostrarse Amigo
 
Old February 2nd, 2005, 04:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Loading controls is easy through Page.LoadControl(path), which is passed to a control reference, then you add through Panel1.Controls.Add(myControl).

You'll probably have to recreate them programmatically on every page load.

Brian
 
Old February 3rd, 2005, 07:36 PM
Authorized User
 
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Brian:
Just I'm having this trouble you explain me.
When I have a web user control loaded which has a button, when user push this button, this web user control simply vanish.
How can I avoid this happens.
Don't you have an example about it?
And how I mantain data into web user control that user already typed?
A.L.

El Hombre que tiene Amigos ha de mostrarse Amigo
 
Old February 4th, 2005, 09:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

No examples, I haven't done what you are doing before. How are you loading the control into the Page? Through the code-behind? Could you post your code so I can see what is happening?

Brian
 
Old February 4th, 2005, 01:56 PM
Authorized User
 
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok Brian.
This is code in button of web user control to show next web user control:

private void Button2_Click(object sender, System.EventArgs e)
{
         WUC_CreDes.WebForm1 parent1 = (WUC_CreDes.WebForm1) this.Page;
    parent1.Button2_Click_1(sender,e);
}

And code into Button2 of web form (Example is a Placeholder):

public void Button2_Click_1(object sender, System.EventArgs e)
{
    Example.Controls.Clear();
    Control control = this.Page.LoadControl("WebUserControl3.ascx");
    Example.Controls.Add(control);
}

In WebUserControl3 I have several TextBox, a button, a label. When user puh button I need to show soemthing into label, but when user push button, this web user control simply vanish.

If I recreate web user control programatically I have not way to recover data into textbox and into label.


El Hombre que tiene Amigos ha de mostrarse Amigo
 
Old February 4th, 2005, 04:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I guess you aren't using this user control anywhere else? First, you shouldn't invoke a user control in that way (calling the event handler). You should call a method, and the method can do whatever.

I would recommend reading this: http://www.codeproject.com/aspnet/Page_UserControl.asp

You need to recreate the user control on every page load, that's why it vanishes.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Form and User Controls CSharpSeeker C# 2005 1 August 22nd, 2007 03:15 PM
Need urgent help loading user controls at runtime rpeters83 ASP.NET 2.0 Professional 7 September 3rd, 2006 10:17 AM
Web parts and User controls capitapicard BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 0 June 26th, 2006 04:11 PM





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