This is my script:
<script type="text/javascript">
$(document).ready(
function (){
setTimeout('myFun()', 10000);
});
function myFun() {
var btn = document.getElementById('<%=myBtn.ClientID %>');
alert(btn);
btn.click();
}
</script>
My markup:
<asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblValue" runat="server" Text=""></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="myBtn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="myBtn" runat="server" Text="hit" />
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblValue.Text = "0";
}
else
{
lblValue.Text = Convert.ToString(Convert.ToInt32(lblValue.Text) + 1);
}
}
I need to refresh the updatepanel after every 10 seconds. But after page load, only once I’m able to achieve that. Is there anything I’m missing? Thanks.
why don’t you use the AJAX Timer control instead. It’ll serve the same purpose in a neat, concise & efficient manner.
Anyways,
Both setTimeout() & setInterval() work the same way.
The key difference is that:
In brief, setTimeout() runs the supplied code only once after the specified interval, whereas setInterval() runs the code again & again after the specified interval.
So use:
Source: jQuery – Novice to Ninja