从服务器端asp.net控件调用客户端Javascript

从服务器端asp.net控件调用客户端Javascript

问题描述:

我在客户端具有javascript函数
我想在服务器端调用此javascript


例如
我正在使用gridview,当我单击gridview中的下一页时,我想将页面滚动到顶部,而我需要使用javascript来做所有这一切.

顺便说一句,我正在使用更新面板,以便该页面不回发
所以任何想法如何调用我在客户端编写的函数,都可以在服务器端使用,
我也曾尝试过这样做,但无法正常工作.

我使用的脚本
< script>
函数scrollWindow(){
window.scrollTo(100,500);
返回false;
}
</script>



//受保护的Sub g1_PageIndexChanging(ByVal发送者作为对象,ByVal e作为System.Web.UI.WebControls.GridViewPageEventArgs)处理g1.PageIndexChanging

//ScriptManager.RegisterStartupScript(Me.Page,Me.[GetType](),"ac","scrollWindow();",True)
//g1.PageIndex = e.NewPageIndex
//grid()

//结束子

帮帮忙,Google也不帮忙

I have a javascript function on my client-side
and i want to call this javascript on server side


E.g
I am using gridview , and i want to page scroll to top when the i click to next page in gridview and all this i have to do using javascript .

by the way i am using update panel so that page do not postback
so any idea how to call the function which i had write on client-side and i can used from server side ,
i had tried doing this also , but won''t work .

Script i used
<script>
function scrollWindow() {
window.scrollTo(100, 500);
return false;
}
</script>



//Protected Sub g1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles g1.PageIndexChanging

//ScriptManager.RegisterStartupScript(Me.Page, Me.[GetType](), "ac", "scrollWindow();", True)
// g1.PageIndex = e.NewPageIndex
// grid()

// End Sub

Help out , Google is also not helping

您可以在设计端的按钮标签中使用以下代码来调用javascript函数.


You can use the following in design side in your button''s tag to call a javascript function.


onclick="javascript:FunctionName(this)"



注意:请记住,服务器端



NOTE: Keep in mind the difference between Server Side

OnClick

方法(使用大写字母C)与& javascript

method (with Capital C) & javascript

onclick



(带有小c).

或者如果您想在没有任何事件(buttonclick等)的情况下调用javascript函数,即代码中的u可以使用以下代码.



(with small c).

or if you want to call a javascript function without any event(buttonclick etc), i.e from code than u can use the following.

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ac", "FunctionName();", true);




希望对您有帮助...




Hope it will help...