<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PeterKellner.net &#187; Membership</title>
	<atom:link href="http://peterkellner.net/category/membership/feed/" rel="self" type="application/rss+xml" />
	<link>http://peterkellner.net</link>
	<description>Microsoft Focussed, JavaScript (ExtJS, SenchaTouch &#38; Windows 8 Metro)</description>
	<lastBuildDate>Fri, 03 Feb 2012 02:58:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Speaking Wednesday May 20th, 6:30PM, Microsoft Office San Francisco on ExtJS and ASP.NET Membership!</title>
		<link>http://peterkellner.net/2009/04/20/speaking-aspnet-extjs-microsoft-sanfrancisco-high-perf-javascript/</link>
		<comments>http://peterkellner.net/2009/04/20/speaking-aspnet-extjs-microsoft-sanfrancisco-high-perf-javascript/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 04:59:38 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Membership]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/04/20/speaking-aspnet-extjs-microsoft-sanfrancisco-high-perf-javascript/</guid>
		<description><![CDATA[&#160;  Come hear about how to see ExtJS integrated with ASP.NET for awesome Membership and Profile Management!&#160; I will speaking at the Microsoft Office at a meeting of Bay.Net Users Group.  http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=378&#38;mid=49  ASP.NET: Membership with Profile and High Performance ExtJS JavaScript Interface  When:&#160;   Wednesday, 5/20/2009 at 6:30 PM  [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>  <p>Come hear about how to see <a href="http://extjs.com/">ExtJS</a> integrated with <a href="http://asp.net">ASP.NET</a> for awesome Membership and Profile Management!&#160; I will speaking at the <a href="http://www.microsoft.com/en/us/default.aspx">Microsoft</a> Office at a meeting of <a href="http://www.baynetug.org/DesktopDefault.aspx">Bay.Net Users Group</a>.</p>  <p><a title="http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=378&amp;mid=49" href="http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=378&amp;mid=49">http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=378&amp;mid=49</a></p>  <p>ASP.NET: Membership with Profile and High Performance <a href="http://extjs.com/">ExtJS</a> JavaScript Interface</p>  <h3>When:&#160; </h3>  <p>Wednesday, 5/20/2009 at 6:30 PM</p>  <h3>Where:&#160; </h3>  <p><strong>Microsoft Office, 835 Market Street, Suite 700, San Francisco</strong></p>  <h3>Event Description</h3>  <p><em>In this session, we will demonstrate building a super rich JavaScript interface to the standard ASP.NET Membership and Profile services. That is, built into ASP.NET are wonderful providers that allow you to validate and store user credentials typically to a database. It also lets you store other information such as pictures, first and last names, as well as anything else you may want to store. In this session we will build a highly performing, 100% JavaScript UI to maintain hundreds of thousands of users. As part of this solution, techniques for using REST based services to access this information will be presented. Once you see this, it will be hard to ever use web forms again.</em></p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/04/20/speaking-aspnet-extjs-microsoft-sanfrancisco-high-perf-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Set the Default Value of a DropDownList in an ASP.NET Page</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/</link>
		<comments>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comments</comments>
		<pubDate>Wed, 17 Oct 2007 17:44:13 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/</guid>
		<description><![CDATA[<p> This article shows how to set the default Value of a DropDownList Control when using asp.net 2.0.  It uses the DataBound event to do it.  A full page example which can be cut and paste is included</p>]]></description>
			<content:encoded><![CDATA[<h2>(Using Membership ObjectDataSource From MSDN Article)</h2>  <p>I&#8217;m doing a project where I have lots of DropDownList&#8217;s on a page and want a simple way to set the initial values based on some known value.&#160; The DropDownLists are retrieved using ObjectDataSource but I don&#8217;t want the first value displayed.&#160; I wrestled some with how to do this using page_load or page_prerender but didn&#8217;t come up with good solutions.&#160; I did finally    <br />decide that programming the databound event of the dropdownlist was probably the best way to go. </p>  <p>The solution is pasted below.&#160; The MembershipUtilities.MembershipODS c# code can be downloaded from MSDN or on my web site at the following location.&#160; <br /></p> <span id="more-80"></span>  <p><a href="/2006/01/09/microsoft-aspnet-20-memberrole-management-with-iis/">http://peterkellner.net/2006/01/09/microsoft-aspnet-20-memberrole-management-with-iis/</a>.</p> <!-- code formatted by http://manoli.net/csharpformat/ --><style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style>  <pre class="csharpcode"><span class="asp">&lt;%@ Page Language=”C#” %&gt;</span>
<span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> “<span class="attr">-</span>//<span class="attr">W3C</span>//<span class="attr">DTD</span> <span class="attr">XHTML</span> <span class="attr">1</span>.<span class="attr">0</span> <span class="attr">Transitional</span>//<span class="attr">EN</span>”

  “<span class="attr">http:</span>//<span class="attr">www</span>.<span class="attr">w3</span>.<span class="attr">org</span>/<span class="attr">TR</span>/<span class="attr">xhtml1</span>/<span class="attr">DTD</span>/<span class="attr">xhtml1-transitional</span>.<span class="attr">dtd</span>”<span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>
    <span class="kwrd">protected</span> <span class="kwrd">void</span> DropDownListUser_DataBound(<span class="kwrd">object</span> sender, EventArgs e)

    {
        DropDownListUser.SelectedIndex =
          DropDownListUser.Items.IndexOf
          (DropDownListUser.Items.FindByValue(Context.User.Identity.Name));
    }
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>
 
<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span>=”<span class="attr">http:</span>//<span class="attr">www</span>.<span class="attr">w3</span>.<span class="attr">org</span>/<span class="attr">1999</span>/<span class="attr">xhtml</span>” <span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>DropDownList Initialize<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span>=”<span class="attr">form1</span>″ <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp:DropDownList</span> <span class="attr">ID</span>=”<span class="attr">DropDownListUser</span>” <span class="attr">runat</span>=”<span class="attr">server</span>”
          <span class="attr">DataSourceID</span>=”<span class="attr">ObjectDataSourceUser</span>”
          <span class="attr">DataTextField</span>=”<span class="attr">UserName</span>” <span class="attr">DataValueField</span>=”<span class="attr">UserName</span>”
          <span class="attr">OnDataBound</span>=”<span class="attr">DropDownListUser_DataBound</span>”<span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">asp:DropDownList</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp:ObjectDataSource</span> <span class="attr">ID</span>=”<span class="attr">ObjectDataSourceUser</span>” <span class="attr">runat</span>=”<span class="attr">server</span>”
          <span class="attr">SelectMethod</span>=”<span class="attr">GetMembers</span>”
          <span class="attr">TypeName</span>=”<span class="attr">MembershipUtilities</span>.<span class="attr">MembershipUserODS</span>”<span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">SelectParameters</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>=”<span class="attr">sortData</span>” <span class="attr">Type</span>=”<span class="attr">String</span>” <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">SelectParameters</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">asp:ObjectDataSource</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Resetting Password with ASP.NET 2.0 Membership and Multiple Providers</title>
		<link>http://peterkellner.net/2007/02/15/resetpasswordaspnet/</link>
		<comments>http://peterkellner.net/2007/02/15/resetpasswordaspnet/#comments</comments>
		<pubDate>Thu, 15 Feb 2007 15:39:16 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/02/15/resetpasswordaspnet/</guid>
		<description><![CDATA[If you ever have wanted to be able to programmatically change (reset) a users
password while at the same time continuing to be able to use the question and
answer feature, this post is for you.]]></description>
			<content:encoded><![CDATA[<style type="text/css">



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style><meta content="text/html; charset=utf-8" http-equiv="Content-Type" />  <p>If you ever have wanted to be able to programmatically change (reset) a users&#160; password while at the same time continuing to be able to use the question and answer feature, this post is for you.&#160; The problem is that if you use code like this:</p> <style type="text/css">



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style>  <pre class="csharpcode"> <span class="kwrd">string</span> username = <span class="str">&quot;user&quot;</span>;
 <span class="kwrd">string</span> password = <span class="str">&quot;pass@word&quot;</span>;
 MembershipUser mu = Membership.GetUser(username);
 mu.ChangePassword(mu.ResetPassword(), password);</pre>

<p>You will find that if you have in your web.config requiresQuestionAnswer=&quot;true&quot;, you will get an error when you try and reset the password.&#160; The elegant solution to this is to create an additional membeship tag in your web.config and reference it when you change passwords.&#160; That is, add another provider like this:</p>
<span id="more-52"></span>

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">membership</span> <span class="attr">defaultProvider</span><span class="kwrd">=&quot;SqlMembershipProvider&quot;</span> <span class="attr">userIsOnlineTimeWindow</span><span class="kwrd">=&quot;15&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">providers</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">clear</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;SqlMembershipProviderOther&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;SqlProviderOneShot.SqlMembershipProvider&quot;</span>
    <span class="attr">requiresQuestionAndAnswer</span><span class="kwrd">=&quot;false&quot;</span>
     <span class="attr">connectionStringName</span><span class="kwrd">=&quot;EmailEmailConnectionString&quot;</span> <span class="attr">applicationName</span><span class="kwrd">=&quot;EmailEmail&quot;</span>
    <span class="attr">enablePasswordRetrieval</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">enablePasswordReset</span><span class="kwrd">=&quot;true&quot;</span>
    <span class="attr">requiresUniqueEmail</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">passwordFormat</span><span class="kwrd">=&quot;Hashed&quot;</span>
    <span class="attr">minRequiredNonalphanumericCharacters</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">writeExceptionsToEventLog</span><span class="kwrd">=&quot;false&quot;</span>
    <span class="attr">minRequiredPasswordLength</span><span class="kwrd">=&quot;1&quot;</span> <span class="attr">passwordStrengthRegularExpression</span><span class="kwrd">=&quot;&quot;</span>
    <span class="attr">passwordAttemptWindow</span><span class="kwrd">=&quot;10&quot;</span> <span class="attr">maxInvalidPasswordAttempts</span><span class="kwrd">=&quot;8&quot;</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">providers</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">membership</span><span class="kwrd">&gt;</span></pre>

<p>Then, when you change your password, reference it as follows:</p>
<!-- code formatted by http://manoli.net/csharpformat/ --><style type="text/css">



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style>

<pre class="csharpcode"><span class="kwrd">string</span> username = <span class="str">&quot;user&quot;</span>;
<span class="kwrd">string</span> password = <span class="str">&quot;pass@word&quot;</span>;
MembershipUser mu = Membership.Providers[<span class="str">&quot;SqlMembershipProviderOther&quot;</span>].GetUser(username);
mu.ChangePassword(mu.ResetPassword(), password);</pre>

<p>Hope this helps! At some point, I will integrate this functionality into my ObjectDataSource article that lets you display your membership information with a gridview or detailsview.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/02/15/resetpasswordaspnet/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Have GridView Highlight Last Inserted Record in ASP.NET 2.0</title>
		<link>http://peterkellner.net/2006/12/07/gridviewhighlightlastinsertedrow/</link>
		<comments>http://peterkellner.net/2006/12/07/gridviewhighlightlastinsertedrow/#comments</comments>
		<pubDate>Thu, 07 Dec 2006 23:41:04 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2006/12/07/gridviewhighlightlastinsertedrow/</guid>
		<description><![CDATA[A question that frequently comes up in the asp.net forums is how to have a gridview show the the last record added highlighted. This articles gives a technique for doing this. It only works with SqlServer but could could be modified for other databases.]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>  <p>A question that frequently comes up in the asp.net forums is how to have a gridview show the the last record added highlighted. This articles gives a technique for doing this. It only works with SqlServer but could could be modified for other databases. </p>  <h2>What It Looks Like Running</h2>  <p>After pressing the insert button on the screen shot below, the bottom line was actually added and it is automatically highlighted. This is in a nutshell, what the code listed below and this article discusses.</p> <span id="more-43"></span>  <p><img src="http://peterkellner.net/wp/Images/misc/GridViewInsertHighlight.jpg" width="409" height="625" /></p>  <h2>The Code</h2>  <p>In order to run the code below, you must first set up Membership. The simplest way to do this is to simply add to your web.config a very small section enabling RoleManager. This will automatically create the membership database in sqlexpress. You should probably add a couple users just so your gridview is not empty from the start. The code you need to add to an empty asp.net 2.0 web site project is as follows (put it in the &lt;System.Web&gt; section).</p>  <div style="font-family: courier new; background: white; color: black; font-size: 10pt">   <p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">roleManager</span><span style="color: blue"> </span><span style="color: red">enabled</span><span style="color: blue">=</span>&quot;<span style="color: blue">true</span>&quot;<span style="color: blue">&gt;&lt;/</span><span style="color: #a31515">roleManager</span><span style="color: blue">&gt;</span> </p> </div>  <p>Once you have done that, you can copy the code below to a new web page and simply run it.</p>  <p>Briefly, the way the code works is that when a row is inserted into the database the sqldatasource&#8217;s Inserted event is called. In this event, we take a look at the return parameter which comes from the sql:</p>  <div style="font-family: courier new; background: white; color: black; font-size: 10pt">   <p style="margin: 0px"><span style="color: red">InsertCommand</span><span style="color: blue">=&quot;INSERT INTO [Names] ([name]) VALUES (@name);SELECT @NewID = Scope_Identity()&quot;</span></p> </div>  <p>NewId is actually a return parameter, so we can get that back in the inserted event. Once we get the value back, we store it in viewstate so that on the upcoming page_prerender, we can check and see which row has that id in it, and then highlight that row. The reason we do it in prerender and not load is because the inserted event is processed after load and it would not work if we put it there.</p>  <p>So, here is the code! Good luck.</p> <style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style>  <pre class="csharpcode"><span class="asp">&lt;%@ Page Language=”C#” %&gt;</span>

<span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> “<span class="attr">-</span>//<span class="attr">W3C</span>//<span class="attr">DTD</span> <span class="attr">XHTML</span> <span class="attr">1</span>.<span class="attr">0</span> <span class="attr">Transitional</span>//<span class="attr">EN</span>” “<span class="attr">http:</span>//<span class="attr">www</span>.<span class="attr">w3</span>.<span class="attr">org</span>/<span class="attr">TR</span>/<span class="attr">xhtml1</span>/<span class="attr">DTD</span>/<span class="attr">xhtml1-transitional</span>.<span class="attr">dtd</span>”<span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>

    <span class="rem">// simple table named: Names. Two columns:  id int, name varchar(64)</span>

    <span class="kwrd">protected</span> <span class="kwrd">void</span> ButtonInsert_Click(<span class="kwrd">object</span> sender, EventArgs e)
    {      
        SqlDataSource1.InsertParameters[<span class="str">&quot;name&quot;</span>].DefaultValue = DateTime.Now.ToString();
        <span class="kwrd">int</span> numInserted = SqlDataSource1.Insert();
        GridView1.DataBind();
    }

    <span class="kwrd">protected</span> <span class="kwrd">void</span> SqlDataSource1_Inserted(<span class="kwrd">object</span> sender, SqlDataSourceStatusEventArgs e)
    {
        <span class="kwrd">object</span> newId = e.Command.Parameters[<span class="str">&quot;@NewId&quot;</span>].Value;
        ViewState[<span class="str">&quot;NewId&quot;</span>] = Convert.ToInt32(newId);
    }

    <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_PreRender(<span class="kwrd">object</span> sender, EventArgs e)
    {
        <span class="kwrd">string</span> newIdLast = <span class="kwrd">string</span>.Empty;
        <span class="kwrd">if</span> (ViewState[<span class="str">&quot;NewId&quot;</span>] != <span class="kwrd">null</span>)
        {
            <span class="kwrd">int</span> newId = (<span class="kwrd">int</span>)ViewState[<span class="str">&quot;NewId&quot;</span>];
            newIdLast = newId.ToString();
            <span class="kwrd">int</span> rowCnt = 0;
            <span class="kwrd">foreach</span> (GridViewRow row <span class="kwrd">in</span> GridView1.Rows)
            {
               <span class="kwrd">string</span> newIdText = row.Cells[1].Text;
                <span class="kwrd">if</span> (newIdText.Equals(newIdLast))
                {
                    <span class="rem">//GridView1.EditIndex = rowCnt;</span>
                    <span class="rem">//GridView1.SelectedIndex = rowCnt;</span>
                    row.Attributes.Add(“bgcolor”, “Gray”);
                    <span class="kwrd">break</span>;
                }
                rowCnt++;
            }
        }
    }
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span>=”<span class="attr">http:</span>//<span class="attr">www</span>.<span class="attr">w3</span>.<span class="attr">org</span>/<span class="attr">1999</span>/<span class="attr">xhtml</span>” <span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">id</span>=”<span class="attr">Head1</span>? <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>Untitled Page<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span>=”<span class="attr">form1</span>? <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">h2</span><span class="kwrd">&gt;</span>Example of GridView that shows highlighted last inserted row<span class="kwrd">&lt;/</span><span class="html">h2</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">br</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp:GridView</span> <span class="attr">ID</span>=”<span class="attr">GridView1</span>? <span class="attr">runat</span>=”<span class="attr">server</span>” <span class="attr">AutoGenerateColumns</span>=”<span class="attr">False</span>” <span class="attr">DataKeyNames</span>=”<span class="attr">id</span>” <span class="attr">DataSourceID</span>=”<span class="attr">SqlDataSource1</span>? <span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Columns</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:CommandField</span> <span class="attr">ShowEditButton</span>=”<span class="attr">True</span>” <span class="attr">ShowDeleteButton</span>=”<span class="attr">True</span>” <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span>=”<span class="attr">id</span>” <span class="attr">HeaderText</span>=”<span class="attr">id</span>” <span class="attr">InsertVisible</span>=”<span class="attr">False</span>” <span class="attr">ReadOnly</span>=”<span class="attr">True</span>”
                    <span class="attr">SortExpression</span>=”<span class="attr">id</span>” <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span>=”<span class="attr">name</span>” <span class="attr">HeaderText</span>=”<span class="attr">name</span>” <span class="attr">SortExpression</span>=”<span class="attr">name</span>” <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Columns</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">asp:GridView</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp:SqlDataSource</span> <span class="attr">ID</span>=”<span class="attr">SqlDataSource1</span>? <span class="attr">runat</span>=”<span class="attr">server</span>” <span class="attr">ConnectionString</span>=”&amp;<span class="attr">lt</span>;%$ <span class="attr">ConnectionStrings:ConnectionString</span> %&amp;<span class="attr">gt</span>;“
          <span class="attr">DeleteCommand</span>=”<span class="attr">DELETE</span> <span class="attr">FROM</span> [<span class="attr">Names</span>] <span class="attr">WHERE</span> [<span class="attr">id</span>] = @<span class="attr">id</span>”
          <span class="attr">InsertCommand</span>=”<span class="attr">INSERT</span> <span class="attr">INTO</span> [<span class="attr">Names</span>] ([<span class="attr">name</span>]) <span class="attr">VALUES</span> (@<span class="attr">name</span>);<span class="attr">SELECT</span> @<span class="attr">NewID</span> = <span class="attr">Scope_Identity</span>()”

          <span class="attr">SelectCommand</span>=”<span class="attr">SELECT</span> [<span class="attr">id</span>], [<span class="attr">name</span>] <span class="attr">FROM</span> [<span class="attr">Names</span>]“ <span class="attr">UpdateCommand</span>=”<span class="attr">UPDATE</span> [<span class="attr">Names</span>] <span class="attr">SET</span> [<span class="attr">name</span>] = @<span class="attr">name</span> <span class="attr">WHERE</span> [<span class="attr">id</span>] = @<span class="attr">id</span>” <span class="attr">OnInserted</span>=”<span class="attr">SqlDataSource1_Inserted</span>”<span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">DeleteParameters</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>=”<span class="attr">id</span>” <span class="attr">Type</span>=”<span class="attr">Int32</span>? <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">DeleteParameters</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">UpdateParameters</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>=”<span class="attr">name</span>” <span class="attr">Type</span>=”<span class="attr">String</span>” <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>=”<span class="attr">id</span>” <span class="attr">Type</span>=”<span class="attr">Int32</span>? <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">UpdateParameters</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">InsertParameters</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>=”<span class="attr">name</span>” <span class="attr">Type</span>=”<span class="attr">String</span>” <span class="kwrd">/&gt;</span>
               <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Direction</span>=<span class="attr">Output</span> <span class="attr">Name</span>=”<span class="attr">NewId</span>” <span class="attr">Size</span>=<span class="attr">4</span> <span class="attr">Type</span>=<span class="attr">Int16</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">InsertParameters</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">asp:SqlDataSource</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">br</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">br</span> <span class="kwrd">/&gt;</span>
        <span class="attr">&amp;nbsp;</span><span class="kwrd">&lt;</span><span class="html">asp:Button</span> <span class="attr">ID</span>=”<span class="attr">ButtonInsert</span>” <span class="attr">runat</span>=”<span class="attr">server</span>” <span class="attr">OnClick</span>=”<span class="attr">ButtonInsert_Click</span>” <span class="attr">Text</span>=”<span class="attr">Insert</span> <span class="attr">Record</span>” <span class="kwrd">/&gt;&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>

<h2>About the Author </h2>

<p>Peter Kellner currently works as an asp.net enterprise consultant at <a href="http://www.73rdstreet.com">http://www.73rdstreet.com</a>. During the past year, Peter Kellner has authored four MSDN articles dealing with Membership and Profiles. He maintains a blog with more articles at <a href="http://peterkellner.net">http://peterkellner.net</a>. </p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/12/07/gridviewhighlightlastinsertedrow/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Moving From Casini to IIS, Login Fails. How come?</title>
		<link>http://peterkellner.net/2006/10/20/loginfailswithiisnotcasini/</link>
		<comments>http://peterkellner.net/2006/10/20/loginfailswithiisnotcasini/#comments</comments>
		<pubDate>Fri, 20 Oct 2006 17:33:09 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2006/10/20/moving-from-casini-to-iis-login-fails-how-come/</guid>
		<description><![CDATA[What to do when an web application you wrote worked fine in developement (VS2005) but when you move it to IIS, you can no longer login using the Membership Provider you configured under development.]]></description>
			<content:encoded><![CDATA[<h2>ASP.NET 2.0 Membership</h2>  <p>A very common question that comes up while using ASP.NET 2.0 Membership is that when moving a web application from the local developer environment with Visual Studio 2005 (VS2005) to IIS is that login no longer works. Almost everytime this happens, it comes down to the application name in the Membership Profile of Web.Config is set to / instead of the actual application name. That is, if you you were to look at your web.config, this is what you would see.</p> <span id="more-38"></span>  <br /> <div class="csharpcode"> <pre class="alt"><span class="kwrd">&lt;</span><span class="html">roleManager</span> <span class="attr">enabled</span>=“<span class="attr">true</span>“<span class="kwrd">/&gt;</span></pre>
<pre>     <span class="kwrd">&lt;</span><span class="html">membership</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">          <span class="kwrd">&lt;</span><span class="html">providers</span><span class="kwrd">&gt;</span></pre>
<pre>          <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span>=“<span class="attr">AspNetSqlMembershipProvider</span>“<span class="kwrd">/&gt;</span></pre>
<pre class="alt">          <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span>=“<span class="attr">AspNetSqlMembershipProvider</span>“</pre>
<pre>               <span class="attr">type</span>=“…“</pre>
<pre class="alt">               <span class="attr">connectionStringName</span>=“<span class="attr">LocalSqlServer</span>“</pre>
<pre>               <span class="attr">enablePasswordRetrieval</span>=“<span class="attr">false</span>“</pre>
<pre class="alt">               <span class="attr">enablePasswordReset</span>=“<span class="attr">true</span>“</pre>
<pre>               <span class="attr">requiresQuestionAndAnswer</span>=“<span class="attr">true</span>“</pre>
<pre class="alt">               <span class="attr">applicationName</span>=“/“</pre>
<pre>               <span class="attr">requiresUniqueEmail</span>=“<span class="attr">false</span>“</pre>
<pre class="alt">               <span class="attr">minRequiredPasswordLength</span>=“<span class="attr">1</span>“</pre>
<pre>               <span class="attr">minRequiredNonalphanumericCharacters</span>=“<span class="attr">0</span>“</pre>
<pre class="alt">               <span class="attr">passwordFormat</span>=“<span class="attr">Hashed</span>“</pre>
<pre>               <span class="attr">maxInvalidPasswordAttempts</span>=“<span class="attr">5</span>“</pre>
<pre class="alt">               <span class="attr">passwordAttemptWindow</span>=“<span class="attr">10</span>“ <span class="attr">p</span>=“”</pre>
<pre>               <span class="attr">asswordStrengthRegularExpression</span>=“”<span class="kwrd">/&gt;</span></pre>
<pre class="alt">     <span class="kwrd">&lt;/</span><span class="html">providers</span><span class="kwrd">&gt;</span></pre>
<pre><span class="kwrd">&lt;/</span><span class="html">membership</span><span class="kwrd">&gt;</span></pre>
</div>
<br />

<p>Notice that the applicationName is set to just a &quot;/&quot;. To make the application work with IIS, you really need to set that to the name of your application. That is, the correct way to specify applicationName is something more like this:</p>
<br />
<div class="csharpcode">
<pre class="alt"><span class="kwrd">&lt;</span><span class="html">roleManager</span> <span class="attr">enabled</span>=“<span class="attr">true</span>“<span class="kwrd">/&gt;</span></pre>
<pre>    <span class="kwrd">&lt;</span><span class="html">membership</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">        <span class="kwrd">&lt;</span><span class="html">providers</span><span class="kwrd">&gt;</span></pre>
<pre>            <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span>=“<span class="attr">AspNetSqlMembershipProvider</span>“<span class="kwrd">/&gt;</span></pre>
<pre class="alt">            <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span>=“<span class="attr">AspNetSqlMembershipProvider</span>“</pre>
<pre>                <span class="attr">type</span>=“…“</pre>
<pre class="alt">                <span class="attr">connectionStringName</span>=“<span class="attr">LocalSqlServer</span>“</pre>
<pre>                <span class="attr">enablePasswordRetrieval</span>=“<span class="attr">false</span>“</pre>
<pre class="alt">                <span class="attr">enablePasswordReset</span>=“<span class="attr">true</span>“</pre>
<pre>                <span class="attr">requiresQuestionAndAnswer</span>=“<span class="attr">true</span>“</pre>
<pre class="alt">                <span class="attr">applicationName</span>=“/<span class="attr">MyCoolApp1</span>“</pre>
<pre>                <span class="attr">requiresUniqueEmail</span>=“<span class="attr">false</span>“</pre>
<pre class="alt">                <span class="attr">minRequiredPasswordLength</span>=“<span class="attr">1</span>“</pre>
<pre>                <span class="attr">minRequiredNonalphanumericCharacters</span>=“<span class="attr">0</span>“</pre>
<pre class="alt">                <span class="attr">passwordFormat</span>=“<span class="attr">Hashed</span>“</pre>
<pre>                <span class="attr">maxInvalidPasswordAttempts</span>=“<span class="attr">5</span>“</pre>
<pre class="alt">                <span class="attr">passwordAttemptWindow</span>=“<span class="attr">10</span>“ <span class="attr">p</span>=“”</pre>
<pre>                <span class="attr">asswordStrengthRegularExpression</span>=“”<span class="kwrd">/&gt;</span></pre>
<pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">providers</span><span class="kwrd">&gt;</span></pre>
<pre>    <span class="kwrd">&lt;/</span><span class="html">membership</span><span class="kwrd">&gt;</span></pre>
</div>
<br />
<p>This also makes it so that you can share the same membership database across multiple applications.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/10/20/loginfailswithiisnotcasini/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Fourth MSDN Article Published! &quot;Adding Personalization with Profiles to the ObjectDataSource&quot;</title>
		<link>http://peterkellner.net/2006/09/04/addprofiletoods/</link>
		<comments>http://peterkellner.net/2006/09/04/addprofiletoods/#comments</comments>
		<pubDate>Mon, 04 Sep 2006 18:55:33 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2006/09/04/addprofiletoods/</guid>
		<description><![CDATA[This article explains how the encapsulation of Membership can be extended to include Profile (personalization) information for users. The designers of Membership included a very basic set of attributes to associate with Members (logged in users).]]></description>
			<content:encoded><![CDATA[<p>Microsoft just published my fourth article. This one is titled: &quot;<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/membershipeditorwithprofile.asp">Microsoft ASP.NET 2.0 Member/Role Management with IIS, Part 4: Adding Personalization with Profiles to the ObjectDataSource</a>&quot;.</p>  <p>You can find it on <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/membershipeditorwithprofile.asp">MSDN here</a>, or on <a href="http://peterkellner.net/2006/03/13/adding-personalization-via-profiles-to-the-objectdatasource-in-aspnet-20/">my blog here</a>.</p>  <p>Here is the introduction.</p> <span id="more-31"></span>  <h2>Introduction</h2>  <p>This article extends one of the web pages developed in <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">Part II of this series</a> using Microsoft’s Profile feature. In Part II, the Membership API was encapsulated in an ObjectDataSource. This allowed the developer to have a drop in web page for the web site administrator to use in an web site project for editing membership. This tools allowed for similar capability to the the web site manager tool included in Visual Studio 2005 (VS2005). It is necessary because using that web configuration tool included with VS2005 is problematic and should not be used in a production web site.</p>  <p>This article explains how the encapsulation of Membership can be extended to include Profile (personalization) information for users. The designers of Membership included a very basic set of attributes to associate with Members (logged in users). The Profile API provided by Microsoft allows for additional information to be attached to each member. Typically, this information would include things like: first name, last name, home address, favorite color schemes or anything else the developer may want to associate with a logged in member. By personalizing the site to the member logged in, it likely increases the chance the user will return and be more comfortable while visiting.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/09/04/addprofiletoods/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Third Article Published on MSDN! ASP.NET 2.0, Membership Meets Atlas</title>
		<link>http://peterkellner.net/2006/08/02/third-article-published-on-msdn-aspnet-20-membership-meets-atlas/</link>
		<comments>http://peterkellner.net/2006/08/02/third-article-published-on-msdn-aspnet-20-membership-meets-atlas/#comments</comments>
		<pubDate>Wed, 02 Aug 2006 22:30:55 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Atlas/AJAX]]></category>
		<category><![CDATA[MSDN Articles]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=41</guid>
		<description><![CDATA[Microsoft published my third article in a series on how to use Membership in ASP.NET 2.0 with an ObjectDataSource.  That is, extending Membership into three tiers.  This article takes what was developed in article two and adds Atlas extensions to make it work even better.  The Article on MSDN uses the March CTP (Community Technology Preview).  There is an update on my blog as well as a download to make it work correctly with the June CTP.]]></description>
			<content:encoded><![CDATA[<p>Microsoft just published my third article. This one is titled: &quot;Member/Role Management with IIS, Part 3: AJAX Enhancements with Microsoft’s Atlas&quot;.</p>  <p>You can find it on <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/membershipeditoratlas.asp">MSDN here</a>, or on <a href="http://peterkellner.net/?p=1">my blog here</a>.</p>  <p>Here is the introduction.</p>  <h2>Introduction</h2>  <p>This article extends one of the web pages developed in Part II of this series using Microsoft’s implementation of AJAX called Atlas. It utilized two techniques for reducing web server traffic to the browser to enhance the users web experience. The first technique uses the UpdatePanel tags to limit the refreshed area of the web page to limited areas and the second has to do with implementing some javascript using Atlas techniques so that the web page is updated on every key stroke in a textbox. A user list is displayed based on what is actively typed into this textbox. After reading this article the developer will be able to implement AJAX (Microsoft’s implementation Atlas) in their own application.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/08/02/third-article-published-on-msdn-aspnet-20-membership-meets-atlas/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Inserting Programmatically with ObjectDataSource in ASP.NET 2.0</title>
		<link>http://peterkellner.net/2006/06/07/inserting-programmatically-with-objectdatasource-in-aspnet-20/</link>
		<comments>http://peterkellner.net/2006/06/07/inserting-programmatically-with-objectdatasource-in-aspnet-20/#comments</comments>
		<pubDate>Wed, 07 Jun 2006 20:21:02 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=37</guid>
		<description><![CDATA[( ObjectDataSource1.Insert(); )  ObjectDataSource&#8217;s are great for building your own middle tier between your aspx web page and your database (or any other datastore for that matter). By binding the datasource to a databound server control like detailsview, you auto-magically get the insert behavior you are looking for. If however, you just just want [...]]]></description>
			<content:encoded><![CDATA[<h2>( ObjectDataSource1.Insert(); )</h2>  <p>ObjectDataSource&#8217;s are great for building your own middle tier between your aspx web page and your database (or any other datastore for that matter). By binding the datasource to a databound server control like detailsview, you auto-magically get the insert behavior you are looking for. If however, you just just want to insert to the ObjectDataSource you have included on your aspx page without using a databound control, you don&#8217;t have a lot of fancy footwork to do. All you have to do is reference the insert parameter by name (or index offset) and assign it directly.</p> <span id="more-23"></span>  <p>Below is an example of how to insert a Role into Membership using the ObjectDataSource developed in a my previous MSDN article <a href="http://peterkellner.net/?p=24">Microsoft ASP.NET 2.0 Member/Role Management with IIS     <br />Part 2: Implementation</a>.</p> <!-- code formatted by http://manoli.net/csharpformat/ --><style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style>  <pre class="csharpcode"><span class="kwrd">&lt;</span> %@ Page Language=&quot;C#&quot; <span class="asp">%&gt;</span>
<span class="kwrd">&lt;</span> !DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;<span class="kwrd">&gt;</span>
 
<span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">protected</span> <span class="kwrd">void</span> Button1_Click(<span class="kwrd">object</span> sender, EventArgs e)
{
  ObjectDataSource1.InsertParameters[<span class="str">&quot;roleName&quot;</span>].DefaultValue =
    TextBoxRole.Text;
  ObjectDataSource1.Insert();
}
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>
 
<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">=&quot;http://www.w3.org/1999/xhtml&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>AddRoleWithODS.aspx<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">=&quot;form1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:ObjectDataSource</span> <span class="attr">ID</span><span class="kwrd">=&quot;ObjectDataSource1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span>
    <span class="attr">InsertMethod</span><span class="kwrd">=&quot;Insert&quot;</span>
    <span class="attr">SelectMethod</span><span class="kwrd">=&quot;GetRoles&quot;</span>
    <span class="attr">TypeName</span><span class="kwrd">=&quot;MembershipUtilities.RoleDataObject&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">insertparameters</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr"> <img src='http://peterkellner.net/wp/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> arameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;roleName&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;String&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">insertparameters</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Button</span> <span class="attr">ID</span><span class="kwrd">=&quot;Button1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Add Role&quot;</span>
    <span class="attr">OnClick</span><span class="kwrd">=&quot;Button1_Click&quot;</span> <span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">=&quot;TextBoxRole&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>

<p>If you do not want to declaratively define the ObjectDataSource and just want to use it directly, you can do that also. You simply reference the ObjectDataSource by Type and call its insert method. An example of that is below.</p>
<style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style>

<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">using</span> MembershipUtilities;
 
<span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Default3 : Page
{
  <span class="kwrd">protected</span> <span class="kwrd">void</span> Button1_Click(<span class="kwrd">object</span> sender, EventArgs e)
  {
    RoleDataObject.Insert(TextBox1.Text);
  }
}</pre>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/06/07/inserting-programmatically-with-objectdatasource-in-aspnet-20/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Adding Personalization via Profiles to the ObjectDataSource in ASP.NET 2.0</title>
		<link>http://peterkellner.net/2006/03/13/adding-personalization-via-profiles-to-the-objectdatasource-in-aspnet-20/</link>
		<comments>http://peterkellner.net/2006/03/13/adding-personalization-via-profiles-to-the-objectdatasource-in-aspnet-20/#comments</comments>
		<pubDate>Tue, 14 Mar 2006 00:33:03 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[MSDN Articles]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=29</guid>
		<description><![CDATA[<p>This article explains the mechanics involved in extending the ObjectDataSource (developed in the previous article in this <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">MSDN Membership Security Series</a>) to handle personalization information using the ASP.NET 2.0 custom provider facility. Then, it goes on to explains some fancy tricks you can do with this ObjectDataSource to make accessing membership even easier. Finally it presents a <a href="http://painfreeods.peterkellner.net/Default.aspx">free tool available on the web</a> that lets you cut and paste part of your web.config file into a web page and out comes a ready-to-compile C-Sharp ObjectDataSource.</p>]]></description>
			<content:encoded><![CDATA[<p>Also published on Microsoft’s MSDN Network at <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/membershipeditorwithprofile.asp">Microsoft ASP.NET 2.0 Member/Role Management with IIS, Part 4: Adding Personalization with Profiles to the ObjectDataSource</a></p>  <p>Applies to:</p>  <ul>   <li>Microsoft ASP.NET 2.0 </li>    <li>Microsoft Visual Studio 2005 </li>    <li>Microsoft Internet Information Services </li> </ul>  <p><a href="http://livedemos.peterkellner.net/AJAXDemo/DefaultWithProfile.aspx"></a></p> <span id="more-20"></span>  <p><a href="http://livedemos.peterkellner.net/AJAXDemo/DefaultWithProfile.aspx">Run Live Demonstration Of Personalization in Membership Technology</a></p>  <p><a href="http://painfreeods.peterkellner.net/">Go to the Web Site to Create Your Own ObjectDataSource From Your Own Web.Config</a></p>  <p><a href="http://download.microsoft.com/download/3/6/5/36559e56-c23f-47cc-9442-a160b3f1b99c/MembershipEditorWithProfile.msi">Click Here for Source Code Associated With This Article</a></p>  <p><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">Microsoft ASP.NET 2.0 Member/Role Management with IIS, Part 2: Implementation</a><span></span> </p>  <hr  ="&lt;hr" />  <p></p>  <h4>Contents</h4> <a href="#Introduction">Introduction</a>   <br /><a href="#Background">Background</a>   <br /><a href="#Why">Why Do We Need This?</a>   <br /><a href="#Adding">Adding Profile Information to the ObjectDataSource</a>   <br /><a href="#Using">Using the Profile Generating Website</a>   <br /><a href="#Build">Build A Simple Web Page</a>   <br /><a href="#Conclusions">Conclusions</a>   <br />  <h2 id="Introduction">Introduction</h2>  <p>This article extends one of the web pages developed in <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">Part II of this series</a> using Microsoft&#8217;s Profile feature. In Part II, the Membership API was encapsulated in an ObjectDataSource. This allowed the developer to have a drop in web page for the web site administrator to use in an web site project for editing membership. This tools allowed for similar capability to the the web site manager tool included in Visual Studio 2005 (VS2005). It is necessary because using that web configuration tool included with VS2005 is problematic and should not be used in a production web site.</p>  <p>This article explains how the encapsulation of Membership can be extended to include Profile (personalization) information for users. The designers of Membership included a very basic set of attributes to associate with Members (logged in users). The Profile API provided by Microsoft allows for additional information to be attached to each member. Typically, this information would include things like: first name, last name, home address, favorite color schemes or anything else the developer may want to associate with a logged in member. By personalizing the site to the member logged in, it likely increases the chance the user will return and be more comfortable while visiting.</p>  <h2>Background</h2>  <p>ASP.NET has done an outstanding job of making the profile information associated with a logged in user very easy to access programmatically. They have done this by using their Provider technology to create a typed class that the developer can access with intellisense property values. What does this mean? This means that the profile information is declaratively defined as XML in the web.config file. The example below shows the lines that have been added to the &lt;system.web&gt; section of the web.config.</p>  <br />  <pre class="csharpcode"> <span class="kwrd">&lt;</span><span class="html">system</span> .<span class="attr">web</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">profile</span> <span class="attr">defaultProvider</span><span class="kwrd">=&quot;SqlProfileProvider&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">providers</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;AspNetSqlProfileProvider&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;SqlProfileProvider&quot;</span>
       <span class="attr">type</span><span class="kwrd">=&quot;System.Web.Profile.SqlProfileProvider&quot;</span>
       <span class="attr">connectionStringName</span><span class="kwrd">=&quot;LocalSqlServer&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">providers</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">properties</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;FirstName&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;LastName&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;AdvancedMode&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;bool&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">group</span> <span class="attr">name</span><span class="kwrd">=&quot;Address&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;Street&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;City&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;State&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;Zip&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">group</span><span class="kwrd">&gt;</span>    <span class="kwrd">&lt;/</span><span class="html">properties</span><span class="kwrd">&gt;</span>  <span class="kwrd">&lt;/</span><span class="html">profile</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">system</span><span class="kwrd">&gt;</span></pre>

<br />

<p>These new properties defined by Microsoft can be accessed in C# at run time very simply. Below are a few lines of code showing how this can be done in a typical codebehind page. These lines of code are taken from the button update event on the page UpdateProfileSimple.aspx included in the download associated with this article.</p>

<br />

<pre class="csharpcode"> <span class="kwrd">protected</span> <span class="kwrd">void</span> ButtonUpdate_Click(<span class="kwrd">object</span> sender,
    EventArgs e)
{
  Profile.FirstName = TextBoxFirstName.Text;
  Profile.LastName = TextBoxLastName.Text;
  Profile.Save();
}</pre>

<br />

<p>Profile is available everywhere because it is a static class generated from the Web.Config section shown above. Because it is an actual class, the properties FirstName and LastName are available from VS2005&#8217;s intellisense and are type safe. No incorrectly typing them and getting syntax errors.</p>

<p>In the simple example below (UpdateProfileSimple.aspx), it is necessary to first pre load the textboxes when the user logs in. This can be done in the pageload event as follows.</p>

<br />

<pre class="csharpcode"> <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
{
  <span class="rem">// Only allow for profile update when a user is logged in</span>
  MembershipUser mu = Membership.GetUser();
  <span class="kwrd">if</span> (mu == <span class="kwrd">null</span>)
  {
    ButtonUpdate.Enabled = <span class="kwrd">false</span>;
  }
  <span class="kwrd">else</span>
  {
    <span class="kwrd">if</span> (!IsPostBack)
    {
      TextBoxFirstName.Text = Profile.FirstName;
      TextBoxLastName.Text = Profile.LastName;
    }
  }
}</pre>

<br />

<p>There are a couple things to notice in the above page_load event. First, if no user is logged in, the update button is disabled. This is because it would be meaningless to press the update button if there was no current user to update. It is important to mention that this article does not address dealing with anonymous users. That is a whole different topic. Very interesting, but beyond the scope of this article. Also notice that the first and last names are only loaded when the page is not a postback. That means that only the first time this page is loaded will the data will be loaded from the Profile datastore. After the first time, the data is stored in the page&#8217;s viewstate and no longer will have to be retrieved from the static Profile class. This is important to note because each time a profile property is accessed, a round trip to the membership database occurs. This is the reason using the Profile classes are often referred to as chatty with the database. Something to think about, and keep in mind when designing your application.</p>

<p>There are several good articles that go into more detail on using the profile provider. <a href="http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx">Scott Gu posts in his blog</a> an excellent how to guide that steps you through creating basic Membership in a web application including customized Profile information. A good one in MSDN is <a href="http://msdn.net/msdnmag/issues/05/10/CuttingEdge/">Personalization and User Profiles in ASP.NET 2.0 by Dino Esposito</a>. Another one of my favorites is <a href="http://www.odetocode.com/Articles/440.aspx">Profiles in ASP.NET 2.0 by Scott Allen</a>.</p>

<h2 id="#Why">Why Do We Need This? </h2>

<p>The questions comes up, why do we need an ObjectDataSource that encapsulates our Profile information? The answer is this. Even though ASP.NET does a wonderful job of giving us programmatic access to the Profile class it does not gives a simple way to view or update this data by binding it directly to any controls like gridview or detailsview. Joshua Flanagan wrote a very nice tool called <a href="http://peterkellner.net/download-manager/">ProfileView</a> that you can see on his blog. Basically, he wrote an ASP.NET 2.0 server control that enables users to view and/or edit the Profile data. It does this using reflection at runtime to figure out what the profile information is, then it shows it.</p>

<p>The ObjectDataSource allows you at design time to make the presentation layer look exactly as you like. It also allows for viewing multiple members profiles at the same time. Take a look at the screen shot below to see what a gridview looks like using on ObjectDataSource generated using this technology. Also, you can <a href="http://livedemos.peterkellner.net/AJAXDemo/DefaultWithProfile.aspx">play with it live right here</a>.</p>

<table border="0" cellpadding="10" width="200"><tbody>
    <tr>
      <td><a href="/images/MembershipProvider/membership.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/membership_t.jpg" width="341" height="388" /></a></td>

      <td><img src="/images/MembershipProvider/membership_namesonly.jpg" /></td>
    </tr>
  </tbody></table>

<p>At first glance, this is identical the screen developed in<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp"> Part 2 of this series</a>. If you look closer however (or at the picture to the right of the first one), you&#8217;ll notice that there are two new columns. First Name and Last Name. Both of these columns have data retrieved from the Membership Profile data provider we have been discussing. In the next section the details of what changes to the ObjectDataSource in the previous article have been made to allow this to happen. Something very important to note however, is that since the ObjectDataSource is basically a static class, the profile information in that ObjectDataSource will not automatically change when the web.config is changed (unlike <a href="http://flimflan.com/blog/ProfileView.aspx">Joshua Flanagan&#8217;s solution</a> which will change).</p>

<h2 id="Adding">Adding Profile Information to the ObjectDataSource</h2>

<p>As was mentioned earlier, the ObjectDataSource developed here is 100% based on the one developed in <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">Part II of this MSDN series, Implementation</a>. The discussion here assumes all the previous code is understood and only explains the additions to support the Profile feature. All the code described here is what gets generated by the <a href="http://painfreeods.peterkellner.net/">ObjectDataSource generator on Peter Kellner&#8217;s Blog</a> (this tool is discussed in greater detail in the next major section of this article). In this section we go through the details of what gets added. In the next section it is shown how the steps to generating the source described here from an existing web.config file.</p>

<h3>Changing Class Names </h3>

<p>Since it&#8217;s possible the ObjectDataSource geneated here may be used in the same project as the one provided with Part 2 of this series, all the public names have been changed to avoid naming conflicts. For example, the class name MembershipUserODS has been renamed to MembershipUserAndProfileODS. The RoleData class has been renamed RoleDataForMP and the MemberhipUserWrapper class has been renamed MembershipUserWrapperForMP (MP standing for MembershipProfile).</p>

<h3>The Insert Method</h3>

<p>The method signature of Insert now contains all the names of the Profile properties. In addition to Membership.CreateUser being called, the Profile properties must be saves also with the Profile.Save() method. Below is the complete Insert method for an example set of profile properties (profile properties are stored in the web.config file and will likely be different for each asp.net web application).</p>

<br />

<pre class="csharpcode">[DataObjectMethod(DataObjectMethodType.Insert, <span class="kwrd">true</span>)]
<span class="kwrd">public</span> <span class="kwrd">void</span> Insert(<span class="kwrd">string</span> userName, <span class="kwrd">bool</span> isApproved,
    <span class="kwrd">string</span> comment, DateTime lastLockoutDate,
    DateTime creationDate,<span class="kwrd">string</span> email,
    DateTime lastActivityDate, <span class="kwrd">string</span> providerName,
    <span class="kwrd">bool</span> isLockedOut,DateTime lastLoginDate,
    <span class="kwrd">bool</span> isOnline, <span class="kwrd">string</span> passwordQuestion,
    DateTime lastPasswordChangedDate, <span class="kwrd">string</span> password,
    <span class="kwrd">string</span> passwordAnswer, <span class="kwrd">string</span> firstName,
    <span class="kwrd">string</span> lastName, <span class="kwrd">bool</span> advancedMode,
    <span class="kwrd">string</span> address_Street, <span class="kwrd">string</span> address_City,
    <span class="kwrd">string</span> address_State, <span class="kwrd">string</span> address_Zip
    )
{

    MembershipCreateStatus status;
    Membership.CreateUser(userName, password, email,
        passwordQuestion, passwordAnswer,
        isApproved, <span class="kwrd">out</span> status);

    <span class="kwrd">if</span> (status != MembershipCreateStatus.Success)
    {
     <span class="kwrd">throw</span> <span class="kwrd">new</span> ApplicationException(status.ToString());
    }

    MembershipUser mu = Membership.GetUser(userName);
    mu.Comment = comment;
    Membership.UpdateUser(mu);
    ProfileCommon pc =
     (ProfileCommon)ProfileBase.Create
        (mu.UserName, <span class="kwrd">true</span>);
    pc.FirstName = firstName;
    pc.LastName = lastName;
    pc.AdvancedMode = advancedMode;
    pc.Address.Street = address_Street;
    pc.Address.City = address_City;
    pc.Address.State = address_State;
    pc.Address.Zip = address_Zip;
    pc.Save();
}</pre>

<br />

<p>Something also to take note of is the the variable names are constructed with an underscore because variable names with periods would not work. Notice in particular the properties that are nested such as address_state. This refers to the Profile property pc.Address.State.</p>

<h3>The Delete Method</h3>

<p>The delete method has no changes. This is because the membership class takes care of removing all profile information when Membership.DeleteUser() is invoked.</p>

<h3>The Update Method</h3>

<p>The Update method is changed. To the parameter list is added all the parameters representing properties. Then, in the update method itself the profile information is update after the Membership is updated. below is a portion of the code for this using the example properties.</p>

<br />

<pre class="csharpcode">ProfileCommon pc = (ProfileCommon)ProfileBase.
      Create(mu.UserName, <span class="kwrd">true</span>);
    pc.FirstName = firstName;
    pc.LastName = lastName;
    pc.AdvancedMode = advancedMode;
    pc.Address.Street = address_Street;
    pc.Address.City = address_City;
    pc.Address.State = address_State;
    pc.Address.Zip = address_Zip;
    pc.Save();</pre>

<br />

<h3>The Get (Select) Methods </h3>

<p>Just like in Part 2 of this series, there are several Get Methods provided. No additional get methods are added, however now, because of the addition of the Profile properties, the Get Method&#8217;s return profile properties include Membership Properties as well as Profile properties. This is handled by first retrieving the Membership data with GetUser or GetUsers methods, then adding the additional properties from the profile to the Generic list which will get returned. The critical section of code that does this is next.</p>

<br />

<pre class="csharpcode">MembershipUserCollection muc = Membership.GetAllUsers();
<span class="kwrd">foreach</span> (MembershipUser mu <span class="kwrd">in</span> muc)
{
 <span class="kwrd">if</span> ((returnAllApprovedUsers==<span class="kwrd">true</span> &amp;amp;&amp;amp; mu.IsApproved==<span class="kwrd">true</span>) ||
 (returnAllNotApprovedUsers==<span class="kwrd">true</span> &amp;amp;&amp;amp; mu.IsApproved==<span class="kwrd">false</span>))
 {
    MembershipUserWrapperForMP md =
      <span class="kwrd">new</span> MembershipUserWrapperForMP(mu);
    ProfileCommon pc = (ProfileCommon)ProfileBase.Create
      (mu.UserName, <span class="kwrd">true</span>);
    md.FirstName = pc.FirstName;
    md.LastName = pc.LastName;
    md.AdvancedMode = pc.AdvancedMode;
    md.Address_Street = pc.Address.Street;
    md.Address_City = pc.Address.City;
    md.Address_State = pc.Address.State;
    md.Address_Zip = pc.Address.Zip;
    memberList.Add(md);
 }
}</pre>

<br />

<h3>Sorting Support </h3>

<p>Sorting the ObjectDataSource&#8217;s columns is also supported. Just as in Membership Part 2, this is supported using anonymous delegates. Basically, a comparater method is created with an anonymous delegate that takes two parameters. The left and right hand side of a sort operation. Then, using this comparater, the generic List is sorted before being returned to the caller. This very clever construct was inspired by <a href="http://blogs.tedneward.com">Ted Neward </a>at a Code Camp in Portland.</p>

<p>Just like the MembershipUser properties, Profile properties are handled the same way so that those values can be sorted in a GridView by clicking on the column headers. Below is the creation of one comparater method.</p>

<br />

<pre class="csharpcode"><span class="kwrd">switch</span> (sortDataBase)
{
  <span class="kwrd">case</span> &amp;quot;FirstName&amp;quot;:
    comparison = <span class="kwrd">new</span>
      Comparison&lt;membershipuserwrapperformp&gt;(
       <span class="kwrd">delegate</span>(MembershipUserWrapperForMP lhs,
            MembershipUserWrapperForMP rhs)
       {
           <span class="kwrd">return</span> lhs.FirstName.CompareTo(
              rhs.FirstName);
       }
     );
    <span class="kwrd">break</span>;&lt;/membershipuserwrapperformp&gt;</pre>

<br />

<h3>The Class associated with the Generic List </h3>

<p>The final piece of code that has to be extended is the Class that is returned from the Get methods. That is the generic list which is declared as follows.</p>

<br />

<pre class="csharpcode"> <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
{
  <span class="rem">// Only allow for profile update when a user is logged in</span>
  MembershipUser mu = Membership.GetUser();
  <span class="kwrd">if</span> (mu == <span class="kwrd">null</span>)
  {
    ButtonUpdate.Enabled = <span class="kwrd">false</span>;
  }
  <span class="kwrd">else</span>
  {
    <span class="kwrd">if</span> (!IsPostBack)
    {
      TextBoxFirstName.Text = Profile.FirstName;
      TextBoxLastName.Text = Profile.LastName;
    }
  }
}</pre>

<br />

<h3>One Final Trick on Using the ObjectDataSource </h3>

<p>ObjectDataSource&#8217;s are great for using with databound ASP.NET&#8217;s controls such as GridView and DetailsView. They are wired such that the get methods, update, delete and insert line up perfectly with what those controls are looking for. However, the ODS&#8217;s can be used directly without having a presentation style control associated with them. For example, the Insert method associated with adding a new member in the included code from the asp.net page MembershipWithProfile.aspx uses the ObjectDataSource to insert even though it is not bound to any control on the page. The data it is entering is coming from TextBox&#8217;s in a table. Below is the Insert code used. Notice how straight forward it is to use compared do creating an inserter and doing all the ADO without this class.</p>

<br />

<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> ButtonNewUser_Click(<span class="kwrd">object</span> sender, EventArgs e)
{

    MembershipUtilities.MembershipUserAndProfileODS
      membershipUserAndProfileODS =
        <span class="kwrd">new</span> MembershipUserAndProfileODS();

    membershipUserAndProfileODS.Insert(
        TextBoxUserName.Text,
        CheckboxApproval.Checked,
        <span class="kwrd">string</span>.Empty,
        DateTime.Now,
        DateTime.Now,
        TextBoxEmail.Text,
        DateTime.Now,
        <span class="kwrd">string</span>.Empty,
        <span class="kwrd">false</span>,
        DateTime.Now,
        <span class="kwrd">false</span>,
        TextBoxPasswordQuestion.Text,
        DateTime.Now,
        TextBoxPassword.Text,
        TextBoxPasswordAnswer.Text,
        TextBoxFirstName.Text,
        TextBoxLastName.Text,
        <span class="kwrd">false</span>,
        <span class="kwrd">string</span>.Empty,
        <span class="kwrd">string</span>.Empty,
        <span class="kwrd">string</span>.Empty,
        <span class="kwrd">string</span>.Empty);

    GridViewMemberUser.DataBind();
    TextBoxUserName.Text = <span class="kwrd">string</span>.Empty;
    TextBoxFirstName.Text = <span class="kwrd">string</span>.Empty;
    TextBoxLastName.Text = <span class="kwrd">string</span>.Empty;
    TextBoxPassword.Text = <span class="kwrd">string</span>.Empty;
    TextBoxEmail.Text = <span class="kwrd">string</span>.Empty;
    TextBoxPasswordAnswer.Text = <span class="kwrd">string</span>.Empty;
    TextBoxPasswordQuestion.Text = <span class="kwrd">string</span>.Empty;
    CheckboxApproval.Checked = <span class="kwrd">false</span>;
}</pre>

<br />

<p>Because this is an actual class with properties, using the ObjectDataSource class is type safe. For example, in the code below, the user may want to count how many zipcodes in the membership database that begin with 9. Here is the code to do it. Notice how Address_Zip is used in a type safe way.</p>

<br />

<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> ButtonZipCount_Click
    (<span class="kwrd">object</span> sender, EventArgs e)
{
    MembershipUtilities.MembershipUserAndProfileODS
        membershipUserAndProfileODS =
        <span class="kwrd">new</span> MembershipUserAndProfileODS();

    List&lt;membershipuserwrapperformp&gt; li =
        membershipUserAndProfileODS.GetMembers
        (<span class="kwrd">string</span>.Empty);

    <span class="kwrd">int</span> count = 0;
    <span class="kwrd">foreach</span> (MembershipUserWrapperForMP mu <span class="kwrd">in</span> li)
    {
        <span class="kwrd">if</span> (mu.Address_Zip.StartsWith(&amp;quot;9&amp;quot;))
        {
            count++;
        }
    }
}&lt;/membershipuserwrapperformp&gt;</pre>

<br />

<h2 id="Using">Using the Profile Generating Website </h2>

<p>All the changes listed in the previous section could be done by hand, however this would be very tedious. To make this process much easier, a code generator has been developed which takes as input the applications web.config file&#8217;s &lt;System.Web&gt; section. The idea is to cut this out of the web.config file and paste it into the web page which will generate the code for you. Below is a screen show of what the web page looks like. When you get to this page, you must first click on the button in the right column labeled &quot;Click Here to Begin&quot;.</p>

<p>Here is the URL: <a href="http://painfreeods.peterkellner.net/">http://painfreeods.peterkellner.net/</a></p>

<p>&#160;<a href="http://peterkellner.net/images/MembershipProvider/ProfileGenPage.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/ProfileGenPage_t.jpg" /></a></p>

<p>The XML which is pasted into the multi line orange textbox is as follows (you should paste your own in here).</p>

<br />

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">system</span>  .<span class="attr">web</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">profile</span> <span class="attr">defaultprovider</span><span class="kwrd">=&quot;SqlProfileProvider&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">providers</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;AspNetSqlProfileProvider&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;SqlProfileProvider&quot;</span> <span class="attr">connectionstringname</span><span class="kwrd">=&quot;LocalSqlServer&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;System.Web.Profile.SqlProfileProvider&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">providers</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">properties</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;FirstName&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;LastName&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;AdvancedMode&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;bool&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">group</span> <span class="attr">name</span><span class="kwrd">=&quot;Address&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;Street&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;City&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;State&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;Zip&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">group</span><span class="kwrd">&gt;</span>    <span class="kwrd">&lt;/</span><span class="html">properties</span><span class="kwrd">&gt;</span>  <span class="kwrd">&lt;/</span><span class="html">profile</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">system</span><span class="kwrd">&gt;</span></pre>

<br />

<p>Now, if the &quot;Show Generated C#&quot; button is pressed, the complete ObjectDataSource will be created. This code can then be cut and pasted into the App_Code directory of the web project. Here is what the screen looks like.</p>

<p><a href="http://peterkellner.net/images/MembershipProvider/ProfileGenSrc.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/ProfileGenSrc_t.jpg" /></a></p>

<p>There are some limitations to this code generation technology. First is that there can only be one level of nesting. That is, there can be no groups of groups. Just one level of grouping is allowed as is shown here. It is OK to have multiple groups, just not nested. Another limitation is the type associated with the name must be a C# type. That is, string, bool,DateTime,etc. The final limitation (known about) is that it can not handle Array or Collection type properties. All properties must be single valued.</p>

<p>At this point, error checking is minimal so if the limitations are exceeded, something will likely come out but it may not be what was desired.</p>

<h2 id="Build">Build A Simple Web Page</h2>

<p>Now that the C# class has been generated, the next steps are very straight forward. For those who have not built a GridView based on an ObjectDataSource, here is a pictorial step by step of the 9 things needed to do to have a very simple gridview control in under 5 minutes.</p>

<table border="0" cellpadding="2" width="694"><caption>Building a Web Page From Scratch 
    <br /></caption><tbody>
    <tr>
      <td>
        <p><a href="http://peterkellner.net/images/MembershipProvider/step1.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step1_t.jpg" width="250" height="186" /></a></p>

        <p>1. Add a New Web Page to the Project</p>
      </td>

      <td>
        <p><a href="http://peterkellner.net/images/MembershipProvider/step2.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step2_t.jpg" width="250" height="179" /></a></p>

        <p>2. Choose Web Page and Name it</p>
      </td>
    </tr>

    <tr>
      <td>
        <p><a href="http://peterkellner.net/images/MembershipProvider/step3.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step3_t.jpg" width="250" height="206" /></a></p>

        <p>3. Add a GridView and an ObjectDataSource. Associate them</p>
      </td>

      <td>
        <p><a href="http://peterkellner.net/images/MembershipProvider/step4.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step4_t.jpg" /></a></p>

        <p>4. Configure the ObjectDataSource by Assigning the Class</p>
      </td>
    </tr>

    <tr>
      <td>
        <p>&#160;</p>

        <p><a href="http://peterkellner.net/images/MembershipProvider/step5.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step5_t.jpg" width="250" height="174" /></a></p>

        <p>5. Choose the Get Method (Use Default)</p>
      </td>

      <td>
        <p>&#160;</p>

        <p><a href="http://peterkellner.net/images/MembershipProvider/step6.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step6_t.jpg" width="250" height="174" /></a></p>

        <p>6. Choose the Update Method (Use Default)</p>
      </td>
    </tr>

    <tr>
      <td>
        <p><a href="http://peterkellner.net/images/MembershipProvider/step7.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step7_t.jpg" width="250" height="174" /></a></p>

        <p>7. Choose the Insert Method (Choose Default)</p>
      </td>

      <td>
        <p><a href="http://peterkellner.net/images/MembershipProvider/step8.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step8_t.jpg" width="250" height="174" /></a></p>

        <p>8. Choose the Delete Method (Choose Default)</p>
      </td>
    </tr>

    <tr>
      <td>
        <p><a href="http://peterkellner.net/images/MembershipProvider/step9.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step9_t.jpg" width="250" height="154" /></a></p>

        <p>9. Run it! (OK, had to enable edit and delete on Gridview. No more boxes left)</p>
      </td>

      <td>&#160;</td>
    </tr>
  </tbody></table>

<p>The code in the associated source to this article has a web apge ( MembershipWithProfile.aspx) which is very similar to what is done here.</p>

<h2 id="Conclusions">Conclusions</h2>

<p>Profiles are a very powerful way to store information about Membership. It&#8217;s powerful in that with very little coding, lots of additional information about logged in users is available. With this tool, there is now a better way to organize this information and maintain it. Briefly mentioned earlier were the performance implications of using Profile information. It is important to understand what his happening under the covers when this technology is used. As long there is an understanding of what is happening and it is acceptable in the web application being developed, this is a wonderful technology.</p>

<p>Finally, as a plug to the technology that was used in this free ObjectDataSource creator, the Pain Free ObjectDataSource Creator, available through subscription on this blog, lets the developer generate very flexible ObjectDataSource&#8217;s to access database information in SqlServer, MySql and Oracle. Unlike the Profile ODS generator in this article, the ODS generator for databases gives you a large amount of flexibility. An infinite number of getter methods, updaters and inserters can be defined. It works with views, and also stored procedures. Any questions on the Pain Free ODS Generator, <a href="http://peterkellner.net/contact/">click here</a>.</p>

<p>Thanks for reading, and best of luck with your coding projects.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/03/13/adding-personalization-via-profiles-to-the-objectdatasource-in-aspnet-20/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>AJAX Meets ASP.NET 2.0 Membership Management For IIS</title>
		<link>http://peterkellner.net/2006/03/02/ajaxmeetsaspnet20/</link>
		<comments>http://peterkellner.net/2006/03/02/ajaxmeetsaspnet20/#comments</comments>
		<pubDate>Thu, 02 Mar 2006 19:34:44 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[MSDN Articles]]></category>
		<category><![CDATA[Membership]]></category>

		<guid isPermaLink="false">/?p=1</guid>
		<description><![CDATA[This article extends one of the web pages developed in Part II of this series using Microsoft's implementation of AJAX called Atlas.  You can view a live demonstration of the technology developed in this article at the URL  <a href="http://livedemos.peterkellner.net/AJAXDemo">http://livedemos.peterkellner.net/AJAXDemo</a>.]]></description>
			<content:encoded><![CDATA[<table border="0" align="left"><tbody>     <tr>       <td class="title">         <div align="center">Microsoft ASP.NET 2.0 Member/Role Management with IIS, Part 3: AJAX Enhancements with Microsoft&#8217;s Atlas </div>       </td>     </tr>   </tbody></table>  <p>&#160;</p>  <table border="0" cellpadding="2" width="200"><tbody>     <tr>       <td>Peter Kellner</td>     </tr>      <tr>       <td><a href="http://peterkellner.net">http://PeterKellner.net</a></td>     </tr>      <tr>       <td>March 2006</td>     </tr>   </tbody></table>  <p>Applies to:</p>  <blockquote>   <p>Microsoft ASP.NET 2.0</p>    <p>Microsoft Visual Studio 2005</p>    <p>Microsoft Internet Information Services</p> </blockquote>  <p>&#160;<a class="style2" href="http://livedemos.peterkellner.net/">Run Live Demonstration Of AJAX Technology</a></p>  <p class="style2"><a href="http://peterkellner.net/download-manager/">Click Here for Source Code Associated With This Article</a>&#160; </p>  <hr />  <h4>Contents</h4>  <p>Introduction    <br />What is AJAX and Atlas     <br />Background     <br />The AJAX Enhanced Version     <br />Technologies Used in AJAX Enhanced Version     <br />Steps Involved in Building (or upgrading) to AJAX using Atlas     <br />Using UpdatePanel ASP.NET Tag     <br />What is Really Happening     <br />Enhancing the TextBox for User Search     <br />Conclusions&#160; </p> <span id="more-19"></span>  <h2>Introduction</h2>  <p>This article extends one of the web pages developed in Part II of this series using Microsoft&#8217;s implementation of AJAX called Atlas. It utilized two techniques for reducing web server traffic to the browser to enhance the users web experience. The first technique uses the UpdatePanel tags to limit the refreshed area of the web page to limited areas and the second has to do with implementing some javascript using Atlas techniques so that the web page is updated on every key stroke in a textbox. A user list is displayed based on what is actively typed into this textbox. After reading this article the developer will be able to implement AJAX (Microsoft&#8217;s implementation Atlas) in their own application.</p>  <h2>What is AJAX and Atlas</h2>  <p>AJAX is an acronym for <strong>A</strong>synchronous <strong>J</strong>avaScript <strong>A</strong>nd <strong>X</strong>ML. It is a technique for making interactive web applications more responsive. It does this by exchanging small amounts of information between the web server and the web client, thereby reducing the amount of traffic to the web client and making the application more responsive. Without AJAX, each time a page is refreshed (or a postback in generated) the complete page must be retransmitted to the users web browser. This is somewhat mitigated by the local cache on the web browser, but still overkill since most of the information on a postback to a web page does not change.</p>  <p>Atlas is Microsoft&#8217;s implantation of AJAX. It is designed to make it relatively easy for software engineer, already skilled in ASP.NET 2.0 to take advantage of AJAX. Though Atlas has huge capabilities (which, by the way come with a huge learning curve), it is very easy to implement the basics of AJAX and significantly improve the user experience of a web site designed with ASP.NET 2.0 as well be shown in this article.</p>&#160;&#160;&#160;&#160; <h2>Background</h2>  <p>Managing membership and roles for ASP.NET 2.0 using ObjectDataSource technology was developed in a previous article published by this author in MSDN ( <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp</a> ). This article stepped through the inner workings of an ObjectDataSource that allowed for the easy creation of gridviews, dataviews, or any other databound control. It also presented a best practices solution in the form of a ASP.NET 2.0 web page (aspx file). The solution allowed for adding, modifying and deleting members, adding and deleting roles, as well as assigning users to roles. The solution is functionally similar to what comes with Visual Studio 2005 under the menu item &quot;Website / ASP.NET Configuration&quot;. The major benefit is that this solution works 100% with IIS 5.1 and 6.0 and gives the software engineer complete customization control of what is presented to the user. It would normally be set to administrator access only. Below is a screen shot of this application previously developed.</p>  <p><a href="http://livedemos.peterkellner.net/AJAXDemo/DefaultNoAjax.aspx"><img border="1" src="http://peterkellner.net/images/ArticleAJAX/DefaultNoAjax.gif" width="450" height="245" /></a></p>  <p><a href="http://livedemos.peterkellner.net/AJAXDemo/DefaultNoAjax.aspx"></a></p>  <p>This application shown above has no AJAX technology in it. This means that every interaction you have with the web form requires a full page refresh of html from the web server. In this case, a picture is not worth very many words, but a URL will certainly make the point. Go to the URL: <a href="http://livedemos.peterkellner.net/AJAXDemo/Default.aspx">http://livedemos.peterkellner.net/AJAXDemo/Default.aspx</a> and play with the web site. Feel completely free to search on this data, add new users, add roles, assign and unassign roles as you please noticing at the time how the page reacts to changes. In particular, note the Search button on top for finding users. This search is a little different than you would normally expect. Instead of looking for exact matches, it effectively finds usernames that begin with what you have typed in the textbox when you press the search button. In the next section, the AJAX enhanced version, the search button is gone and as the username is typed into the textbox, the list of usernames will be automatically updated. This could have been done here also, however it would have caused a complete refresh of the page on every keystroke. Not only would the performance have been unacceptable, it would also have been unusable with all the flashing while typing. This is why in non-AJAX applications, there is almost always a button to press when data is finished being entered.</p>  <p>While you are running the demonstration program, notice at the top of the page there is a link that takes you to the same application without AJAX. Notice that in this application, there is a button for search. Notice also when you check and uncheck the checkboxes to display Manage Roles or Create New Users, those sections turn on and off with a lot of screen refreshing. Also notice the difference when you edit users and assign or unassign roles. </p>  <h2>The AJAX Enhanced Version</h2>  <p>Without actually running the web application, the only visual change the user can see in the AJAX enhanced version of this application is that there is no search button above the user list. This is because with AJAX, as the user types in the search criteria, the list of users is automatically restricted to the search criteria defined by users that begin with what is typed. Notice in the screen shot below, ch is entered into the username textbox and just the usernames beginning with ch automatically appear. </p>  <p><a href="http://livedemos.peterkellner.net/AJAXDemo/Default.aspx"><img border="1" src="http://peterkellner.net/images/ArticleAJAX/DefaultWithAjax.gif" width="450" height="245" /></a>&#160;</p>  <h2>Technologies Used in AJAX Enhanced Version</h2>  <p>Obviously, Microsoft&#8217;s Atlas is the primary technology used to implement AJAX. Atlas has lots of functionality and capability, however in this article (and the code associated with the AJAX enhanced Membership Editor), there is just a small part of Atlas being used. Actually, there are only two technologies going on. One has to do with the updates on the screen not requiring complete html refreshes between postbacks, and the other has to do with extending the functionality of the TextBox control the user enters the name for search. Because the default TextBox has no event associated with characters changing (it only has an event which generates a postback for TextChanged) the TextBox has to be enhanced to deal with the javascript function OnTextChanged. </p>  <h2>Steps Involved in Building (or upgrading) to AJAX using Atlas</h2>  <p>In order to Atlas enable an application you need to make several changes to your project. I won&#8217;t go through all the details, however, the basics are you need to copy in the Atlas script library, modify your web.config, add the atlas dll to your project and finally, add some initializing tags in your aspx pages. The other way to begin working with Atlas (and is it was done to convert the project associated with this article) is first download the new Atlas template from Microsoft&#8217;s Atlas web site. Then, create a new web project using the newly installed Atlas template. Next, rename the default.aspx file in case you have your own, then copy in all your existing libraries and pages. Finally, add your sections to the Atlas enabled web.config file and make sure everything works as before with no Atlas functionality. The final step is to look at the original default.aspx file and copy the Atlas constructs into the headers of an existing page you want to add AJAX capabilities.</p>  <p>It is recommended not to put Atlas in your master page because there are undoubtedly pages that do not need AJAX capability. It is better to put that capability in only the pages you need to keep things simple.</p>  <h2>Using UpdatePanel ASP.NET Tag</h2>  <p>Below is the actual UpdatePanel asp.net control surrounding the checkboxes that let you turn on and off the Role Management, and the Create of New User section. It&#8217;s the two checkboxes half way down the web screen.</p>  <br />  <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">atlas</span> <span class="attr">:UpdatePanel</span> <span class="attr">ID</span><span class="kwrd">=&quot;UpdatePanelCheckBoxes&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
 <span class="kwrd">&lt;</span><span class="html">contenttemplate</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">table</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">align</span><span class="kwrd">=&quot;left&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:CheckBox</span> <span class="attr">ID</span><span class="kwrd">=&quot;CheckBoxManageRoles&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Manage Roles&quot;</span>
          <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">AutoPostBack</span><span class="kwrd">=&quot;True&quot;</span> <span class="attr">Checked</span><span class="kwrd">=&quot;True&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">align</span><span class="kwrd">=&quot;right&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:CheckBox</span> <span class="attr">ID</span><span class="kwrd">=&quot;CheckBoxAddUser&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Create New Users&quot;</span>
         <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">AutoPostBack</span><span class="kwrd">=&quot;True&quot;</span> <span class="attr">Checked</span><span class="kwrd">=&quot;True&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span>
 <span class="kwrd">&lt;/</span><span class="html">contenttemplate</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">atlas</span><span class="kwrd">&gt;</span></pre>

<br />

<p>The UpdatePanel control is the control that will most likely be used the most. By surrounding parts of the web page that will change on the postback, this causes the affect of letting this section update with out actually a screen refresh. Essentially, what Atlas does on a page that is Atlas enabled, is it lets all the normal asp.net page lifecycle events process normally (including the Page_Init method) but instead of redisplaying all the HTML in the Page_Render method, it knows to only update code inside the UpdatePanels defined on the web page. In reality what is happening is Atlas is simulating a postback instead of doing a real one.</p>

<p>Something that must be set also is in the ScriptManager tag, for this to actually work, the EnablePartialRendering must be set to true as shown below. If it is not set, then the page behaves as if the UpdatePanel tags are not there.</p>

<br />

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">atlas</span> <span class="attr">:ScriptManager</span> <span class="attr">ID</span><span class="kwrd">=&quot;ScripManager&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span>
   <span class="attr">EnablePartialRendering</span><span class="kwrd">=&quot;true&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">atlas</span><span class="kwrd">&gt;</span></pre>

<br />

<p>The final thing to do is to surround all the areas on the aspx page with these UpdatePanel tags. Once this is done, VS2005 does a nice job of showing the UpdatePanel areas. The screen shot below shows the actual screen shot of the page used to manage members. Notice all the UpdatePanel tags displayed above the regions. Clicking on the image will display a large one which is much easier to see the details.</p>

<p><a href="http://peterkellner.net/images/ArticleAJAX/vs2005UpdatePanels.gif"><img border="1" src="http://peterkellner.net/images/ArticleAJAX/vs2005UpdatePanels_small.gif" width="450" height="245" /></a></p>

<p>Trigger tags go hand in hand with the UpdatePanel control. Essentially, you can nest trigger controls in the UpdatePanel control and that will specify when the UpdatePanel will actually be posted back. You can specify triggers in two ways. The first way is on some control event such as the EventName &quot;Click&quot; on the button control. The other way is on some control value changing. with that, you would specify the controlID and the property name. There are no examples of triggers in the article download. The code below is just an example of typical code.</p>

<br />

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">atlas</span> <span class="attr">:UpdatePanel</span> <span class="attr">ID</span><span class="kwrd">=&quot;Panel1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
 <span class="kwrd">&lt;</span><span class="html">contenttemplate</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">=&quot;TextBox1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Button</span> <span class="attr">ID</span><span class="kwrd">=&quot;Button1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
 <span class="kwrd">&lt;/</span><span class="html">contenttemplate</span><span class="kwrd">&gt;</span>
 <span class="kwrd">&lt;</span><span class="html">triggers</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">atlas</span> <span class="attr">:ControlEventTrigger</span> <span class="attr">ControlID</span><span class="kwrd">=&quot;Button1&quot;</span> <span class="attr">EventName</span><span class="kwrd">=&quot;Click&quot;</span> <span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">atlas</span> <span class="attr">:ControlValueTrigger</span> <span class="attr">ControlID</span><span class="kwrd">=&quot;TextBox1&quot;</span> <span class="attr">PropertyName</span><span class="kwrd">=&quot;Text&quot;</span>   <span class="kwrd">/&gt;</span>
 <span class="kwrd">&lt;/</span><span class="html">triggers</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">atlas</span><span class="kwrd">&gt;</span></pre>

<br />

<h2>What is Really Happening</h2>

<p>To understand what is really happening with these UpdatePanel tags, it is helpful to look at the source generated for the web page. Essentially what is happening is that for every control on your web page that is surrounded by the UpdatePanel tags, javascript is created which forces a postback on every click. For example, just looking at the checkboxAddUser control, the following is what is generated.</p>

<br />

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">align</span><span class="kwrd">=&quot;right&quot;</span><span class="kwrd">&gt;</span>
 <span class="kwrd">&lt;</span><span class="html">label</span> <span class="attr">for</span><span class="kwrd">=&quot;CheckBoxAddUser&quot;</span><span class="kwrd">&gt;</span>Create New Users<span class="kwrd">&lt;/</span><span class="html">label</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">input</span> <span class="attr">id</span><span class="kwrd">=&quot;CheckBoxAddUser&quot;</span>
   <span class="attr">type</span><span class="kwrd">=&quot;checkbox&quot;</span> <span class="attr">name</span><span class="kwrd">=&quot;CheckBoxAddUser&quot;</span>
   <span class="attr">checked</span><span class="kwrd">=&quot;checked&quot;</span> <span class="attr">onclick</span>=
   <span class="kwrd">&quot;javascript:setTimeout
   ('__doPostBack(\'CheckBoxAddUser\',\'\')', 0)&quot;</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

<br />

<p>This is in addition to all the javascript references that include lots of other javascripts. The bottom line here is that if you include Atlas in your web pages, the actual payload size delivered to your web page in bytes will be significantly larger on the first download then it would be without Atlas. Subsequent requests are of course much smaller because, depending on how you design your page, only small amounts of data need to be returned on each future postback.</p>

<h2>&#160;</h2>

<h2>Enhancing the TextBox for User Search</h2>

<p>The textbox search functionality is a little more tricky. It involves adding javascript which reacts to keystrokes changes. The reason this is necessary is because there is not event in the TextBox control that responds to keyboard clicks. There is only an event that reacts to text changes which is not good enough for our needs. In this application, I am using javascript from The <a href="http://aspadvice.com/blogs/garbin/archive/2006/02/25/15360.aspx">Atlas Notes Blog</a> by Garbin</p>

<p>The steps necessary to make this work are as follows:</p>

<p>Add the TextChangedBehavior.js to the ScriptLibrary folder</p>

<p>Add just below the &lt;form&gt; tag of your aspx page a line that includes the new javascript</p>

<br />

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">atlas</span> <span class="attr">:ScriptManager</span> <span class="attr">ID</span><span class="kwrd">=&quot;sm&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span>
     <span class="attr">EnablePartialRendering</span><span class="kwrd">=&quot;true&quot;</span><span class="kwrd">&gt;</span>
 <span class="kwrd">&lt;</span><span class="html">scripts</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">atlas</span> <span class="attr">:ScriptReference</span>
     <span class="attr">Path</span><span class="kwrd">=&quot;ScriptLibrary/TextChangedBehavior.js&quot;</span> <span class="kwrd">/&gt;</span>
 <span class="kwrd">&lt;/</span><span class="html">scripts</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">atlas</span><span class="kwrd">&gt;</span></pre>

<br />

<p>Add a small javascript code piece to your web page that your TextBox control will reference</p>

<br />

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">type</span><span class="kwrd">=&quot;text/javascript&quot;</span><span class="kwrd">&gt;</span>
  <span class="kwrd">function</span> onTextChange() {
    __doPostBack(<span class="str">'GridViewMemberUser'</span>,<span class="str">''</span>) ;
        }
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span></pre>

<br />

<p>And, finally add another xml-script to the bottom of your web page that declaratively tells the Atlas processor to add this new javascript capability to the TextBoxSearchUser Control. This essentially maps the onclick event of the TextBoxSearchUser to the onTextChange javascript. The timeout is very nice because it allows for typing without causing postbacks until the typer stops typing for that many milliseconds.</p>

<br />

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">type</span><span class="kwrd">=&quot;text/xml-script&quot;</span><span class="kwrd">&gt;</span>
 &lt;page&gt;
  &lt;components&gt;
   &lt;textbox id=<span class="str">&quot;TextBoxSearchUser&quot;</span>&gt;
    &lt;behaviors&gt;
     &lt;textchangedbehavior timeout=<span class="str">&quot;100&quot;</span>
        changed=<span class="str">&quot;onTextChange&quot;</span> /&gt;
    &lt;/behaviors&gt;
   &lt;/textbox&gt;
  &lt;/components&gt;
 &lt;/page&gt;
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span></pre>

<br />

<h1>Conclusions</h1>

<p>AJAX, though in concept is not new, is one of the most exciting new technologies to hit the Web for quite some time. The tool kits now available, such as Microsoft&#8217;s Atlas which is described here and included with the demonstration download, makes adding AJAX functionality to existing ASP.NET 2.0 applications very straight forward. In this article, I&#8217;ve discussed the mechanics of adding AJAX functionality but have not addressed the impact to web servers, cross browser functionality or web design. Those things must all be considered before including AJAX technology in an existing web application. Overall however, AJAX, and Microsoft&#8217;s implementation ATLAS, are wonderful things.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/03/02/ajaxmeetsaspnet20/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Membership Management Newly Styled GridView</title>
		<link>http://peterkellner.net/2006/01/27/membership-management-newly-styled-gridview/</link>
		<comments>http://peterkellner.net/2006/01/27/membership-management-newly-styled-gridview/#comments</comments>
		<pubDate>Fri, 27 Jan 2006 17:46:09 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=27</guid>
		<description><![CDATA[Mikhail Lukyanau has been kind enough to provide a redesigned version of the membership.aspx page]]></description>
			<content:encoded><![CDATA[<body>


<p class="style4">Mikhail Lukyanau has been kind enough to provide a redesigned version of the membership.aspx page. The source file for this can be downloaded at <a href="http://peterkellner.net/zdm_1_2/index.php?file=7">(Download New File)</a>. Below is a screen shot of this new look. </p>
<p class="style4"><a href="http://peterkellner.net/images/MSDN_Membership/Membership1aspx.jpg"><img src="http://peterkellner.net/images/MSDN_Membership/Membership1aspx_t.jpg" alt="" width="400" height="300" border="0" longdesc="http://peterkellner.net/images/MSDN_Membership/Membership1aspx.jpg" /></a></p>
<p class="style4">Figure 1 &#8211; Updated Design for Membership.aspx By Mikhail Lukyanau</p>
<p class="style4">&nbsp; </p>
</body>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/01/27/membership-management-newly-styled-gridview/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Using Membeship ObjectDataSource For Returning ProviderUserKey (ForeignKey Use)</title>
		<link>http://peterkellner.net/2006/01/10/using-membeship-objectdatasource-for-returning-provideruserkey/</link>
		<comments>http://peterkellner.net/2006/01/10/using-membeship-objectdatasource-for-returning-provideruserkey/#comments</comments>
		<pubDate>Tue, 10 Jan 2006 16:54:53 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/archives/2006/01/10/26/</guid>
		<description><![CDATA[<p>This article gives an example of how to modify the Object DataSource in the previous article (<a href="http://peterkellner.net/archives/2006/01/09/24/">Microsoft ASP.NET 2.0 Member/Role Management with IIS<br />
Part 1: Security and   Configuration Overview </a> ) to return a ProviderUserKey which can then be used as a foreign key into the developer's own data tables.
</p><p></p>]]></description>
			<content:encoded><![CDATA[<p>I was recently asked how to use the Membership Data Object to return the unique ProviderKey generated by the Membership object. This may be necessary if want to associate the membership data with an existing table. That is, add a foreign key &quot;ProviderUserKey&quot; to another table so you can track an existing user to your current database without getting involved in extending the base provider. You can of course extend the existing provider to include other fields, but in general, you probably are better off maintaining your own tables rather than extending the provider model. Peter Dawson does an excellent job of explaining and showing how to extend the Membership Provider in his article <a href="http://www.theserverside.net/articles/showarticle.tss?id=CreatingProfileProvider">Creating a Custom ASP.NET Provider. </a>(published on theserverside.net)</p> <span id="more-16"></span>  <p>So, back to what needs to be done to use my Membership ObjectDataClass (<a title="View Details: Microsoft ASP.NET 2.0 Member/Role Management with IIS&lt;br/&gt;Part 2: Implementation" href="http://peterkellner.net/archives/2006/01/09/24/" rel="bookmark">Part 2: Implementation&quot; href=&quot;http://peterkellner.net/archives/2006/01/09/24/&quot; rel=bookmark&gt;Microsoft ASP.NET 2.0 Member/Role Management with IIS</a>    <p>Part 2: Implementation</p> ). First thing is you need to add another insert method to the class. This method takes just a few parameters and returns as out parameters both the status of the insert as well as the providerUserKey as a string.</p>  <br />  <pre class="csharpcode">
[DataObjectMethod(DataObjectMethodType.Insert, <span class="kwrd">false</span>)]
<span class="kwrd">static</span> <span class="kwrd">public</span> <span class="kwrd">void</span> Insert(<span class="kwrd">string</span> userName,
    <span class="kwrd">bool</span> isApproved,
    <span class="kwrd">string</span> email,
    <span class="kwrd">string</span> passwordQuestion,
    <span class="kwrd">string</span> password,
    <span class="kwrd">string</span> passwordAnswer,
    <span class="kwrd">out</span> MembershipCreateStatus membershipCreateStatus,
    <span class="kwrd">out</span> <span class="kwrd">string</span> providerIdKeyString)
{
    MembershipUser muNew = Membership.CreateUser(userName,
        password, email, passwordQuestion, passwordAnswer,
        isApproved,<span class="kwrd">out</span> membershipCreateStatus);
    <span class="kwrd">if</span> (membershipCreateStatus ==
        MembershipCreateStatus.Success)
    {
        providerIdKeyString = muNew.ProviderUserKey.ToString();
    }
    <span class="kwrd">else</span>
    {
        providerIdKeyString = <span class="kwrd">string</span>.Empty;  <span class="rem">// failed</span>
    }
    <span class="kwrd">return</span>;
}</pre>
<br />

<p class="style4">Figure 1 &#8211; The New Insert Method to be added to MembershipUserODS.cs</p>



<p>If you want to turn the Guid passed back into a native Guid type do the following. (this could be useful if you want to retrieve the current username as shown below.</p>

<br />
<pre class="csharpcode">
Guid myNewGuild = <span class="kwrd">new</span> Guid(providerIdKeyString);
MembershipUser myCurrentMembershipUser = Membership.GetUser(myNewGuild);
<span class="kwrd">string</span> memberName = myCurrentMembershipUser.UserName;</pre>
<br />

<p class="style4">Figure 2 &#8211; Example of converting created ProviderUseKey to Guid and retreiving username</p>


<p>Now that we have the new Insert Method defined the easiest thing to do is use it directly. Below is a complete aspx page that references the new method as well as a screen shot of what it looks like to add a new member. Notice that the status label is returning the providerUserKey.</p>

<p><img src="http://peterkellner.net/images/MSDN_Membership/returnkey1.jpg" /></p>

<p><img src="http://peterkellner.net/images/MSDN_Membership/returnkey2.jpg" /></p>

<p class="style4">Figure 3 &#8211; Examples of adding a new user with a valid password, and one without a valid password</p>

<br />
<pre class="csharpcode">
<span class="kwrd">&lt;</span> %@ Page Language="C#" <span class="asp">%&gt;</span>
<span class="kwrd">&lt;</span> !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"<span class="kwrd">&gt;</span>
 
<span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
 
    <span class="kwrd">protected</span> <span class="kwrd">void</span> ButtonNewUser_Click(<span class="kwrd">object</span> sender, EventArgs e)
    {
        MembershipCreateStatus membershipCreateStatus;
        <span class="kwrd">string</span> providerIdKeyString = <span class="kwrd">string</span>.Empty;
        MembershipUtilities.MembershipUserODS.Insert(TextBoxUserName.Text,
            CheckboxApproval.Checked,
            TextBoxEmail.Text,
            TextBoxPasswordQuestion.Text,
            TextBoxPassword.Text,
            TextBoxPasswordAnswer.Text,
            <span class="kwrd">out</span> membershipCreateStatus,
            <span class="kwrd">out</span> providerIdKeyString
        );
        <span class="kwrd">if</span> (membershipCreateStatus == MembershipCreateStatus.Success)
        {
            LabelInsertMessage.Text = <span class="str">"New User Create Successfully.  Key: "</span> + providerIdKeyString;
        }
        <span class="kwrd">else</span>
        {
            LabelInsertMessage.Text = membershipCreateStatus.ToString();
        }
 
        <span class="kwrd">return</span>;
    }
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>
 
<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">="http://www.w3.org/1999/xhtml"</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>Untitled Page<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">="form1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr"> <img src='http://peterkellner.net/wp/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </span> <span class="attr">anel</span> <span class="attr">ID</span><span class="kwrd">="PanelCreateUser"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">BorderColor</span><span class="kwrd">="Black"</span> <span class="attr">BorderWidth</span><span class="kwrd">="1px"</span>
                <span class="attr">Height</span><span class="kwrd">="50px"</span> <span class="attr">Width</span><span class="kwrd">="125px"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">cellpadding</span><span class="kwrd">="3"</span> <span class="attr">cellspacing</span><span class="kwrd">="3"</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">="height: 32px"</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label3"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="UserName"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">="height: 32px"</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">="TextBoxUserName"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">="height: 32px"</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label4"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Password"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">="height: 32px"</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">="TextBoxPassword"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label5"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="PasswordQuestion"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">="TextBoxPasswordQuestion"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label6"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="PasswordAnswer"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">="TextBoxPasswordAnswer"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label2"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Email"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">="TextBoxEmail"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label9"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Approved"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:CheckBox</span> <span class="attr">ID</span><span class="kwrd">="CheckboxApproval"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="kwrd">/&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Button</span> <span class="attr">ID</span><span class="kwrd">="ButtonNewUser"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">OnClick</span><span class="kwrd">="ButtonNewUser_Click"</span> <span class="attr">Text</span><span class="kwrd">="Create New User"</span> <span class="kwrd">/&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="LabelInsertMessage"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
<br />
<p class="style4">Figure 4 &#8211; complete aspx page excercising new insert method</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/01/10/using-membeship-objectdatasource-for-returning-provideruserkey/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 4/13 queries in 0.002 seconds using disk

Served from: peterkellner.net @ 2012-02-04 05:50:16 -->
