C# 后台动态控制输出、动态控制前台元素的显示隐藏等等
(1) 使用JSP <%= %>,它可以获取后台的变量值。可以输出到前台任何地方。 (我都可)
前台
<%= txtImg%>
后台
public string txtImg = string.Empty; StringBuilder scriptList = new StringBuilder(); scriptList.Append("<script src='//333333.js'></script>"); //引入 txtImg = scriptList.ToString();
OR
<script type="text/javascript"> $(function () { <%= txt_shuchu %> }) </script>
public string txt_shuchu = string.Empty; StringBuilder scriptList = new StringBuilder(); scriptList.Append("$('input:radio:first').removeAttr('checked');$('input:radio:last').attr('checked', 'checked'); "); txt_shuchu = scriptList.ToString();
(2)利用ASP.NET控件 (控制输出)
前台
<div class="subbtn"> <asp:Literal ID="LitBtn" runat="server"> //我想如果我满足条件,这里会有个操作选项 </asp:Literal> </div>
后台
LitBtn.Text = "<a herf='javascript:void(0);' class='btn-d-blue'>创建终端</ a>"; //加个onclick事件 LitBtn.Text = string.Format("<a herf='javascript:void(0);' id='btn_ww' onclick=\"doCreateTerminal('{0}');return false;\" class='btn-d-blue'>创建终端</ a>", AffiliateId);