Hi,
I created a v simple user control using ajax updatepanel.
and called it in a asp.net page. it works fine but looks like usercontrol doesnot refresh. I added new records to check
but i am not sure whats wrong I am doing.
UserControl Design Code
<div style="padding-top: 0px">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label id="ltlctrl" Width="30%" Height="18px" runat="server"></asp:Label
>
<asp:Timer ID="Timer1" runat="server" Interval="10" OnTick="Timer1_Tick1">
</asp:Timer>
<fieldset>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<br />
</div>
==========================
==Code behind in userControl===============
===
private void Page_Load(object sender, System.EventArgs e)
{
GetNews();
}
public void GetNews()
{
// Put user code to initialize the page here
SqlConnection myCon = new SqlConnection("server=TEST
;DATABASE=
SA_USER;US
ER ID=sa;password=;");
string strSql = "SELECT top 5 * FROM tbl_News order by dateCreated asc";
string strScrolling = "";
HtmlTableCell cellScrolling = new HtmlTableCell();
SqlCommand myComd = new SqlCommand(strSql, myCon);
SqlDataReader sqlRdr;
try
{
myCon.Open();
sqlRdr = myComd.ExecuteReader();
strScrolling = "<Marquee OnMouseOver='this.stop();'
OnMouseOut='this.start();'
direction='up' scrollamount='2' bgcolor='blue' width='80%'>";
while (sqlRdr.Read())
{
strScrolling = strScrolling + "<a href='#' OnClick=" + "javascript:window.open('n
ewsDetail.
aspx?NewsI
d=" + sqlRdr.GetValue(0) + "','NewsDetail','width=400
,height=40
0;toolbar=
no;');" + "><font face='verdana' size='2' color='#ffffff'>" + sqlRdr.GetValue(1) + "</a> " + sqlRdr.GetValue(2).ToStrin
g() + "</font><br><br>";
}
strScrolling = strScrolling + "</Marquee>";
sqlRdr.Close();
ltlctrl.Text = strScrolling;
//cellScrolling.InnerHtml = strScrolling;
//rowScrolling.Cells.Add(c
ellScrolli
ng);
}
catch (Exception ex)
{
throw (ex);
}
finally
{
//close sql connection
myCon.Close();
}
protected void Timer1_Tick1(object sender, EventArgs e)
{
UpdatePanel1.Update();
}
}
==========================
=ASP.NET Page added that user Control-------------------
-
<%@ Register TagPrefix="uc1" TagName="links" Src="Ticker.ascx" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:links ID="link1" runat="server" />
</div>
</form>
</body>
</html>
<div style="padding-top: 0px">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick">
</asp:AsyncPostBackTrigger
</Triggers>
<ContentTemplate>
<asp:Label id="ltlctrl" Width="30%" Height="18px" runat="server"></asp:Label
<asp:Timer ID="Timer1" runat="server" Interval="10" >
</asp:Timer>
<fieldset>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<br />
</div>