刚才回答过我帖子的朋友们好 <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="5000">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>废话少说,我上代码。cs文件中 static string strConnection = ConfigurationManager.AppSettings["sqlconn"].ToString();
static SqlConnection conn = new SqlConnection(strConnection); protected void Page_Load(object sender, EventArgs e)
{
Get();
} protected void Timer1_Tick(object sender, EventArgs e)
{
Get();
} protected void Get()
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from a where a='嗷嗷嗷'", conn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
//this.PopupWin1.AutoShow = true;
this.PopupWin1.Message = reader["a"].ToString();
reader.Close();
}
else
{
//this.PopupWin1.AutoShow = false;
this.PopupWin1.Message = "111";
reader.Close();
}
conn.Close();
}为什么没效果?
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="5000">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>废话少说,我上代码。cs文件中 static string strConnection = ConfigurationManager.AppSettings["sqlconn"].ToString();
static SqlConnection conn = new SqlConnection(strConnection); protected void Page_Load(object sender, EventArgs e)
{
Get();
} protected void Timer1_Tick(object sender, EventArgs e)
{
Get();
} protected void Get()
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from a where a='嗷嗷嗷'", conn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
//this.PopupWin1.AutoShow = true;
this.PopupWin1.Message = reader["a"].ToString();
reader.Close();
}
else
{
//this.PopupWin1.AutoShow = false;
this.PopupWin1.Message = "111";
reader.Close();
}
conn.Close();
}为什么没效果?
{
Timer1_Tick(null, null);
}
在控件的cs代码中定义一个属性
public string Msg
{
set { Label1.Text = value; }
}2打开aspx页面
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" Interval="1000" runat="server" ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>