[英]How to convert this json into string and get value of the 'id' property
[英]Convert a string value into PlaceHolder id
作為一個新手,我嘗試了幾次Google搜索並找到了一些令人困惑的答案。 我想要實現的是:
單擊一個按鈕(許多)中的一個,
提取該按鈕的文本值,然后
使用該值使相關的占位符可見。
到目前為止,我已經完成了前兩個步驟,但是如何完成第3步? 到目前為止,如果單擊“ 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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.