在CS页面中如何调用JS脚本?
解决方案 »
- vs2008起始页去掉msdn等更新?
- 问个URL路由的问题
- 请问为设么我在向TabContainer里面动态添加TabPanel的时候第一个能成功,但添加第2个的时候就把第1个TabPanel覆盖了呢?
- 假如在页面内有一个 TextBox1 ,我把鼠标在 TextBox1 框内点一下准备输入内容的时候,我想激发以下事件,就是说不让用户直接在 TextBox1
- 最后十分问个javascript的问题,在js中怎么把一个字符串转化为c#中的DateTime型?
- 超质 asp.net网站!学习asp的同学们 必看!不看后悔!
- 关于读取多个表的sql语句怎么写?
- 大家编asp.net都用什么工具
- 大问题啊
- DataGrid的问题!是老问题吧,不过想了半天不知道怎么解决(50分)
- 各位帮帮忙看看这个错误如何解决,谢谢!
- 有哪位能够提供一份web开发的需求文档,小弟100分倾囊相授了
Button1.Attributes.Add("onclick", "if(!confirm('警告:会被删除掉,继续吗?')) return false;");
我估計你的意思是說 調用外面的JS文件。
這個本身好像不能實現。
能實現的只能手動寫腳本
如:C#的
<%@ Page Language=”C#” %>
<script runat=”server”>
protected void Page_Load(object sender, EventArgs e)
{
string myScript = @”function AlertHello() { alert(‘Hello ASP.NET’); }”;
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
“MyScript”, myScript, true);
}
</script>
vb.net的
<%@ Page Language=”VB” %>
<script runat=”server”>
Protected Sub Page_Load()Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myScript As String = “Function AlertHello()function AlertHello() { alert(‘Hello ASP.NET’); }”
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), “MyScript”, _
myScript, True)
End Sub
</script>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Adding JavaScript</title>
</head>
<body>
<form id=”form1” runat=”server”>
<div>
<asp:Button ID=”Button1” Runat=”server” Text=”Button”
OnClientClick=”AlertHello()” />
</div>
</form>
</body>
</html>當然還有其他的方法。這就不一一道來了。
function searchEnter()
{
if(13==event.keyCode)
{
event.returnValue=false;
event.cancel = true;
document.getElementById('<%=Button1.ClientID%>').click();
}
}
function init()
{
document.getElementById("TextBox1").scrollTop = document.getElementById("TextBox1").scrollHeight;
}
</script>这个是为了让一个Textbox的滚动条保持在最下面,但是当我用Ajax把Textbox用于动态刷新了之后,这个函数的调用就出现了问题。因为是在<body onload="init();">中调用,所以静态刷新的时候不激发这个动作。
function init()
{
if(event.propertyName=="value")
{
document.getElementById("TextBox1").scrollTop = document.getElementById("TextBox1").scrollHeight; }
}
onpropertychange="init()" 。textbox在页面中好像没有这个方法啊....
---
总有事件吧。前台后台
textbox在CS中有没方法直接让滚动条一直居下方?
如果有那就比弄JS快多了啊.....
谢谢了~~
下面演示代码,当点击button1时,回发到服务端,页面返回时,会执行客户端脚本方法setText
文件名:defautl3.aspx
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1"
runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
<script type="text/javascript">
if(invoke!=null)
setText();
function setText(){
document.getElementById("<%=TextBox1.ClientID %>").value="set by client script function";
}
</script>
</body>
</html>.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
string js = "<script>var invoke=true;</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), string.Empty, js);
}
}┍┥CSDN竹子专享签名功能┝━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┑
│◆如果问题解决,请结贴,谢谢! │
│◆不知道怎么结贴?请单击我。 │
│◆如有仍有其它问题,请继续顶贴。 │
│◆表跟竹子要QQ,不开QQ已经好几年了,改用GOOGLE TALK。 │
┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┙
请大家帮助我啊
一个js脚本怎么应用的到cs文件中并且怎么应用啊