当前位置:编程学习 > C#/ASP.NET >>

谁帮我写段代码,后台写JS,前台调用的?

最简单的ASPX.cs后台写个alert("a") 就行,还有前台aspx怎么调用,但IE首页察看源代码不会显示出来的。 --------------------编程问答-------------------- 后台:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "function test(){alert('a');}", true);

前台加一个Button点击调用:
<input id="Button1" type="button" value="button" onclick="test()" /> --------------------编程问答--------------------

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Info", "function ShowMes(mes){alert(mes);}", true);
        }
    }



<asp:Button runat="server" Text="Button" OnClientClick="ShowMes('hi');" />

察看源代码不会显示出来的?放到js文件,然后再HTML中包含 --------------------编程问答-------------------- 楼上的都可以 --------------------编程问答--------------------   LZ 开了2个一样的帖子 --------------------编程问答-------------------- Response.Write("<script>alert('a');</script>"); --------------------编程问答--------------------

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="butBack" runat="server" Text="Button"  />
        <asp:Button ID="butGo" runat="server" Text="Button" onclick="butGo_Click" />
    </div>
    
    </form>
</body>
</html>

后台

using System;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.butBack.Attributes.Add("style","display:none");
    }
    protected void butGo_Click(object sender, EventArgs e)
    {
        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('a');document.getElementById('butBack').click()", true);
    }
}


补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,