Thursday, March 15, 2007

ASP.NET Wishlist

Steven Smith has posted his wishlist for ASP.NET. He's in Seattle for the MVP summit. You can read about the items here: http://aspadvice.com/blogs/ssmith/archive/2007/03/14/ASP.NET-Wish-List.aspx.

I would like to focus my attention on a couple:
1) Recursive FindControl - Would be cool, but, as Steven mentions, there are a few functions out there that provide this. Nice to have, but dont compromise any other deliverables for this.

2) Cache Improvements - This is huge. I dont rely too heavily on Cache, but I do use it enough to say that companies like ScaleOut have stepped up to fill in the gaps that Microsoft has made. I would like to see two things out of Steven's list: Distributed Cache and a Cache Provider Model. I'd like to see the out of the box implementation have distributed cache mechanism, but also have the ability to throw in our own implementation of cache.

I'm really excited to see the next feature set of ASP.NET....read more!

Monday, March 5, 2007

Invoking an ajax/atlas modal dialog off a postback

Recently I was working on a scenario where I had to show an ajax/atlas modal dialog using ajax' ModalPopupExtender after some server side processing had been done. This was very hard because one of the control's required properties is the TargetControlID, which responds to a click event and throws up the modal dialog, all before the postback occurs.

I tried looking for a fancy way to be able to get this modal up and running by assiging some dummy control in the markup and calling .Show() to make the dialog show up, but that didn't yield me much.

I found a bit of a hack, which is pretty much creating a control (in my example, a label) on page_load, adding it to the UpdatePanel's ContentTemplateContainer's control collection, assign the ID of the dummy label to the ModalPopupExtender's TargetControlID property and then on a postback I could call .Show() on the MPE (ModalPopupExtender) and the dialog would show up as I needed it.

In the following example I am displaying the current timestamp on a label that is set off of a button click postback event.


default.aspx:



   1:  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

   2:  <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %> 

   3:   

   4:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

   5:  <html xmlns="http://www.w3.org/1999/xhtml">

   6:  <head runat="server">

   7:      <title>Untitled Page</title>

   8:  </head>

   9:  <body>

  10:      <form id="form1" runat="server">

  11:          <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />

  12:          <asp:UpdatePanel ID="upShowStuff" runat="Server">

  13:              <ContentTemplate>

  14:                  <asp:Button id="Button1" runat="Server" Text="Process Postback" OnClick="Button1_Click" />

  15:                  <ajax:ModalPopupExtender ID="mdePopup" runat="server" PopupControlID="pnlShowStuff" 

  16:                  OkControlID="btnOK" /> 

  17:                  <asp:Panel ID="pnlShowStuff" runat="Server" Style="display:none">

  18:                      <div style="border:solid 1px #000">

  19:                          <asp:Label ID="lblShowStuff" runat="Server" />

  20:                          <asp:Button id="btnOK" runat="Server" Text="OK" />

  21:                      </div>

  22:                  </asp:Panel>

  23:              </ContentTemplate>

  24:          </asp:UpdatePanel> 

  25:      </form>

  26:  </body>

  27:  </html>



default.aspx.cs:



   1:  public partial class _Default : System.Web.UI.Page 

   2:  {

   3:      protected void Page_Load(object sender, EventArgs e)

   4:      {

   5:          Label lbl = new Label();

   6:          lbl.ID = "tempholder";

   7:          upShowStuff.ContentTemplateContainer.Controls.Add(lbl);

   8:          mdePopup.TargetControlID = lbl.ID;

   9:      }

  10:   

  11:      protected void Button1_Click(object sender, EventArgs e)

  12:      {

  13:          lblShowStuff.Text = DateTime.Now.ToLongTimeString();

  14:          mdePopup.Show();

  15:      }

  16:  }


...read more!