Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys..!!!!!!!!!

i am developing chat application..when user click on online users link...the pop up window (dynamic control) will be shown in an update panel.but due to timer event ,after post back dynamically created controls gets deleted from the page..so in a post back event i will again create them with same id's.but due to this whenever i am trying to type in textbox in an user control.after page refresh , focus from textbox gets diverted.so i have to again and again click on tetxbox to type something in it.

timer event is used to find whether new message is came for current user in a database or not.
i think the problem is due to recreation of user control in pageload event.

ASP.NET
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ChatWindow.ascx.cs" Inherits="ChatWindow" %>


<div style="width: 211px;border:thick solid #ffa800"> 

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
 <ContentTemplate> 
          Hi  <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>..<br />
        <asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" Height="172px"  Width="186px"></asp:TextBox><br /><br />
            <asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick" Enabled="true">   </asp:Timer>            
</ContentTemplate></asp:UpdatePanel>  </div> 
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate> 
       <asp:TextBox ID="TextBox1" runat="server" Width="148px"></asp:TextBox> 
        <asp:Button ID="BtnSend" runat="server" onclick="BtnSend_Click" Text="Send" />   </ContentTemplate>
        </asp:UpdatePanel> 

C#
protected void craetecontrols() // this function is in main page in which i am  adding    above user control
    {
        foreach (DictionaryEntry obj in arr)
        {
            Panel p1 = new Panel();
            p1.ID = "PanelChat" + obj.Key.ToString();
            ChatWindow mycontrol = (ChatWindow)LoadControl("~/ChatWindow.ascx");
            mycontrol.ID = "ChWId" + obj.Key.ToString();
            p1.Controls.Add(mycontrol);
            p1.Style.Add("position", " absolute");
            p1.Style.Add("bottom", "0");
            p1.Style.Add("right", obj.Value.ToString());
            UpdatePanel4.ContentTemplateContainer.Controls.Add(p1);
        }
    }
Posted
Updated 9-Jun-13 22:15pm
v6

1 solution

 
Share this answer
 
Comments
sunil pol 10-Jun-13 3:11am    
yes timer event is working properly..but problem occurs due to dynamic control....in postback event dynamic controls gets deleted...so i am re creating them with same id's(i persist id's in session array) and thats why focus gets distracted...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900