頁面定時刷新(c# asp .net 2003)

本文介绍了如何在ASP.NET 2003的C# WebForm中实现页面定时刷新的功能。通过主页面和子页面的交互,结合TextBox控件和字符串操作,展示了自动刷新的技术实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

頁面:

 

主頁面 aspx

<%@ Page language="c#" Codebehind="inp116.aspx.cs" AutoEventWireup="false" Inherits="USE_WEB_SC.ASP.inp116" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    
<HEAD>
        
<title>各戶下單未承接表</title>
        
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
        
<meta content="C#" name="CODE_LANGUAGE">
        
<meta content="JavaScript" name="vs_defaultClientScript">
        
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
        
<meta http-equiv="Content-Type" content="text/html; charset=big5">
        
<style type="text/css">
BODY 
{ MARGIN-TOP: 0px; MARGIN-RIGHT: 0px }
BODY 
{ FONT-SIZE: 12px }
TD 
{ FONT-SIZE: 12px }
TH 
{ FONT-SIZE: 12px }
        
</style>
    
</HEAD>
    
<body MS_POSITIONING="GridLayout">
        
<form id="Form1" method="post" runat="server">
            
<TABLE width="100%">
                
<TR>
                    
<TD height="50"><FONT face="新細明體">
                            
<TABLE border="0" cellPadding="0" cellSpacing="0">
                                
<TR>
                                    
<TD width="58" align="center" nowrap>刷新時間</TD>
                                    
<TD width="168" align="center" nowrap style="WIDTH: 52px"><asp:textbox id="TextBox1" runat="server" Columns="8"></asp:textbox></TD>
                                    
<TD width="14" nowrap></TD>
                                    
<TD width="44" nowrap><asp:button id="Button1" runat="server" Text="確認"></asp:button></TD>
                                    
<TD width="209" nowrap>
                                        
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" Font-Size="12px" ErrorMessage="不能為空"
                                            Display
="Dynamic" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
                                        
<asp:RangeValidator id="RangeValidator1" runat="server" ErrorMessage="請輸入1~30之間的數字!" Display="Dynamic"
                                            Type
="Integer" MaximumValue="30" MinimumValue="1" ControlToValidate="TextBox1" Font-Size="12px"></asp:RangeValidator></TD>
                                
</TR>
                            
</TABLE>
                        
</FONT>
                    
</TD>
                
</TR>
                
<TR>
                    
<TD vAlign="top"><iframe border="0" name="a1" src="inp116up.aspx" frameBorder="0" width="100%" scrolling="no"
                            onload
="this.height=a1.document.body.scrollHeight"> 您的瀏覽器不支援內置框架或目前的設定為不顯示內置框架。</iframe>
                    
</TD>
                
</TR>
            
</TABLE>
        
</form>
    
</body>
</HTML>

主頁面 aspx.cs

 

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;
using System.Data.SqlClient;

namespace USE_WEB_SC.ASP
{
    
/// <summary>
    
/// inp116 的摘要描述。
    
/// </summary>

    public class inp116 : System.Web.UI.Page
    
{
        
protected System.Web.UI.WebControls.TextBox TextBox1;
        
protected System.Web.UI.WebControls.Button Button1;
        
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
        
protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
        
protected System.Web.UI.WebControls.DataGrid dgShow;
    
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
if(!this.IsPostBack)
            
{
                
this.Session.Clear();
                
string stremp_no=Request.QueryString["emp_no"];
                
string strCon = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                SqlConnection con 
= new SqlConnection(strCon);
                con.Open();
                SqlCommand cmd
=new SqlCommand("select c30_02 from cnf30 where c30_05='"+stremp_no+"'",con);
                
string  strc30_05=cmd.ExecuteScalar().ToString();
                
this.TextBox1.Text=strc30_05;
                
this.Session["strc30_05"]=Convert.ToString(Convert.ToInt64(strc30_05)*60);
            }

            
this.Session["strcomid"]=this.Request.QueryString["comID"];
        }

        
Web Form 設計工具產生的程式碼
        
private void Button1_Click(object sender, System.EventArgs e)
        
{
            
this.Session.Clear();
            
this.Session["strc30_05"]=Convert.ToString(Convert.ToInt64(this.TextBox1.Text)*60);
            
string sessionstr=this.Session["strc30_05"]+"";
            
this.Session["strcomid"]=this.Request.QueryString["comID"];
        }

    }

}

子頁面 aspx:

 

<%@ Page language="c#" Codebehind="inp116up.aspx.cs" AutoEventWireup="false" Inherits="USE_WEB_SC.ASP.inp116up" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    
<HEAD>
        
<title>inp116up</title>
        
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        
<meta name="CODE_LANGUAGE" Content="C#">
        
<meta name="vs_defaultClientScript" content="JavaScript">
        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        
<meta http-equiv="refresh" content="<%=this.Session["strc30_05"]%>;url=inp116up.aspx">
    
</HEAD>
    
<body MS_POSITIONING="GridLayout">
        
<form id="Form1" method="post" runat="server">
            
<asp:DataGrid id="dgShow" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
                Width
="100%" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" BackColor="White"
                CellPadding
="3" Font-Size="12px" AutoGenerateColumns="False">
                
<FooterStyle Wrap="False" ForeColor="#000066" BackColor="White"></FooterStyle>
                
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle>
                
<ItemStyle ForeColor="#000066"></ItemStyle>
                
<HeaderStyle Font-Bold="True" Wrap="False" ForeColor="White" BackColor="#006699"></HeaderStyle>
                
<Columns>
                    
<asp:BoundColumn DataField="i16_01" HeaderText="編號">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                        
<ItemStyle Wrap="False"></ItemStyle>
                        
<FooterStyle Wrap="False"></FooterStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_02" HeaderText="取件時間">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                        
<ItemStyle Wrap="False"></ItemStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_21" HeaderText="公司客代">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_22" HeaderText="公司名稱">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_23" HeaderText="地址">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_24" HeaderText="聯系人">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_25" HeaderText="電話">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                        
<ItemStyle Wrap="False"></ItemStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_27" HeaderText="Email">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_52" HeaderText="目的地">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_55" HeaderText="件數">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_57" HeaderText="重量">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="i16_59" HeaderText="備註">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="dep_no3" HeaderText="建檔分站">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:BoundColumn DataField="comid" HeaderText="建檔公司">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                    
</asp:BoundColumn>
                    
<asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="i16_04" DataNavigateUrlFormatString="http://www.use.com.hk/ASPN/inp016.aspx?key_i16_04={0}"
                        DataTextField
="i16_04" HeaderText="查看" DataTextFormatString="詳細資料">
                        
<HeaderStyle Wrap="False"></HeaderStyle>
                        
<ItemStyle Wrap="False"></ItemStyle>
                    
</asp:HyperLinkColumn>
                
</Columns>
                
<PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White" Wrap="False" Mode="NumericPages"></PagerStyle>
            
</asp:DataGrid>
        
</form>
    
</body>
</HTML>

子頁面aspx.cs:

 

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;
using System.Data.SqlClient;

namespace USE_WEB_SC.ASP
{
    
/// <summary>
    
/// inp116up 的摘要描述。
    
/// </summary>

    public class inp116up : System.Web.UI.Page
    
{
        
protected System.Web.UI.WebControls.DataGrid dgShow;
    
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在這裡放置使用者程式碼以初始化網頁
            this.BindData();
        }

        
private void BindData()
        
{
            
string strcomid=this.Session["strcomid"]+"";
            
string strempty="";
            
string strCon = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
            SqlConnection con 
= new SqlConnection(strCon);
            DataSet ds 
= new DataSet();
            
if(strcomid=="0000")
            
{
                SqlDataAdapter da 
= new SqlDataAdapter("select i16_01,i16_02,i16_21,i16_22,i16_23,i16_24,i16_25,i16_27,i16_52,i16_55,i16_57,i16_59,dep_no3,comid,i16_04 from inf16 where  i16_61='"+strempty+"' and i16_63='"+strempty+"'",con);
                da.Fill(ds,
"inf16");
            }

            
else
            
{
                SqlDataAdapter da 
= new SqlDataAdapter("select i16_01,i16_02,i16_21,i16_22,i16_23,i16_24,i16_25,i16_27,i16_52,i16_55,i16_57,i16_59,dep_no3,comid,i16_04 from inf16 where comid='"+strcomid+"' and i16_61='"+strempty+"' and i16_63='"+strempty+"'",con);
                da.Fill(ds,
"inf16");
            }

            dgShow.DataSource 
= ds.Tables["inf16"].DefaultView;
            
//            ds.Tables["inf16"].DefaultView.Sort="c32_02 ASC";
            dgShow.DataBind();
        }



        
Web Form 設計工具產生的程式碼


        
private void dgShow_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        
{
            
string strcomid=this.Session["strcomid"]+"";
            
if(strcomid=="0000")
                
this.dgShow.Columns[13].Visible=true;
            
else
                
this.dgShow.Columns[13].Visible=false;
        }

    }

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值