I want to showcase an ASP.NET page featuring 4 update panels and data refreshing upon button click for the first time. Below are my inquiries:
- How can I load the page content first and then the data? I prefer not to include data load methods in the page load.
- Is there a way to refresh the page/update panel from the code behind? (I tried calling the __doPostBack event or JavaScript from the code behind, but it didn't work)
Thank you for your assistance
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<button id="btnCrashRefresh" onserverclick="btnCrashRefresh_ServerClick" type="submit" runat="server" class="btn btn-default pull-right" style="padding-top: 0px;padding-bottom: 0px;">
<span class="glyphicon glyphicon-refresh"></span>
</button>
<asp:Label ID="Label1" class="label-info pull-right" runat="server" Text="<DateTime>" ></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Code Behind
System.Timers.Timer myTimer = new System.Timers.Timer();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetInitialValues();
btnCrashRefresh.ServerClick += new EventHandler(btnCrashRefresh_ServerClick);
myTimer.Interval = 2000;
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
myTimer.Start();
}
}
void myTimer_Elapsed(object sender, ElapsedEventArgs e)
{
string script = "DoPostback();";
ScriptManager.RegisterStartupScript(btnCrashRefresh, this.GetType(), "Refresh", getjQueryCode(script), true);
}
Javascript
function DoPostback() {
__doPostBack('<%=btnCrashRefresh %>');
}