此代码适用于其他页面 但它没有在新页面中工作
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript">
function myfun() {
alert("test");
}
</script>
</asp:Content>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton CssClass="Link" ID="IMGDetail"
ClientIDMode="Static" runat="server"
ImageUrl="~/Img/Detail.png" Height="19px"
Width="19px" OnClick="IMGDetail_Click" ToolTip="Detail" />
</ItemTemplate>
</asp:TemplateField>
protected void IMGDetail_Click(object sender, ImageClickEventArgs e) {
LinkButton lbtn = (LinkButton) sender;
GridViewRow gvr = (GridViewRow) lbtn.NamingContainer;
Label LabelTicketId = (gvr.FindControl("LBTicketId") as Label);
Session["TicketId"] = LabelTicketId.Text;
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "myfun()", true);
}
答案 0 :(得分:0)
我认为您需要在aspx页面中添加以下标记。
<asp:ScriptManager ID="ScriptManager" runat="server" />
在Codebehind中
ScriptManager.RegisterStartupScript(this, typeof(string), "myfun", "myfun()", true);