我需要将WebUserControl加载到PlaceHolder OnClick [英] I need to load WebUserControl to PlaceHolder OnClick

查看:68
本文介绍了我需要将WebUserControl加载到PlaceHolder OnClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的页面包含:
1-文本框.
一键式.
2位固定器.

我有3个WebUsersControls,其中包含许多控件.

我需要的是,例如在TextBox中输入1,然后单击按钮,在PlaceHolder中加载第一个WebUserControl,然后,如果我在TextBox中输入2,则在PlaceHolder中加载第二个WebUserControl,而不会删除第一个. />
谢谢

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

推荐答案

页面指令
<%@ 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):

<ucq:control1 id="control1"  runat="server"  />
<ucq:control2 id="control2"  runat="server" />
<ucq:control3 id="control3"  runat="server" />


背后的代码


Code behind

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;
      }
   }



但是,如果可以使用javascript会更好.
让我知道您的反馈.



But if you can do using javascript that will be better.
Let me know your feedback.


我建​​议您将用户控件放在div中,并先将它们设置为隐藏,然后根据需要使用JavaScript显示.
I would suggest placing the user controls in divs and setting them initially as hidden, then displaying them as necessary with JavaScript.


谢谢马克·尼沙尔克

我不知道将显示多少WebUserControl和哪些命令的问题.
Thank You Mark Nischalke

The problem that I don''t know how many WebUserControl will display and which orders.


这篇关于我需要将WebUserControl加载到PlaceHolder OnClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆