ajax中如何重新调用JS文件,SOS!
前台页面<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="Maticsoft.Web.Admin.WSNC_Sensor.Index" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ Register TagPrefix="dcwc" Namespace="Dundas.Charting.WebControl" Assembly="DundasWebChart" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<%@ Register Src="../../Controls/copyright.ascx" TagName="copyright" TagPrefix="uc1" %>
<%@ Register Src="../../Controls/checkright.ascx" TagName="checkright" TagPrefix="uc2" %>
<%@ Register TagPrefix="cc1" Namespace="LtpPageControl" Assembly="LtpPageControl" %>
<!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>
<link href="../style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server" >
<div style="text-align: center">
<script language="javascript" type="text/javascript" src="../AlarmPop.js" ></script>
<!-- JS文件 -->
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<table cellspacing="0" cellpadding="5" width="97%" border="0">
<tr><td> <asp:UpdatePanel ID="UpdatePanel5" runat="server" UpdateMode="Always">
<ContentTemplate>
<table cellspacing="0" cellpadding="5" width="100%" border="0">
<tr><td height="15"></td></tr>
<tr>
<td align="left" style="height: 25px">
快速查询:
<asp:TextBox ID="txtKey" runat="server" ToolTip="关键字"></asp:TextBox>
<asp:DropDownList ID="DropField" runat="server" Width="150px" AutoPostBack="true" OnSelectedIndexChanged="DropField_SelectedIndexChanged">
<asp:ListItem Value="N_UnitCode">节点号</asp:ListItem>
<asp:ListItem Value="SensorClass">节点类型</asp:ListItem>
</asp:DropDownList>
<asp:ImageButton ID="btn_Search" runat="server" ImageUrl="../images/button_search.GIF"
ToolTip="快速检索信息" OnClick="btn_Search_Click"></asp:ImageButton>
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Button" />
</td>
</tr>
<tr><td height="15"></td></tr>
</table>
<table cellspacing="0" cellpadding="5" width="100%" border="0">
<tr>
<td bgcolor='<%=Application[Session["Style"].ToString()+"xtable_bgcolor"]%>' style="width: 100%">
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:GridView ID="gridView" runat="server" AutoGenerateColumns="False" Width="100%"
AllowPaging="True" AllowSorting="True" OnRowCreated="gridView_RowCreated" OnPageIndexChanging="gridView_PageIndexChanging"
OnRowDataBound="gridView_RowDataBound" CellPadding="5" BorderWidth="1px" PageSize="15" OnRowDeleting="gridView_RowDeleting" OnSorting="gridView_Sorting" OnRowCommand="gridView_RowCommand"
DataKeyNames="SensorID" HorizontalAlign="Center" >
<Columns>
<asp:BoundField DataField="G_UnitCode" HeaderText="所属站点" />
<asp:BoundField DataField="N_UnitCode" HeaderText="节点号" >
<HeaderStyle Height="26px" />
<ItemStyle Height="26px" />
</asp:BoundField>
<asp:BoundField DataField="SensorClass" HeaderText="节点类型" />
<asp:TemplateField HeaderText="当前通道值">
<ItemTemplate>
<%# showCurr(Eval("N_UnitCode").ToString(), Eval("SensorClass").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="AddTime" HeaderText="加入时间" />
<asp:BoundField DataField="UpdateTime" HeaderText="更新时间" />
<asp:ButtonField Text="查看记录" HeaderText="查看记录" CommandName="SearchData" >
</asp:ButtonField>
<asp:BoundField DataField="AlarmState" HeaderText="告警状态" Visible="false" />
</Columns>
<PagerSettings Mode="NumericFirstLast" />
<PagerStyle HorizontalAlign="Right" VerticalAlign="Middle" />
<RowStyle Height="20px" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"/>
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" Interval="30000" runat="server" OnTick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="Label1" runat="server" Visible="False" ForeColor="Red">没有数据!!</asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gridView"/>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"/>
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn_Search" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
后台重新调用
protected void Timer1_Tick(object sender, EventArgs e)
{
BindData();
System.Web.UI.ScriptManager.RegisterStartupScript(this.ScriptManager1, this.GetType(), "New", "../AlarmPop.js", true);
}
protected void Button3_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.UpdatePanel4, this.GetType(), "New", "../AlarmPop.js", true);
}
调用不成功 --------------------编程问答-------------------- 后台只好调用JS里的方法吧
不能直接调用JS吧
你把功能写JS方法里调用好了 --------------------编程问答-------------------- 會不會是你的路徑問題,比如說要加上文件夾名。 --------------------编程问答-------------------- 把JS文件换成直接写试试
<script>...</script> --------------------编程问答-------------------- 应该不是路径的问题
这个界面刚打开会调用一次JS文件,看到效果了
而且我把
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Button" />
按钮放在<asp:ScriptManager ID="ScriptManager1" runat="server" />
这个前面,然后点击按钮也会调用JS文件
但是这整个页面会闪一下,我加了AJAX是局部刷新的,放在AJAX外面程序正常的,放AJAX里面就不行了
--------------------编程问答-------------------- 有高人指点下吗 --------------------编程问答-------------------- 你仅仅是需要动态的加载一下JS文件?
http://blog.csdn.net/sgear/archive/2008/01/14/2043364.aspx --------------------编程问答-------------------- 是的,需要在重新调用JS文件 --------------------编程问答--------------------
6楼的可以.以前用过.好像也是找的那个 --------------------编程问答-------------------- 来人啊。。。。。 --------------------编程问答--------------------
怎么在后台调用
protected void Timer1_Tick(object sender, EventArgs e)
{
/////???????????
} --------------------编程问答-------------------- ScriptManager.RegisterStartupScript("<script language='javascript'>s1.src='test.js';</script>")
可以吗
--------------------编程问答-------------------- 难道你要这样???
.aspx
<HEAD>
<title>WebForm1</title>
<asp:placeholder id="myplaceholder" runat="server"></asp:placeholder>
</HEAD>
.cs
private void Button2_Click(object sender, System.EventArgs e)--------------------编程问答--------------------
{
System.Web.UI.Control a = Page.FindControl("myplaceholder");
System.Web.UI.HtmlControls.HtmlGenericControl objLink = new HtmlGenericControl("script");
objLink.Attributes.Add("language","javascript");
objLink.Attributes.Add("src","1.js");//这个地方你自己用变量控制
objLink=objLink;
a.Controls.Add(objLink);
}
<asp:placeholder id="myplaceholder" runat="server"></asp:placeholder>
这句不能放HEAD里
只能放body里,但是没出现效果 --------------------编程问答-------------------- 动态加载一个js文件即可 --------------------编程问答--------------------
ScriptManager.RegisterClientScriptBlock(this.UpdatePanel4, this.UpdatePanel4.GetType(), "New", "alert('弹出加载测试');", true);
这个可以调出一个弹出框,我想加载下JS文件弄不出来,郁闷啊
ScriptManager.RegisterClientScriptBlock(this.UpdatePanel4, this.UpdatePanel4.GetType(), "New", "../AlarmPop.js", true);--------------------编程问答-------------------- 请问下如何写个javascript函数啊
<script language=javascript>
function ChangeSrc()
{
var Key = document.getElementById("SrcExample")
Key.src="../AlarmPop.js";//JS文件存放路径
return false;
}
然后在后台调用ChangeSrc函数
ScriptManager.RegisterStartupScript(this, GetType(), "New", " <script language= 'javascript'>ChangeSrc() </script> ", true);
补充:.NET技术 , ASP.NET