Reputation: 931
Ok, so I've done some searching, but I can't seem to find exactly what I'm looking for. I'm fairly new to ASP.NET, but not to C#. I had to create a page to handle a regular web services request in order to update a web store with data from a web-based accounting software service. The problem I have is that I need the page to load first, then run the update, otherwise the page times out and the update fails. The display page has only a few labels, and that's all I require on it as the page will refresh every so often and run the update. However, I need the update method to be able to put the results to the screen. I have no problem getting the update to run, just making sure the results are displayed. I have no buttons that are pressed, there are no forms used.
Here's my page code:
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
<div class="pageHeader">
<div class="caption">
<h1><asp:Localize ID="Caption" runat="server" Text="Update of Order Status From NetSuite Into AbleCommerce"></asp:Localize></h1>
</div>
</div>
<div>
<asp:Label ID="Label0" runat="server"></asp:Label>
<br /><br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br /><br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<br /><br />
<asp:Label ID="Label3" runat="server"></asp:Label>
</div>
</asp:Content>
And here is my back code:
public partial class Template_Default : CommerceBuilder.Web.UI.AbleCommercePage
{
private void PerformUpdate(object State)
{
Store _Store = StoreDataSource.Load(1);
Token.Instance.InitStoreContext(_Store);
String results = PontoonUpdate.soUpdate(); // method that performs the updates
Label3.Text = "Update Completed. " + String.Format("{0:MM-dd-yyyy hh:mm:ss}", DateTime.Now + "\n\n" + results);
}
protected void Page_Load(object sender, EventArgs e)
{
Label0.Text = "Update start time: " + String.Format("{0:MM-dd-yyyy hh:mm:ss}", DateTime.Now);
Label1.Text = "Order updates will begin.";
Label2.Text = "Processing...";
if(!Page.IsPostBack)
System.Threading.ThreadPool.QueueUserWorkItem(PerformUpdate);
}
}
I know I'm missing something, and I know it's due to my lack of experience with ASP.NET. If anyone has any pointers I'd be greatly appreciative.
Ok, I found the answer to what I wanted to do. I was searching for something else and found this...
http://www.simple-talk.com/dotnet/asp.net/implementing-waiting-pages-in-asp.net/
Upvotes: 4
Views: 2563
Reputation: 12192
wrap your controls in an UpdatePanel. It is a poor man's AJAX. Place your controls (or your entire page for that matter) into the content template. Then in the Triggers section, tell it which controls to watch, and what events to catch. It'll do the rest. In your case, from here you just need some sort of event to trigger. It could be a javascript to fire a button onLoad, or even the bind event of some other control. It doesn't really matter.
<asp:UpdatePanel runat="server" ID="update">
<ContentTemplate>
<div class="pageHeader">
<div class="caption">
<h1><asp:Localize ID="Caption" runat="server" Text="Update of Order Status From NetSuite Into AbleCommerce"></asp:Localize></h1>
</div>
</div>
<div>
<asp:Label ID="Label0" runat="server"></asp:Label>
<br /><br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br /><br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<br /><br />
<asp:Label ID="Label3" runat="server"></asp:Label>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="generate" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Upvotes: 1