Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将字符串值转换为占位符id_C#_String_Asp.net Placeholder - Fatal编程技术网

C# 将字符串值转换为占位符id

C# 将字符串值转换为占位符id,c#,string,asp.net-placeholder,C#,String,Asp.net Placeholder,作为一名新手,我尝试了几次谷歌搜索,发现了一些令人困惑的答案。我努力实现的目标是: 点击一个按钮(众多按钮中的一个) 提取该按钮的文本值,然后 使用该值可使相关占位符可见 到目前为止,我已经完成了前两个步骤,但如何完成第三个步骤?到目前为止,如果我点击Asia按钮,我的代码是: protected void btnArea_Click(object sender, EventArgs e) { string ar = (sender as Button).Text; //ar =

作为一名新手,我尝试了几次谷歌搜索,发现了一些令人困惑的答案。我努力实现的目标是:

  • 点击一个按钮(众多按钮中的一个)

  • 提取该按钮的文本值,然后

  • 使用该值可使相关占位符可见

  • 到目前为止,我已经完成了前两个步骤,但如何完成第三个步骤?到目前为止,如果我点击
    Asia
    按钮,我的代码是:

    protected void btnArea_Click(object sender, EventArgs e)
    {
        string ar = (sender as Button).Text;
        //ar = "Asia";
        phdasia.Visible = true;
    }
    

    简单地说,对于新手来说,我必须插入什么来代替phdasia?

    如果占位符控件共享相同的名称格式,您可以通过名称访问它们:

    protected void btnArea_Click(object sender, EventArgs e)
    {
        string ar = (sender as Button).Text;
        //ar = "Asia";
        string name = "phd" + ar.ToLower(); // The naming format comes here
        Control[] controls = this.Controls.Find(name, true); //find the control(s) by name
    
        foreach(Control control in controls) // mow loop and make them visible
            control.Visible = true;
        //phdasia.Visible = true;
    }
    
    编辑:或者,您可以使用
    FindControl
    方法在包含页面上查找ID属性为
    “phdasia”
    的控件:

    Control control = FindControl(name);
    if(control!=null)
        control.Visible = true;
    

    非常感谢。它不仅有效,而且我理解它!