I am using the following code.But whenver i open the following webpage with below code I loose focus in evry 1000 ms.can anyone help me to resolve this isse
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChatRoom.aspx.cs" Inherits="ChatApplication.ChatRoom" MaintainScrollPositionOnPostback="true" Theme="Theme1"%><!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 id="Head1" runat="server"><script type="text/javascript">
window.onload = function () {
if (document.getElementById("<%# txtMessageIsFocus.ClientID%>").value) {
document.getElementById("<%# txtMessage.ClientID%>").focus();
}
}
function NotFucus() {
document.getElementById("<%# txtMessageIsFocus.ClientID%>").value = "false";
}
function SetScrollPosition() {
var div = document.getElementById('divMessages');
div.scrollTop = div.scrollHeight;
}
function SetToEnd(txtMessage) {
if (txtMessage.createTextRange) {
var fieldRange = txtMessage.createTextRange();
fieldRange.moveStart('character', txtMessage.value.length);
fieldRange.collapse();
fieldRange.select();
}
var div = document.getElementById('divMessages');
div.scrollTop = div.scrollHeight;
document.getElementById("<%# txtMessageIsFocus.ClientID%>").value = "true";
}
function ReplaceChars() {
var txt = document.getElementById('txtMessage').value;
var out = "<"; // replace this
var add = ""; // with this
var temp = "" + txt; // temporary holder
while (temp.indexOf(out) > -1) {
pos = temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add +
temp.substring((pos + out.length), temp.length));
}
document.getElementById('txtMessage').value = temp;
}
function LogOutUser(result, context) {
// don't do anything here
}
function LogMeOut() {
LogOutUserCallBack('LogOut');
}
function FocusThisWindow(result, context) {
// don't do anything here
}
function FocusMe() {
FocusThisWindowCallBack('FocusThisWindow');
}
</script></head><body style="background-color: gainsboro;" onload="SetScrollPosition()" onunload="LogMeOut()"><form id="form1" runat="server"><div><asp:Label Id="lblRoomName" Font-Size="18px" runat="server" /><br /><br /><asp:Label Id="lblRoomId" Visible="false" runat="server" /><asp:HiddenField ID="txtMessageIsFocus" runat="server" Value="true" /><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><script type="text/javascript">
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
xPos = $get('divMessages').scrollLeft;
yPos = $get('divMessages').scrollTop;
}
function EndRequestHandler(sender, args) {$get('divMessages').scrollLeft = xPos;$get('divMessages').scrollTop = yPos;
}</script><asp:UpdatePanel Id="UpdatePanel1" runat="server" UpdateMode="Conditional"><Triggers><%-- <asp:AsyncPostBackTrigger ControlId="Timer1" />--%></Triggers><ContentTemplate><asp:Timer Id="Timer1" Interval="1000" OnTick="Timer1_OnTick" runat="server" /><table border="0" cellpadding="0" cellspacing="0"><tr><td style="width: 500px;"><div id="divMessages" style="background-color: White; border-color:Black;border-width:1px;border-style:solid;height:300px;width:592px;overflow:scroll; font-size: 11px; padding: 4px 4px 4px 4px;" onload="SetScrollPosition()"><asp:Literal Id="litMessages" runat="server" /></div></td><td> </td><td><div id="divUsers" style="background-color: White; border-color:Black;border-width:1px;border-style:solid;height:300px;width:150px;overflow:scroll; font-size: 11px; padding: 4px 4px 4px 4px;"><asp:Literal Id="litUsers" runat="server" /></div></td></tr><tr><td height="0px;"><asp:Panel Id="pnlChatNow" Visible="false" CssClass="chatNowPanel" runat="server"><div class="chatNowPanelTitle">Private Message</div><br /><asp:Label Id="lblChatNowUser" Text="MyGoodFellow" runat="server" /><br />wants to chat with you.<br /><br /><asp:Button Id="btnChatNow" Text="Chat Now" CausesValidation="false" runat="server" OnClick="BtnChatNow_Click" /><asp:Button Id="btnCancel" Text="Cancel" CausesValidation="false" runat="server" OnClick="BtnCancel_Click" /></asp:Panel> </td><td colspan="2"></td></tr><tr><td colspan="3"><asp:TextBox Id="txtMessage" onkeyup="ReplaceChars()" runat="server"
Width="340px" onclick="FocusMe()"
onfocus="SetToEnd(this)" onblur="NotFucus()" /><asp:Button Id="btnSend" runat="server" Text="Send" OnClientClick="SetScrollPosition()" OnClick="BtnSend_Click" /></td></tr></table> </ContentTemplate></asp:UpdatePanel> </div></form></body></html>