troubleshooting Question

simple ajax user control which updates timely

Avatar of dotnet0824
dotnet0824 asked on
.NET ProgrammingASP.NET
12 Comments2 Solutions679 ViewsLast Modified:
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>
                &nbsp;<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>
                    &nbsp;</fieldset>
            </ContentTemplate>
        </asp:UpdatePanel>
    &nbsp;
        <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;USER 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('newsDetail.aspx?NewsId=" + sqlRdr.GetValue(0) + "','NewsDetail','width=400,height=400;toolbar=no;');" + "><font  face='verdana' size='2' color='#ffffff'>" + sqlRdr.GetValue(1) + "</a>&nbsp;&nbsp;" + sqlRdr.GetValue(2).ToString() + "</font><br><br>";
            }

            strScrolling = strScrolling + "</Marquee>";

            sqlRdr.Close();
            ltlctrl.Text = strScrolling;

            //cellScrolling.InnerHtml = strScrolling;

            //rowScrolling.Cells.Add(cellScrolling);  

        }

        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>
ASKER CERTIFIED SOLUTION
imayknowit

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros