C# 我需要从c代码后面执行Java脚本函数

C# 我需要从c代码后面执行Java脚本函数,c#,javascript,asp.net,iis,C#,Javascript,Asp.net,Iis,我需要从c代码后面执行Java脚本函数。使用Asp.net服务器控制中继器并在条件为真时检查条件需要运行java脚本函数,该函数将打开超链接显示块这是我的javascript函数 function MyFunction(username) { document.getElementById("hyp").style.display = "block"; } 这是我在该条件后的Asp.net代码,如果为true,我调用c#code behind方法writeText(): 受保护的字符串w

我需要从c代码后面执行Java脚本函数。使用Asp.net服务器控制中继器并在条件为真时检查条件需要运行java脚本函数,该函数将打开超链接显示块这是我的javascript函数

function MyFunction(username) {
  document.getElementById("hyp").style.display = "block";
}
这是我在该条件后的Asp.net代码,如果为true,我调用c#code behind方法writeText():


受保护的字符串writeText(字符串PageDataId、字符串AlbumId、字符串a)
{
RegisterStartupScript(this.GetType(),“hwa”,“MyFunction('Checkjj');”,true);
字符串html=“”;
html+=“”;
返回html;
}
这个c#调用javascript函数来显示html锚点,以阻止在开始时显示none

这是锚标签

<a id="hyp" name="hyp"  href="#" class="lightbox<%=inc+"b" %>">Part II</a>

使用html:

您可以发现此博客很有帮助:


您有任何错误吗?@SivaRajini我收到此错误分析器错误消息:服务器标记不能包含构造。如果我在标记中添加runat Server,则我无法使用class=“lightbox”>它给我的错误是不正确的。。。你可以在itemDatabound Event上添加它。请指导我如何操作?我刚刚添加了一个sample@JayZee将
runat=“server”
添加到属性列表的开头,然后将class属性放在属性列表的末尾。然后运行它。它应该运行。
<a id="hyp" name="hyp"  href="#" class="lightbox<%=inc+"b" %>">Part II</a>
  void MyRepeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
string someVar = "someValue"  ;  
           ((HtmlAnchor)e.Item.FindControl("hyp")).Attributes.Add ("css", "lightbox" + someVar);          
       }  
<asp:Repeater ID="MyRepeater" runat="server" OnItemDataBound="MyRepeater_ItemDataBound">

       <a id="hyp" name="hyp"  href="#" runat="server">Part II</a>

</asp:Repeater>