我有一段javascript代码,原本写在asp .net页面里,我想把它写入asp .net后台代码中。请问要怎么写?谢谢!

解决方案 »

  1.   

    也就是说从aspx文件中,该为写入aspx.cs中,请给实例说明。
      

  2.   

     Response.Write("<script>alert('消息')</script>");
    这样就可以,我一般是这么用的。
    不过你得最好在加载页面前就加载。
    别用着时面页上不有。
      

  3.   

    Page.ClientScript.RegisterStartupScript(this.GetType(), "jsCode", "function aaa(){}", true);
      

  4.   

    这是我写的一个点击按钮的js你可以参考以下
                    string strScript = "function OpenWin(){";
                    strScript += " var str=window.showModalDialog('../Default.aspx',window,'dialogWidth:300px;dialogHeight:280px;center:yes');";
                    strScript += "}";
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "clientScript", strScript, true);
    然后你再出发这个按钮的click事件就行了
    按钮名称.Attributes.Add("onclick", "javascript:OpenDetailWin()");
    这样就可以了。
    或者是("<script></script>")这样也可以加入
    不过还得具体情况具体分析
      

  5.   

    不过用了updatepanl就不能这么用了
      

  6.   

    Page.ClientScript.RegisterStartupScript(this.GetType(), "jsCode", "alert('这里写把!')", true);
      

  7.   

    1 Response.Write(" <script>alert('消息') </script>");
    2 Page.ClientScript.RegisterStartupScript(this.GetType(), "jsCode", "function aaa(){}", true);
      

  8.   

    这是用updatepanel的:ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('删除成功');", true);
    这是不用updatepanel的:Response.Redirect("<script></script>");
      

  9.   

    我要写的javascript不只是一个函数,代码如下:
    <script type="text/javascript">
    var ig=document.getElementById("obj");
    var box=document.getElementById("box");
    var btn=document.getElementById("btn");
    var w=box.offsetWidth;  //边框宽度,就是162px
    var isIE = (document.all) ? true : false;  
    var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6); 
    var Bind = function(object, fun) { 
        return function() {
            return fun.apply(object, arguments);
        }
    }
    ig.style.position ="fixed";
    ig.style.zIndex='1000';
    ig.style.left='0'+"px";
    ig.style.top='100'+"px";
    if(isIE6){
    ig.style.position ="absolute";
    ig._fixed = Bind(ig, function(){
    ig.style.marginTop = document.documentElement.scrollTop  + "px";
    ig.style.marginLeft = document.documentElement.scrollLeft + "px";});
    ig._fixed()
    window.attachEvent("onscroll", ig._fixed); //当滚动时,保持相对位置
    }
    function set(){
        if(ig.offsetLeft+w==0)
            d(1);
        else
            d(-1);
    }
    function d(n){
        var T=setTimeout("d("+n+")",1);
        n=n<0?n-20:n+20
        ig.style.left=ig.offsetLeft+n+"px";
        if(ig.offsetLeft+w<=0){
            clearTimeout(T);
            ig.style.left=-w+"px";
            document.getElementById("icon").src="../Image/z_menuClose.gif";
            //btn.style.backgroundImage
            //btn.style.background-image: url('file:///c:/inetpub/wwwroot/ITService/../Image/z_menuClose.gif');
           // btn.style.backgroundColor="#0000FF";  //蓝色,关闭的时候
        }
        if(ig.offsetLeft>=0){
            clearTimeout(T);
            ig.style.left=0;
            document.getElementById("icon").src="../Image/z_menuOpen.gif";
          //  btn.style.background-image: url('file:///c:/inetpub/wwwroot/ITService/../Image/z_menuOpen.gif');
         // btn.style.backgroundColor="#FF0000"; //红色,打开的时候
        }
    }
    </script>