May 23 2008

ASP.NET and Password TextBox with initial value

Tag: ASP.NETTyrone @ 8:54 am

Some asked me a question the other day about an issue they were experiencing with pre-loading a password text box with some initial text. Here is what their code looked like:

ASPX

<asp:TextBox id="txtPassword" runat="server" TextMode="Password" />

 

Code-Behind

txtPassword.Text = "mypassword";

 

But, when the page loaded, there was no value contained in the password text box. So, what’s the issue? Apparently, this is a restriction that the ASP.NET developers thought that should be in place due to security reasons. However, a workaround for this is to add the value to the attributes collection of the web server control:

txtPassword.Attributes.Add("value", "mypassword");

 

Doing this would cause the Value attribute of the <input type="password"> HTML control to be populated. So, here is what will be sent to the browser for rendering:

<input type="password" id="txtPassword" name="txtPassword" value="mypassword" />

 

It should be noted that even though the value of the password will be masked in the browser, the value will show up in clear text if you view the page source. So, if this is not the behavior you would like to have, then this is not the solution for you. Hopefully, this was of some help to you.

Until next time…

 

Happy Coding!

 


Jan 09 2008

Strongly-Typed Session Properties in ASP.NET

Tag: .NET Framework, ASP.NETTyrone @ 10:02 pm

I recently was given the opportunity to comment on a blog post which discussed a method of using Strongly-Types Session Properties with ASP.NET. After reading it, I noticed that the implementation was quite similar to something I have been using for months now. I was able to provide some feedback on how his implementation differed from mine. Anyway’s, the link below will take you to the blog post which I am referring to and you could decide for yourself.

UPDATE: 1/11/2008

For those who would like to see my implementation here it is:

   1:  using System;
   2:   
   3:  using System.Web;
   4:   
   5:  [Serializable]
   6:   
   7:  public sealed class SessionManager {
   8:   
   9:     private const string SESSION_MANAGER = “SESSION_MANAGER”;
  10:   
  11:     private Product _product = null;
  12:   
  13:     private SessionManager( ) {
  14:   
  15:     }
  16:   
  17:     public static SessionManager Current {
  18:   
  19:         get {
  20:   
  21:             HttpContext context = HttpContext.Current;
  22:   
  23:             SessionManager manager =
  24:   
  25:                 context.Session[ SESSION_MANAGER ] as SessionManager;
  26:   
  27:             if ( manager == null ) {
  28:   
  29:                 manager = new SessionManager( );
  30:   
  31:                 context.Session[ SESSION_MANAGER ] = manager;
  32:   
  33:             }
  34:   
  35:             return manager;
  36:   
  37:         }
  38:   
  39:     }
  40:   
  41:     public Product ActiveProduct {
  42:   
  43:         get {
  44:   
  45:             return this._product;
  46:   
  47:         }
  48:   
  49:         set {
  50:   
  51:             this._product = value;
  52:   
  53:         }
  54:   
  55:     }
  56:   
  57:  }
  58:   
  59:  //And to access this property
  60:  SessionManager.Current.ActiveProduct = new Product();

 

If you would like to see what others have implemented, see the article below:

Strongly-Typed Session in ASP.NET - Chris Stewart’s ASP.NET Blog

Until next time…

 

Happy Coding!

 

kick it on DotNetKicks.com


Nov 16 2007

.NET and the Provider Model

Tag: .NET Framework, ASP.NETTyrone @ 11:42 pm

If you have been using the new features of the ASP.NET 2.0 web framework like Membership, Roles, SiteMap, Profiles and others, you have probably heard about the Provider Model. If not, have no fear, you have been using it all along.  The Provider Model is a set of API’s that were build into the .NET 2.0 Framework that gives both windows and web developers the ability to build applications that allow certain features/functionality to be replaced, at runtime, via the application’s configuration file.  The only requirement is that the new feature must implement all of the interfaces of the feature being replaced.  This is all done through a set of abstract classes.

Without going through much detail, Miguel Castro was a guest on DnrTV and he really goes into detail on a real word example ( Credit Card Processing ) on how you would use the Provider Model for this senario.  This was a really great show and it’s the real reason why I was encouraged to blog about this.

Happy Coding!

 

 

kick it on DotNetKicks.com