Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 2nd, 2005, 02:39 PM
Authorized User
 
Join Date: Dec 2004
Location: Mexico City, , Mexico.
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
  #2 (permalink)  
Old February 2nd, 2005, 04:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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
  #3 (permalink)  
Old February 3rd, 2005, 07:36 PM
Authorized User
 
Join Date: Dec 2004
Location: Mexico City, , Mexico.
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
  #4 (permalink)  
Old February 4th, 2005, 09:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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
  #5 (permalink)  
Old February 4th, 2005, 01:56 PM
Authorized User
 
Join Date: Dec 2004
Location: Mexico City, , Mexico.
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
  #6 (permalink)  
Old February 4th, 2005, 04:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:21 AM.


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