Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

My page contains:
1-TextBox.
1-Button.
2-Place Holder.

I have 3 WebUsersControls which contain many controls.

What I need is, when enter 1 in the TextBox for example, and then click button, load the first WebUserControl in the PlaceHolder, Then if I entered 2 in the TextBox load the second WebUserControl in the PlaceHolder, without removing first one.

Thank You
Posted

page directive
C#
<%@ Register Src="controls/wuc1.ascx" TagName="control1" TagPrefix="ucq" %>
<%@ Register Src="controls/wuc2.ascx" TagName="control2" TagPrefix="ucq" %>
<%@ Register Src="controls/wuc3.ascx" TagName="control3" TagPrefix="ucq" %>

within page body(Place Holder):
C#
<ucq:control1 id="control1"  runat="server"  />
<ucq:control2 id="control2"  runat="server" />
<ucq:control3 id="control3"  runat="server" />

Code behind
C#
protected void Page_Load(object sender, EventArgs e)
  {
      if (!Page.IsPostBack)
      {
        control1.Visible=false;
        control2.Visible=false;
        control3.Visible=false;
      }
  }
protected void btnCommand_Click(object sender, EventArgs e)
  {
  if(!string.IsNullOrEmpty(textbox1.text))
      {
        if(textbox1.text.tostring()=="1")
             control1.Visible=true;
        if(textbox1.text.tostring()=="2")
             control2.Visible=true;
        if(textbox1.text.tostring()=="3")
             control3.Visible=true;
      }
   }


But if you can do using javascript that will be better.
Let me know your feedback.
 
Share this answer
 
v4
I would suggest placing the user controls in divs and setting them initially as hidden, then displaying them as necessary with JavaScript.
 
Share this answer
 
Thank You Mark Nischalke

The problem that I don't know how many WebUserControl will display and which orders.
 
Share this answer
 
Comments
[no name] 5-Aug-11 10:48am    
Add a comment, not an answer.

What do you mean you don't know how many and the order? There are no requirements or business logic for this? How do you expect to be able to complete this task?
 
Share this answer
 
Hi, if you don't know how many controls which be added, you can try this

string control_url = "your_control_url"; // for example: shopping_cart.ascx
YourControl test = (YourControl)Page.LoadControl(control_url); // casting object to your control class
this.Controls.Add(test); // add control to your page
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900