就是我在aspx页面里引用js文件,然后调用这个js文件里的一个function。打个比方吧,类似于asp里的<% call function() %>谢谢,20分表心意~

解决方案 »

  1.   

    string str = "function()";//前台函數名
                ClientScriptManager cs = Page.ClientScript;
                cs.RegisterStartupScript(this.GetType(), "", str, true);
      

  2.   

    呵呵,不知樓主是在前台.ASPX調用,還是在後台.CS調用?!
    如果是前台,直接調用即可。我想樓主指的是後台CS裡調用吧。
    我們舉個例子:
    //js函數
    <script>
    function test(){
      alert("Hello");
    }
    </script>//後台CS的page_load裡調用protected void Page_Load(object sender, EventArgs e)
        {
            string str = "test()";//JS函數名
            ClientScriptManager cs = Page.ClientScript;
            cs.RegisterStartupScript(this.GetType(), "", str, true);
    }
      

  3.   

    StringBuilder scriptstring = new StringBuilder();
    scriptstring.Append("<script language=javascript>");
    scriptstring.Append("function Setfirstfocus(){");
    scriptstring.Append("alert('karso ok!');}");
    scriptstring.Append("</script>");
    string js = scriptstring.ToString();
    Page.RegisterClientScriptBlock("Setfirstfocus", js);