Neopets alum will appreciate the title, everyone else, not so much. Anyway, let's just say you want to alert someone of some thing, some event or happening. It could happen within Page_Init, Page_Load, or some custom function you wrote, such as MyFatButton_Click(). This is all asp.net, in case there was any doubt.
In my situation, I'm working in an order entry system where people first add items, and later in the process, add payments of check, credit card, etc. There is nothing that prevents them from going back several steps and removing items after payments are applied (but not submitted yet). This results in a negative order balance which is generally undesirable, as we do not want to owe people money or have to refund money.
The fix was to simply remove payments on a negative order balance. This was regarded as acceptable by the client, and if it's good with them, it's good with me. But they also wanted to let the user know that something has happened, e.g., their payment was removed. Here's the code for that:
(inside page_init, page_load would have worked fine as well, as far as I know):
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "alertPaymentRemoved", string.Format("alert ('The payment(s) for this order have been removed.');"), true);
Some explanation might be helpful here. The ScriptManager allows you to inject some javascript at the time where it is useful to do so. The first argument, this, is a reference to the aspx page. Let me know if you have any questions.
Wednesday, April 29, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment