从C#调用javascript - 请帮忙 [英] Calling javascript from C#--help please

查看:68
本文介绍了从C#调用javascript - 请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//我编写了以下代码,但它无效。

//请帮忙吗?

// ---------- --------------------------------------

使用System;

使用System.Collections;

使用System.ComponentModel;

使用System.Data;

使用System.Drawing ;

使用System.Web;

使用System.Web.SessionState;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Web.UI.HtmlControls;


命名空间测试

{

///< summary>

/// WebForm1的摘要说明。

///< / summary>

公共类CallJavaScriptFromServerCode:System.Web.UI.Page

{

private void Page_Load(object sender,System.EventArgs e)

{

string toRed ="< script language = \" javascript \"> " ;;

toRed + =" function RedIt(){" ;;

toRed + =" document.bgColor = \" red \" ;如果(!IsClientScriptBlockRegistered(" bgColor"))

{

RegisterClientScriptBlock(" bgColor",toRed);

}

}

#region Web表单设计器生成的代码

覆盖protected void OnInit(EventArgs e)

{

//

// CODEGEN:ASP.NET Web窗体设计器需要此调用。

//

InitializeComponent();

base.OnInit(e);

}


///< summary>

///所需方法对于Designer支持 - 请勿使用代码编辑器修改

///此方法的内容。

///< / summary>

private void InitializeComponent()

{

this.Load + = new System.EventHandler(this.Page_Load);


}

#endregion

}

}

// I wrote the following code but it is not working.
// Any help please?
// ------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Testings
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class CallJavaScriptFromServerCode : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string toRed = "<script language=\"javascript\"> ";
toRed += "function RedIt() { ";
toRed += "document.bgColor = \"red\"; } ";
toRed += "</script>";

if(!IsClientScriptBlockRegistered("bgColor"))
{
RegisterClientScriptBlock("bgColor",toRed);
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

推荐答案

双hoy,


什么叫你的javascript函数?


我没有看到任何代码来解雇它。是否附有按钮点击?


-

此致,


S. Justin Gengo,MCP

网站开发人员/程序员

www.aboutfortunate。 com


混乱就是订单。

Nietzsche

" Bishoy George" <双**** @ bishoy.com>在留言中写道

news:uo ************** @ TK2MSFTNGP14.phx.gbl ...
Bishoy,

What calls your javascript function?

I don''t see any code to fire it. Is it attached to a button click?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Bishoy George" <bi****@bishoy.com> wrote in message
news:uo**************@TK2MSFTNGP14.phx.gbl...
//我写了以下代码,但它不起作用。
//请帮忙吗?
// -------------------------- ----------------------
使用System;
使用System.Collections;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Web;
使用System.Web.SessionState;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.HtmlControls;

命名空间测试
{
///< summary>
/// WebForm1的摘要描述。
///< / summary>
公共类CallJavaScriptFromServerCode:System.Web.UI.Page
{
private void Page_Load(对象发送者,System.EventArgs e)
字符串toRed ="< script language = \" javascript \"> " ;;
toRed + =" function RedIt(){" ;;
toRed + =" document.bgColor = \" red\" ;; }" ;;
toRed + ="< / script>" ;;

if(!IsClientScriptBlockRegistered(" bgColor"))
{
RegisterClientScriptBlock (bgColor,toRed);
}

#region Web窗体设计器生成的代码
覆盖保护的void OnInit(EventArgs e)
{
//
// CODEGEN:ASP.NET Web窗体设计器需要此调用。
//
InitializeComponent();
base.OnInit( e);
}
///< summary>
/// Designer支持所需的方法 - 不要修改
///这个内容使用代码编辑器的方法。
///< / summary>
private void InitializeComponent()
{
this.Load + = new System.EventHandler(this.Page_Load) ;

}
#endregion
}
}
// I wrote the following code but it is not working.
// Any help please?
// ------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Testings
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class CallJavaScriptFromServerCode : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string toRed = "<script language=\"javascript\"> ";
toRed += "function RedIt() { ";
toRed += "document.bgColor = \"red\"; } ";
toRed += "</script>";

if(!IsClientScriptBlockRegistered("bgColor"))
{
RegisterClientScriptBlock("bgColor",toRed);
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}



Bishoy George写道:
Bishoy George wrote:
//我编写了以下代码,但它无效。
//请帮忙吗?
// --------------------------------- ---------------
使用System;
使用System.Collections;
使用System.ComponentModel;
使用System.Data; <使用System.Drawing;
使用System.Web;
使用System.Web.SessionState;
使用System.Web.UI;
使用System.Web.UI。 WebControls;
使用System.Web.UI.HtmlControls;

名称空间测试
//
摘要>
///摘要说明for WebForm1。
///< / summary>
公共类CallJavaScriptFromServerCode:System.Web.UI.Page
{void void Page_Load(object sender,System.EventArgs e) )
{
string toRed ="< script language = \" javascript \"> " ;;
toRed + =" function RedIt(){" ;;
toRed + =" document.bgColor = \" red\" ;; }" ;;
toRed + ="< / script>" ;;

if(!IsClientScriptBlockRegistered(" bgColor"))
{
RegisterClientScriptBlock (bgColor,toRed);
}

#region Web窗体设计器生成的代码
覆盖保护的void OnInit(EventArgs e)
{
//
// CODEGEN:ASP.NET Web窗体设计器需要此调用。
//
InitializeComponent();
base.OnInit( e);
}
///< summary>
/// Designer支持所需的方法 - 不要修改
///这个内容使用代码编辑器的方法。
///< / summary>
private void InitializeComponent()
{
this.Load + = new System.EventHandler(this.Page_Load) ;

}
#endregion
}
}
// I wrote the following code but it is not working.
// Any help please?
// ------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Testings
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class CallJavaScriptFromServerCode : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string toRed = "<script language=\"javascript\"> ";
toRed += "function RedIt() { ";
toRed += "document.bgColor = \"red\"; } ";
toRed += "</script>";

if(!IsClientScriptBlockRegistered("bgColor"))
{
RegisterClientScriptBlock("bgColor",toRed);
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}




什么不是''工作?当你从asp页面查看来源时是脚本吗?


-

Rob Schieber



What isn''t working? is the script there when you view the source from
your asp page?

--
Rob Schieber


页面上有什么叫它的吗?


-

Curt Christianson

site: http://www.darkfalz.com

博客: http://blog.darkfalz.com


" Bishoy George"写道:
is there anything on the page calling it?

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"Bishoy George" wrote:
//我写了下面的代码,但它没有用。
//请帮忙吗?
// ------- -----------------------------------------
使用System; 使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Web;
使用System。 Web.SessionState;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.HtmlControls;

名称空间测试
///< summary>
/// WebForm1的摘要描述。
///< / summary>
公共类CallJavaScriptFromServerCode:System .Web.UI.Page
{void void Page_Load(object sender,System.EventArgs e)
字符串toRed ="< script language = \" javascript\"> " ;;
toRed + =" function RedIt(){" ;;
toRed + =" document.bgColor = \" red\" ;; }" ;;
toRed + ="< / script>" ;;

if(!IsClientScriptBlockRegistered(" bgColor"))
{
RegisterClientScriptBlock (bgColor,toRed);
}

#region Web窗体设计器生成的代码
覆盖保护的void OnInit(EventArgs e)
{
//
// CODEGEN:ASP.NET Web窗体设计器需要此调用。
//
InitializeComponent();
base.OnInit( e);
}
///< summary>
/// Designer支持所需的方法 - 不要修改
///这个内容使用代码编辑器的方法。
///< / summary>
private void InitializeComponent()
{
this.Load + = new System.EventHandler(this.Page_Load) ;

}
#end>
}

// I wrote the following code but it is not working.
// Any help please?
// ------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Testings
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class CallJavaScriptFromServerCode : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string toRed = "<script language=\"javascript\"> ";
toRed += "function RedIt() { ";
toRed += "document.bgColor = \"red\"; } ";
toRed += "</script>";

if(!IsClientScriptBlockRegistered("bgColor"))
{
RegisterClientScriptBlock("bgColor",toRed);
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}



这篇关于从C#调用javascript - 请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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