ASP .NET后台文件写javascript代码
我有一段javascript代码,原本写在asp .net页面里,我想把它写入asp .net后台代码中。请问要怎么写?谢谢!
也就是说从aspx文件中,该为写入aspx.cs中,请给实例说明。
寫了之後你做什麼操作?
Response.Write("<script>alert('消息')</script>");
这样就可以,我一般是这么用的。
不过你得最好在加载页面前就加载。
别用着时面页上不有。
Page.ClientScript.RegisterStartupScript(this.GetType(), "jsCode", "function aaa(){}", true);
方法同上
这是我写的一个点击按钮的js你可以参考以下
string strScript = "function OpenWin(){";
strScript += " var str=window.showModalDialog('../Default.aspx',window,'dialogWidth:300px;dialogHeight:280px;center:yes');";
strScript += "}";
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "clientScript", strScript, true);
然后你再出发这个按钮的click事件就行了
按钮名称.Attributes.Add("onclick", "javascript:OpenDetailWin()");
这样就可以了。
或者是("<script></script>")这样也可以加入
不过还得具体情况具体分析
不过用了updatepanl就不能这么用了
ClientScript.RegisterStartupScript
Page.ClientScript.RegisterStartupScript(this.GetType(), "jsCode", "alert('这里写把!')", true);
1 R
相关问答:
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.WebControls
Namespace CBDAspNet.WebControls.HTML
''' <summary>
'' ......
服务器现在是。net 2.0的
我现在的项目就是asp.net mvc + linq的,现在服务器的环境配置用不了。
不知道有前辈碰到过这样的问题没。
难道服务器必须要装.net3.5 和 asp.net mvc
请前辈指点
不装你认为你要怎么 ......
function CheckOpwd(){//验证用户名
var pwd=document.all.txtOpwd;
var div1=document.getElementById("divPwd");
if (pwd.value=="")
{
......
本人不会asp,报错了,请大家帮忙看看。
代码如下:
<%
dim keyword_Name,keyword_YJ,keyword_RQ
if rs("QS_PASS_1_name")<>"0,0" then
keyword_Name=split(rs("QS_ ......
A页面
<table width="200" border="1">
<tr>
<td>1</td>
<td>3</td>
<td><!--#include/top.html#-- ......