C# 在锚点上添加onclick属性
我正试图以这种方式在锚标记上添加onclick属性C# 在锚点上添加onclick属性,c#,attributes,anchor,C#,Attributes,Anchor,我正试图以这种方式在锚标记上添加onclick属性 chq.Attributes["Onclick"] = "http://172.17.0.221:81/CheckVerification1.aspx?id=" + Session["U_EMAIL"].ToString(); 这是我的锚标签 <a id="chq" runat="server" target="_blank">Cheque</a> 支票 但是这种方法是不可行的,任何人都可以给出替代方法来做到这一
chq.Attributes["Onclick"] = "http://172.17.0.221:81/CheckVerification1.aspx?id=" + Session["U_EMAIL"].ToString();
这是我的锚标签
<a id="chq" runat="server" target="_blank">Cheque</a>
支票
但是这种方法是不可行的,任何人都可以给出替代方法来做到这一点
chq.Attributes["src"] = "http://172.17.0.221:81/CheckVerification1.aspx?id=" + Session["U_EMAIL"].ToString();
Html
<a id="chq" runat="server" src="" target="_blank">Cheque</a>
支票
如果要在onclick事件触发时重定向,则必须使用锚定标记的src属性,在代码后面,可以通过这种方式向原始html元素添加属性
chq.Attributes.Add("src", "http://172.17.0.221:81/CheckVerification1.aspx?id=");
是否要从代码隐藏中添加属性?是的,我想将会话电子邮件id作为querystring获取到另一个页面无需添加
onclick
属性。最好的方法是使用src
属性。尝试使用chq.Attributes.Add(“src”),“http://172.17.0.221:81/CheckVerification1.aspx?id=“+会话[“U_电子邮件”].ToString())
@user1645793::在使用第一个解决方案时,页面呈现后,src
属性的值是多少?我在页面加载事件中使用上述代码,但这几乎不是working@user1645793::将src
更改为href
。