Showing posts from August, 2008

Role Enabled Custom Controls

So we did all this work to a membership provider and a role provider for ASP.NET and it was a lesson in patients as we figured out how it was all suppose to work.  However, now we have it I found out that the ASP.NET controls are not enabled for roles.  It works well with our Forms authentication for blocking access to pages where the user doesn't have the right role.  However, I want to display controls and not display controls based on the user's role.  I love to create custom controls that work just like we want them to work.  So I subclassed the Panel control and "roles" enabled it.  Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebUtility { [DefaultProperty( "Text" )] [ToolboxData( "<{0}:RolePanel runat=server></{0}:RolePanel>" )] public class RolePanel : Panel {

Dynamic Javascript in an Update Panel - A Better Way

Last post was about how dynamic javascript in the update panel was not being re-executed on a partial postback.  I have a better way of making it execute -- parse the controls in the UpdatePanel and call the javascript method eval(). Here is the hook: Page.ClientScript.RegisterStartupScript( this .GetType(), "LoadHandler" , "function LoadHandler(){EvalScript($get('" + updatePanel.ClientID + "'),'scriptId');};\r\n" , true ); Page.ClientScript.RegisterStartupScript( this .GetType(), "AddLoadHandler" , "Sys.Application.add_load(LoadHandler);\r\n" , true ); EvalScript looks like this: function EvalScript(control, id) {  if(!control){return;}  for(var n=0;n<control.children.length;n++)  {      if((control.children[n].tagName == 'SCRIPT') && (control.children[n].id == id)){          var scriptElement = control.removeChild(control.children[n]);          eval(scriptElement.innerHTML);      }else{        

Dynamic Javascript in an Update Panel

If you are using an Ajax UpdatePanel in ASP.NET and you have a control that renders javascript, that javascript will not change when on a partial postback.  For example, I have a Repeater control that loops though so GEO points and outputs javascript to add PushPin to a Virtual Earth map.  If a partial postback is called, and the Repeater rebinds it recreates the javascript, however on the client side the ScriptManager just replaces the UpdatePanel innerHTML with then new code.  It doesn't tell the javascript engine to reparse that code and recreate the functions that are being replaced.  To solve this problem I had to write some javascript client code that would parse the return, and move my <SCRIPT> tags to the head of the page.  This "woke up" the javascript engine and the new functions where recompiled. How to hook it up: 1) The first thing to do is to tell the ScriptManager to parse the innerHTML of the UpdatePanel and move all script blocks to the head of th

I am back...

I took off 4 months to remodel my kitchen, in that time I did no programming.  Now I am back to work for at least a week now.  I havn't forgotten anything (except for the SQL Server sa password -- which means that it is a good one.)  I can program just as well as before I left.  {6230289B-5BEE-409e-932A-2F01FA407A92}

DAL using subsonic

I was investigating a starter website and noticed that it mentioned subsonic . Since third-party components can be tricky for implementation and security, I went to see what it was. Subsonic is an open source Data Access Layer. Someone has probably mentioned it to me before but it didn't register. The website has videos using subsonic which are great. Subsonic connects to the database and creates a DAL for a .Net project which uses intellisense for discovery. The only thing that worries me is that the connection isn't through SPs they create but they say they parse the SQL commands so that SQL injection isn't a problem. I also watched another video of theirs about their REST handler on their tips and tricks page . While I still like .NetTiers for my DAL (which requires a purchase of CodeSmith ), I liked the easy of use and the fact that CodeSmith is not required. Just as I was grumbling to myself about a startersite for this, I found the link on the front page of their si