Hi,
When we place the JavaScript in the Updatepanel, we will notice that any javascript elements in the html are not fired.
To work around this, we can add this JavaScript on the fly. For instance:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
string strScript = "var obj = $get('Text1');" +
" var obj1 = new Date();" +
" obj.value = obj1.toLocaleString()";
//If we don't comment this line, the date that is in the input text will not be update.
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "script", strScript, true);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:scriptmanager ID="ScriptManager1" runat="server">
</asp:scriptmanager>
</div>
<asp:updatepanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<input id="Text1" type="text" />
<asp:label ID="Label1" runat="server"></asp:label>
<script type="text/javascript">
var obj = $get('Text1');
var obj1 = new Date();
obj.value = obj1.toLocaleString();
</script>
<asp:timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick">
</asp:timer>
</contenttemplate>
</asp:updatepanel>
</form>
</body>
</html>
I look forward to hearing from you.