如何在c#中的pageload事件中调用javascript函数 [英] how to call javascript function in pageload event in c#

查看:322
本文介绍了如何在c#中的pageload事件中调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 

< script 语言 = javascript 类型 = text / javascript < span class =code-keyword>>

function print(){
window.print();
}
< / script >
代码背后:

protected void Page_Load( object sender,EventArgs e)
{
ScriptManager.RegisterClientScriptBlock( this .Page, this .GetType(), script print());
}
无法正常工作。请帮助我。



 

解决方案

尝试下面的类似解决方案



http:// stackoverflow.com/questions/14079029/how-to-call-javascript-function-on-page-load-in-asp-net [ ^ ]



我创建了一个示例,代码流到达页面加载事件的javascript函数。



  protected   void  Page_Load( object  sender,EventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), Javascript 的javascript:打印(); true );
}







 <  !DOCTYPE  < span class =code-attribute>   html  >  

< html xmlns = http://www.w3.org/1999/ xhtml >
< head runat = server >
< 标题 > < / title >

< script lang = javascript type = text / javascript >

function print(){
// window.print();
alert('你好');
}
< / script >

< / head >
< body >
< 表格 < span class =code-attribute> id = form1 runat = server >
< div >

< / div >
< / form >
< span class =code-keyword>< / body >
< / html >


I have tried using this.

 <script language="javascript" type="text/javascript">

        function print() {
            window.print();
        }
    </script>
In code behind:

    protected void Page_Load(object sender, EventArgs e)
    {
      ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "script", "print()", true);
    }
But it is not working.please help me.


解决方案

Try the below with similar solution

http://stackoverflow.com/questions/14079029/how-to-call-javascript-function-on-page-load-in-asp-net[^]

I created a sample and code flow reaches the javascript function on page load event.

protected void Page_Load(object sender, EventArgs e)
       {
           ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:print(); ", true);
       }




<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script lang="javascript" type="text/javascript">

        function print() {
            // window.print();
            alert('hello');
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>


这篇关于如何在c#中的pageload事件中调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆