我想用<asp:Timer ID="Timer1" runat="server" Interval="30000" OnTick="Timer1_Tick">
30秒刷新UpdatePanel2,但是 每次都是把所有的页面刷新一次,请问 怎么设置能实现刷新UpdatePanel2部分?<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>WWWWWW</title> <script language="JavaScript" type="text/javascript" src="JS/Prototype.js"></script> <script language="JavaScript" type="text/javascript" src="JS/Public.js"></script> <script language="JavaScript" type="text/javascript" src="JS/jspublic.js"></script> <script language="JavaScript" type="text/javascript" src="JS/AdminIndex.js"></script> <style type="text/css">
.style1
{
width: 721px;
}
</style>
</head>
<body id="Indexbody">
<form runat="server" id="form1">
<asp:ScriptManager ID="Scriptmanager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<%-- 身份:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br>
名称:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br>
消息:
<asp:Label ID="Label3" runat="server"></asp:Label>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/sms1.gif" Visible="False"
alt="你有未读消息" />--%>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="30000" OnTick="Timer1_Tick">
</asp:Timer>
<table>
<tr>
<td>
身份:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br>
名称:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br>
消息:
<asp:Label ID="Label3" runat="server"></asp:Label>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/sms1.gif" Visible="False"
alt="未读消息" />
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</td>
<td colspan="3">
<div id="sys_top" name="sys_top" style="height: 66px; background-color: #DAE9F5;
width: 1009px;">
<center style="width: 916px">
<font size="6" color="">WWWWWW</font></center>
</div>
</td>
</tr>
<tr style="vertical-align: top">
<td id="frmTitle" align="left">
<iframe id="left" style="z-index: 2; visibility: inherit; width: 180px; height: 794px"
name="left" src="menua.aspx?type=0" frameborder="0" scrolling="no"></iframe>
</td>
<td class="but" onclick="switchSysBar()">
<div style="border-right: 0px; border-top: 0px; border-left: 0px; width: 12px; height: 700px;
border-bottom: 0px">
<center>
<table id="Divb" cellpadding="0" cellspacing="0" style="width: 12px; height: 720px;">
<tr>
<td style="background: url(Images/butBG.gif);">
<img id="switchPoint" alt="关闭左栏" onmousemove="switchSysBarb()" onmouseout="switchSysBarc()"
src="Images/close.gif">
</td>
</tr>
</table>
</center>
</div>
</td>
<td class="style1">
<iframe id="sys_main" name="sys_main" style="z-index: 2; width: 991px; height: 798px;"
frameborder="0 " scrolling="auto"></iframe>
</td>
</tr>
</tbody>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack){ if (Session["User"] == null)
{
Response.Redirect("Login.aspx");
}
else
{ //UserEntity user = (UserEntity)Session["User"];
SessionClass se = new SessionClass();
UserEntity user = se.getUserEntity();
this.Label2.Text = user.name;
this.Label1.Text =user.isadmin=="1"?"管理员":"普通用户"; }
} }
protected void Timer1_Tick(object sender, EventArgs e)
{
UserEntity u = Session["User"] as UserEntity; if(null!=u){
int Count = new DAO.Dao().Search_Mess("","0", u.isadmin, u.name).Rows.Count;
if(Count>0){
this.Label3.Text = "有" + Count + "新消息!";
this.Image1.Visible = true;
}
} }
}
30秒刷新UpdatePanel2,但是 每次都是把所有的页面刷新一次,请问 怎么设置能实现刷新UpdatePanel2部分?<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>WWWWWW</title> <script language="JavaScript" type="text/javascript" src="JS/Prototype.js"></script> <script language="JavaScript" type="text/javascript" src="JS/Public.js"></script> <script language="JavaScript" type="text/javascript" src="JS/jspublic.js"></script> <script language="JavaScript" type="text/javascript" src="JS/AdminIndex.js"></script> <style type="text/css">
.style1
{
width: 721px;
}
</style>
</head>
<body id="Indexbody">
<form runat="server" id="form1">
<asp:ScriptManager ID="Scriptmanager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<%-- 身份:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br>
名称:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br>
消息:
<asp:Label ID="Label3" runat="server"></asp:Label>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/sms1.gif" Visible="False"
alt="你有未读消息" />--%>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="30000" OnTick="Timer1_Tick">
</asp:Timer>
<table>
<tr>
<td>
身份:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br>
名称:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br>
消息:
<asp:Label ID="Label3" runat="server"></asp:Label>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/sms1.gif" Visible="False"
alt="未读消息" />
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</td>
<td colspan="3">
<div id="sys_top" name="sys_top" style="height: 66px; background-color: #DAE9F5;
width: 1009px;">
<center style="width: 916px">
<font size="6" color="">WWWWWW</font></center>
</div>
</td>
</tr>
<tr style="vertical-align: top">
<td id="frmTitle" align="left">
<iframe id="left" style="z-index: 2; visibility: inherit; width: 180px; height: 794px"
name="left" src="menua.aspx?type=0" frameborder="0" scrolling="no"></iframe>
</td>
<td class="but" onclick="switchSysBar()">
<div style="border-right: 0px; border-top: 0px; border-left: 0px; width: 12px; height: 700px;
border-bottom: 0px">
<center>
<table id="Divb" cellpadding="0" cellspacing="0" style="width: 12px; height: 720px;">
<tr>
<td style="background: url(Images/butBG.gif);">
<img id="switchPoint" alt="关闭左栏" onmousemove="switchSysBarb()" onmouseout="switchSysBarc()"
src="Images/close.gif">
</td>
</tr>
</table>
</center>
</div>
</td>
<td class="style1">
<iframe id="sys_main" name="sys_main" style="z-index: 2; width: 991px; height: 798px;"
frameborder="0 " scrolling="auto"></iframe>
</td>
</tr>
</tbody>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack){ if (Session["User"] == null)
{
Response.Redirect("Login.aspx");
}
else
{ //UserEntity user = (UserEntity)Session["User"];
SessionClass se = new SessionClass();
UserEntity user = se.getUserEntity();
this.Label2.Text = user.name;
this.Label1.Text =user.isadmin=="1"?"管理员":"普通用户"; }
} }
protected void Timer1_Tick(object sender, EventArgs e)
{
UserEntity u = Session["User"] as UserEntity; if(null!=u){
int Count = new DAO.Dao().Search_Mess("","0", u.isadmin, u.name).Rows.Count;
if(Count>0){
this.Label3.Text = "有" + Count + "新消息!";
this.Image1.Visible = true;
}
} }
}
http://topic.csdn.net/u/20080916/10/5C2D967F-4930-4DA7-A819-F86E2BC9A33F.html
<asp:Timer ID="Timer1" runat="server" Interval="30000" OnTick="Timer1_Tick">
</asp:Timer>//把这个放到<ContentTemplate></ContentTemplate>外面
建议 使用ajax
使用xmlHttpRequest异步提交