当前位置: 代码迷 >> ASP.NET >> vs2010中怎么使用ClientScriptManager
  详细解决方案

vs2010中怎么使用ClientScriptManager

热度:3912   发布时间:2013-02-25 00:00:00.0
vs2010中如何使用ClientScriptManager?
两个问题:

1. 想要达到2008中的ScriptManager.RegisterStartupScript效果,在页面上弹出提示对话框。
2. int i = 0;
  return int.TryParse(str, out i); out i 这个是什么意思?


请知道的人赐教,谢谢。


------解决方案--------------------------------------------------------
首先要搞清楚ref和out的区别,ref 要求参数在传递给函数前要初始化,out则不需要。
两者都是按地址传递的,使用后都将改变原来的数值。rel可以把参数的数值传递进函数,但是out是要把参数清空,就是说你无法把一个数值从out传递进去的,out进去后,参数的数值为空,所以你必须初始化一次。这个就是两个的区别,或者说就像有的网友说的,rel是有进有出,out是只出不进。
------解决方案--------------------------------------------------------
int i=0;
if(int.TryParse("abc",out i)){转换成功,i就是要的值}
------解决方案--------------------------------------------------------
探讨
受教了,对于是楼说的不是很明白,这个返回类型不是bool型嘛,为什么说转换成功,i就是要的值?

------解决方案--------------------------------------------------------
this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert(\"编辑成功\");", true);
------解决方案--------------------------------------------------------
探讨
两个问题:

1. 想要达到2008中的ScriptManager.RegisterStartupScript效果,在页面上弹出提示对话框。
2. int i = 0;
return int.TryParse(str, out i); out i 这个是什么意思?


请知道的人赐教,谢谢。

------解决方案--------------------------------------------------------
探讨

10中没有ScriptManager这个类,只有ClientScriptManager类,但ClientScriptManager又没有RegisterStartupScript方法;

我在网上查了一下,我看有人这样用:
ClientScriptManager csm = Page.ClientScript.... 后面怎么写忘了。

但我的Page类中没有ClientScript……

------解决方案--------------------------------------------------------
C# code
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace Yasn.SCS.Web{    public partial class WebForm1 : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {            ClientScriptManager csm = Page.ClientScript;            csm.RegisterStartupScript(this.GetType(), "信息框", "成功");        }    }}
  相关解决方案