在asp.net 3.5使用的RegisterClientScriptBlock /的RegisterStartupScript的 [英] Use of RegisterClientScriptBlock/RegisterStartupScript in asp.net 3.5

查看:166
本文介绍了在asp.net 3.5使用的RegisterClientScriptBlock /的RegisterStartupScript的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是无法理解有什么用it.RegisterClientScriptBlock /的RegisterStartupScript的

i am not able to understand what is the use of it.RegisterClientScriptBlock/RegisterStartupScript

当我们能够照片直接写代码javascrpt文件in.js然后调用它按钮

when we can direclty write the javascrpt code in.js file then call it on the button

例如:2

<script>
    function ReqField1Validator() { 
        if (document.forms[0].txtField1.value == '') {
            alert('TextBox cannot be empty') 
            return false
         } 
         return true 
     } 
</script>

btnPostback.Attributes.Add("onclick","return ReqField1Validator()");



会是怎样使用的RegisterClientScriptBlock /的RegisterStartupScript?

what will be the use of RegisterClientScriptBlock/RegisterStartupScript ?

protected void btnPostback_Click(object sender, EventArgs e)  {
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append(@"<script language='javascript'>");
    sb.Append(@"var lbl = document.getElementById('lblDisplayDate');");
    sb.Append(@"lbl.style.color='red';");
    sb.Append(@"</script>");

    if (!ClientScript.IsStartupScriptRegistered("JSScript")){
        ClientScript.RegisterStartupScript(this.GetType(), "JSScript", sb.ToString());
    }
}



阅读几篇文章,但他们并不清楚。

read few articles but they were not clear

在这个任何想法将是巨大的。

any thoughts on this would be great

由于
王子

推荐答案

的RegisterStartupScript 用于注册,一旦页面加载完成后执行JavaScript函数,这段JavaScript代码在onLoad之前执行页面的事件引发的。你可以用它为多种原因,例如,您要执行任何特定取决于背后的代码中的一些变量值的JavaScript函数。

RegisterStartupScript is used to register and execute javascript functions once the page finished loading, this javascript code executes before the onLoad event of page is raised. You can use it for multiple reasons, for example, you want to execute any particular javascript function depending on some variable value in your code behind.

在另一方面,的RegisterClientScriptBlock 用于在页面的顶部添加一个脚本块,同样它提供你一个方法,在后面的代码客户端代码和服务器代码都工作。

On the other hand, RegisterClientScriptBlock is used to add a script block on the top of your page, similarly it provides you a way to work with both client side code and server code in your code behind.

这篇关于在asp.net 3.5使用的RegisterClientScriptBlock /的RegisterStartupScript的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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