c# - 如何根据用户请求调用 WebUserControls?

标签 c# asp.net

我正在构建一个网站,我需要根据用户请求调用 WebUserControls (.ascx),我该如何实现?这可能吗?

例子:

protected void userclick_click(object sender, EventArgs e)
{
    if(textbox1.Text == "2")
    {
        call WebUserControl1.ascx
    }
    else
    {
      /*do nothing*/
    }
}

我为此使用 C#。

提前谢谢你。

最佳答案

protected void userclick_click(object sender, EventArgs e)
{
    if(textbox1.Text == "2")
    {
        Control c1 = LoadControl("MyUserControl.ascx");
        //page or whatever control you want to add to
        Page.Controls.Add(c1);
    }
    else
    {
      /*do nothing*/
    }
}

关于c# - 如何根据用户请求调用 WebUserControls?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7655615/

相关文章:

c# - 使用 > out.txt 命令 C#

c# - Excel Interop (Visual Studio C#) - "Embed Interop Type"属性

c# - 在 Visual Studio ASP.NET 解决方案中禁用 Resharper 本地化检查

Jquery Monthpicker 不工作

c# - 将自定义对象的 ArrayList 保存到用户设置

c# - 通过 for 循环初始化带有 Lists<int> 的交错数组

c# - 我有一个 WebGet 方法,如何获取 xml 结果?

c# - 我在将此 SAMLResponse 读入 SecurityToken 对象时遇到问题

c# - 如何在 ListView 中显示对象列表属性

c# - 从 asp.net 中的文件夹下载文件