Wednesday, September 17, 2008

Conditional ModalPopupExtender as UpdateProgress control

I'm a big fan of Matt Berseth's blog and his articles are some of the most clear, concise ones out there when dealing with UI elements and webcontrols for ASP.NET.   I've happily employed his ModalPopup as an AJAX Progress Indicator example in a project I'm working on but ran into a small hitch.

Matt's Indicator envelops the beauty of simplicity in that it simply calls the ModalPopupExtender's show() and hide() events when the page's requestmanager receives a request from the Scriptmanager.

One of my pages contains a fairly dense GridView which reflects data that's changed quite often.  As such, I've encapsulated this GridView in an UpdatePanel control and added a Timer control to it with a tick of 20000.   I wanted to show the Modal Progress Indicator when users changed filtering options (controls) for this Gridview but didn't want it to show on postback from the Timer.  After a bit of searching it was as simple as pulling the name of the control that triggered the async call and managing the reaction.

 

<form id="form1" runat="server">
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<script type="text/javascript" language="javascript">
// register for our events
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
function beginRequest(sender, args)
{
if(args.get_postBackElement().id.toString() != 'NameOfMyTimerControl')
{
// show the popup
$find('NameOfMyPopupExtender').show();
}
}
function endRequest(sender, args)
{
// hide the popup
$find('NameOfMyPopupExtender').hide();
}
</script>


Now my Progress Indicator only shows when users interact with the page and NOT when the timer refreshes the data.


Day 1

Cowboy coding time!

I've created this stop as a repository for shitty code-snippets, excuses for not doing things the "RIGHT" way and overall generalizations of lack-of-technique or foundation when it comes to C#, ASP.NET, AJAX or ADO.NET.

How often do you coders out there - looking for examples of functions or methods which achieve a seemingly simple task - wind up creating your own solution but often wondering if anyone else would benefit? I've lost count of the times but finally decided to do something about it. Sure - some of my examples or codings will contain errors or flaws. Sure they might be downright unintelligible. As long as it works and allows me to continue on a task or project, I'm good with it.

Let the games begin...

Being a programmer and web-developer for close to 15 years now, I've gone through various languages, tools and methodologies.

I've always been one who can get a job or task done in a short amount of time. Lots of that can be attributed to the lack of any disciplined coding or development.
A former co-worker of mine had the fortune of having to maintain an app that I had written. In referring to it on his own blog he coined what he had to work with as "cowboy code", thus the name of my blog.
I'm proud to say I'm a cowboy-coder. One who ignores best-method approaches to coding. One who doesn't care a lick about paired-programming, scrum sessions or TDD. I work from the top - down. I use session variables. I don't comment my code. I hate creating views and love using #temp tables!
Yeah...I'm that guy