方法一:
前台控制后台方法来控制样式。
<a style='<%# Judge(Eval("CREATEUSERNO"),false)%>'
#region 判断是否创建人等于登录人
/// <summary>
/// 判断创建人是否为登录人,假如是前台显示修改,否则显示浏览;
/// </summary>
protected string Judge(object obj,bool flay)
{
if (obj != null && obj.ToString() == UserInfo.UserOrganizationNO)
{
return flay?"display:inline": "display:none";
}
else
{
return flay?"display:none": "display:inline";
}
}
或者前台:<tr <%=setys()%>>
后台:protected string setys()
{
return "style='display:none;'";
}
方法二:
<div id="d1" runat="server" style="display:none">aaaaaa</div>
<asp:Button ID="btn" Text="显示" runat="server" onclick="btn_Click" />
<asp:Button ID="btnN" Text="隐藏" runat="server" onclick="btnN_Click" />
C#代码:
protected void btn_Click(object sender, EventArgs e)
{
d1.Style.Add(HtmlTextWriterStyle.Display, "block");
}
protected void btnN_Click(object sender, EventArgs e)
{
d1.Style.Add(HtmlTextWriterStyle.Display, "none");
}
方法三:
想要在后台控制前台,必须设置对象的runat属性值为"server"。如
Html代码
- <div id="DIV1" runat="server" >
- </div>
后台:(C#代码)
- this.DIV1.Style.Value = "display:none";
或者:
- DIV1.Attributes.CssStyle.Value = "display:none";