tag:blogger.com,1999:blog-47025029574224805592024-03-14T02:01:04.905+08:00Chris Par's - Microsoft .NetChris Par's Blog and it is all about Microsoft .Net, ASP .Net, SQL Server Analysis Service, SQL Server Intergration Services, SQL Server Reporting Service, Pattern and Practises, Web Client Software Factory, and alot more.Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.comBlogger35125tag:blogger.com,1999:blog-4702502957422480559.post-25065582997959863682008-12-20T16:15:00.001+08:002008-12-20T16:15:59.492+08:00Sorting with IComparable and Comparison Delegate on List<T><p>One of the popular generic collection types in .Net 2.0 is List<T>, which we use to store a list of T items. For example, List<Country> stores a list of countries that defined by Country class. It works perfectly to bind the collection to a datasource to be displayed on, for instance drop down or grid view. But you may want the list to be sorted before it is bound to the datasource. Yes, List collection support a method called List<T>.sort() but in order to use sort() method, T must inherit IComparable interface.</p> <p>To read more about this, visit <a title="MSDN: IComparable" href="http://msdn.microsoft.com/en-us/library/system.icomparable(VS.71).aspx" target="_blank">here</a>.</p> <p>So let's take Country as the example. A typical Business Entity will look like:-</p> <pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Country<br /> {<br /> <span class="kwrd">public</span> Country()<br /> {<br /> }<br /><br /> <span class="kwrd">public</span> Country(System.String countryName, System.Int32 id)<br /> {<br /> <span class="kwrd">this</span>.countryNameField = countryName;<br /> <span class="kwrd">this</span>.idField = id;<br /> }<br /><br /> <span class="kwrd">private</span> System.String countryNameField;<br /><br /> <span class="kwrd">public</span> System.String CountryName<br /> {<br /> get { <span class="kwrd">return</span> <span class="kwrd">this</span>.countryNameField; }<br /> set { <span class="kwrd">this</span>.countryNameField = <span class="kwrd">value</span>; }<br /> }<br /><br /> <span class="kwrd">private</span> System.Int32 idField;<br /><br /> <span class="kwrd">public</span> System.Int32 Id<br /> {<br /> get { <span class="kwrd">return</span> <span class="kwrd">this</span>.idField; }<br /> set { <span class="kwrd">this</span>.idField = <span class="kwrd">value</span>; }<br /> }<br />}</pre><br /><br /><p><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style>Next step is to inherit IComparable <a title="MSDN: Interface" href="http://msdn.microsoft.com/en-us/library/87d83y5b.aspx" target="_blank">interface</a>.</p><br /><br /><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Country: IComparable<Country></pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>Once you have inherit the Interface, you are required to implement the definitions. In C#, you can right click on the Interface, and select Implement Interface > Implement Interface. Then the required method will be automatically added to your class. It will look similar to this:-</p><br /><br /><pre class="csharpcode"><span class="preproc">#region</span> IComparable<Country> Members<br /><br /> <span class="kwrd">public</span> <span class="kwrd">int</span> CompareTo(Country other)<br /> {<br /> <span class="kwrd">throw</span> <span class="kwrd">new</span> Exception(<span class="str">"The method or operation is not implemented."</span>);<br /> }<br /><br /><span class="preproc">#endregion</span></pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>Alright, you are almost done with a simple sorting. Now you need to implement the CompareTo method like this:-</p><br /><br /><pre class="csharpcode"><span class="preproc">#region</span> IComparable<Country> Members<br /><br /> <span class="kwrd">public</span> <span class="kwrd">int</span> CompareTo(Country other)<br /> {<br /> <span class="kwrd">return</span> CountryName.CompareTo(other.CountryName);<br /> }<br /><br /><span class="preproc">#endregion</span></pre><br /><br /><p><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style>To test it, simply fill the List<Country> with data and call List<Country>.sort() method. It will automatically sort the list. Now is this what we need? If yes, move on to others. If no, what is the problem? Come to think of it, we may have different comparison in different scenario. For example, we may want to sort by ID in a GridView, and we may want to sort by Name (ASC or DESC) in a drop down box. So we want a more dynamic implementation. </p><br /><br /><p>Here, we need to use <a href="http://msdn.microsoft.com/en-us/library/tfakywbh.aspx" target="_blank">Generic Comparison delegate</a> to provide different comparison methods. We may want to sort by ID or sort by Name in Descending order. Alright, you may simple need to write this:</p><br /><br /><pre class="csharpcode"><span class="preproc">#region</span> Comparison Function<br /><br /> <span class="kwrd">public</span> <span class="kwrd">static</span> Comparison<Country> SortById = <span class="kwrd">delegate</span>(Country c1, Country c2)<br /> {<br /> <span class="kwrd">return</span> c1.Id.CompareTo(c2.Id);<br /> };<br /> <br /> <span class="rem">// Sort by Name in DESC order</span><br /> <span class="kwrd">public</span> <span class="kwrd">static</span> Comparison<Country> SortByName_DESC = <span class="kwrd">delegate</span>(Country c1, Country c2)<br /> {<br /> <span class="kwrd">return</span> c2.CountryName.CompareTo(c1.CountryName);<br /> };<br /><br /><span class="preproc">#endregion</span></pre><br /><br /><p><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style>So with Comparison delegates, you can come out with different kind of comparison to help you sort the list in your own way. The methods are being called in this way:</p><br /><br /><pre class="csharpcode">List<Country> list = <span class="kwrd">new</span> List<Country>();<br /><br />list = GetCountries();<br /><br /><span class="rem">// Default Sorting</span><br />list.sort();<br /><br /><span class="rem">//Sort By ID</span><br />list.sort(Country.SortById);<br /><br /><span class="rem">//Sort By Name DESC</span><br />list.sort(Country.SortByName_DESC);</pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>Done! If the above example does not help to solve your problem, you may want to consider creating a custom comparer class by inheriting from <a href="http://msdn.microsoft.com/en-us/library/system.collections.icomparer.aspx" target="_blank">IComparer</a> interface.</p><br /><br /><p>Cheers.</p> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-32695807944717924142008-12-01T14:59:00.002+08:002008-12-01T15:02:31.761+08:00'Sys' is Undefined. Javascript error when you use AJAX extension<p>You probably will notice a scripting error when using ASP.Net AJAX Extension in your web pages. </p> <p>Error: 'Sys' is undefined.</p> <p>It is due to the ajax extension is not properly registered and configured in your web.config.</p> <p>Solution: </p> <p>There are a few things that you need to have in your web config.</p> <p>1.) Make sure you have add below line to your assembly under <compilation><assemblies></p> <pre class="csharpcode"><span class="kwrd"><</span><span class="html">add</span> <span class="attr">assembly</span><span class="kwrd">="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"</span> <span class="kwrd">/></span></pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>2.) Add following lines under <system.web></p><br /><br /><pre class="csharpcode"><span class="kwrd"><</span><span class="html">httpHandlers</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">add</span> <span class="attr">verb</span><span class="kwrd">="*"</span> <span class="attr">path</span><span class="kwrd">="*.asmx"</span> <span class="attr">validate</span><span class="kwrd">="false"</span> <span class="attr">type</span><span class="kwrd">="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"</span><span class="kwrd">/></span><br /> <span class="kwrd"><</span><span class="html">add</span> <span class="attr">verb</span><span class="kwrd">="GET,HEAD"</span> <span class="attr">path</span><span class="kwrd">="ScriptResource.axd"</span> <span class="attr">type</span><span class="kwrd">="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"</span> <span class="attr">validate</span><span class="kwrd">="false"</span><span class="kwrd">/></span><br /><span class="kwrd"></</span><span class="html">httpHandlers</span><span class="kwrd">></span></pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>3.) Add following line under <system.web><httpModules></p><br /><br /><pre class="csharpcode"><span class="kwrd"><</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">="ScriptModule"</span> <span class="attr">type</span><span class="kwrd">="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"</span><span class="kwrd">/></span></pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>Cheers. This has solve my problem. I hope it does the same to you.</p><br /><br /><p>Some updates from Scott.</p><br /><br /><p><a title="http://weblogs.asp.net/scottgu/archive/2006/10/29/tip_2f00_trick_3a00_-handling-errors-with-the-updatepanel-control-using-asp.net-ajax.aspx" href="http://weblogs.asp.net/scottgu/archive/2006/10/29/tip_2f00_trick_3a00_-handling-errors-with-the-updatepanel-control-using-asp.net-ajax.aspx">http://weblogs.asp.net/scottgu/archive/2006/10/29/tip_2f00_trick_3a00_-handling-errors-with-the-updatepanel-control-using-asp.net-ajax.aspx</a></p>Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-73420569902099581792008-10-14T13:08:00.002+08:002008-10-14T13:13:58.363+08:00Store a type String value into type Guid<p>Sometimes, it is a good practice to use uniqueidentifier data type as your primary key in your database so that it eases your job when you are trying to merge your data from multiple data sources/locations.</p> <p>however, the value is displayed as string in your application and when you want retrieve a data using the uniqueidentifier/Guid, the application will throw an exception because it does not allow you to input string for the type of Guid. Most of the function will look like:</p> <p><em>public MembershipUser GetUserById(object key);</em></p> <p>so if you call below statement will cause you an error:</p> <p><em>MembershipUser user = GetUserById("23c46d23-8459-46fe-9e19-2da6800ef654"); <strong>//wrong</strong></em></p> <p>In fact, you need to use this:</p> <p><em>MembershipUser user = GetUserById(new Guid("23c46d23-8459-46fe-9e19-2da6800ef654")); <strong>//Correct</strong></em></p>Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-58595315216478982762008-10-13T17:54:00.001+08:002008-10-14T13:10:57.143+08:00How to Generate Validation Key and Decryption Key for Encryption<p>Usually when you deal with Membership Provider in ASP.Net, you will need to supply validation key and decryption key manually for Password Format using Hashed or Encryption. AutoGenerate is only valid for Password Format = Clear.</p> <p>before you generate the keys, you have to keep in mind that</p> <p>1.) ValidationKey is 64bit of hex value. So you will require varchar(128).</p> <p>2.) DescryptionKey is 24bit of hex value. So you will require varchar(48).</p> <p>You either choose to assign your own value or use this link to generate a random value for your application.</p> <p><a title="http://www.eggheadcafe.com/articles/GenerateMachineKey/GenerateMachineKey.aspx" href="http://www.eggheadcafe.com/articles/GenerateMachineKey/GenerateMachineKey.aspx">http://www.eggheadcafe.com/articles/GenerateMachineKey/GenerateMachineKey.aspx</a></p>Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-87811765674311612592008-09-05T15:40:00.003+08:002008-09-05T15:44:28.733+08:00Microsoft Popfly (Mashup) SampleRecently, I have created a mashup sample using Microsoft Popfly. Here is a video player that play a list of Youtube videos with the keyword "Mister Cupid".<br /><br /><br /><br /><br /><br /><iframe allowtransparency="true" style="width:700px; height:500px;" frameborder="no" src="http://www.popfly.com/users/chrispar/Youtube-MisterCupid.small"></iframe>Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-63358057292760806622008-08-30T16:48:00.000+08:002008-08-30T17:08:57.504+08:00Cross-Page Posting for handling some combination of user input<blockquote> <p></p> </blockquote> <p>I believe everybody know ASP .Net supports same page Postback function by default. For example, same page posting back to the same page. For those that do not know, ASP .Net 2.0 introduces a new capability whereby pages can post to pages other than themselves. We call this Cross-Page posting and usually it gives a tight coupling for these pages.</p> <p>Now, let's see what we need to create here.</p> <p>Let's use Page 1 as a Posting Page and Page 2 as the Receiving Page.</p> <ol> <li>To create a Cross Page posting, we can use PostbackURL from the button (LinkButton, Button, ImageButton) in Page 1 and point it to Page 2.</li> <pre class="csharpcode"><span class="kwrd"><</span><span class="html">asp:Button</span> <span class="attr">ID</span><span class="kwrd">="Button1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Button"</span> <span class="attr">PostBackUrl</span><span class="kwrd">="~/Page 2.aspx"</span> <span class="kwrd">/></span></pre><br /> <style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /> <li>In Page 2, add a PreviousPageType directive. This will allow you know set your previous page to Page 1.</li><br /><br /> <pre class="csharpcode"><span class="asp"><%@ PreviousPageType VirtualPath="~/Page 1.aspx" %></span></pre><br /> <style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style></ol><br /><br /><blockquote><br /> <p>Or Use TypeName to Class name </p><br /><br /> <pre class="csharpcode"><span class="asp"><%@ PreviousPageType TypeName="_Page_1" %></span></pre><br /></blockquote><br /><br /><p>Above steps will let you set the tight coupling relationship between Page 1 and Page 2 and you can access the properties, control or functions in Page 1 from Page 2. </p><br /><br /><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Page_2 : System.Web.UI.Page<br />{<br /> _Page_1 PostingPage;<br /><br /> <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)<br /> {<br /> <span class="kwrd">if</span> (<span class="kwrd">this</span>.PreviousPage != <span class="kwrd">null</span>)<br /> {<br /> PostingPage = <span class="kwrd">this</span>.PreviousPage;<br /><br /> Label1.Text = PostingPage.Page1_Propertise;<br /> }<br /> <span class="kwrd">else</span><br /> {<br /> Label1.Text = <span class="str">"Previous Page is Null"</span>;<br /> }<br /> }<br /> }</pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>Usually you can use when creating wizard or pages that required tight coupling. You have to set PreviousPageType directive in order to access Page 1 properties.</p><br /><br /><p>Okie now, you might ask how to access a page's properties, control, or function without using PreviousPageType directive. The answer is..you may use Reference directive. Let's create the scenario now.</p><br /><br /><p>Now, we do not want to use PostbackURL at the button in Page 1, instead, we use a normal navigation method.</p><br /><br /><pre class="csharpcode"><span class="kwrd"><</span><span class="html">asp:Button</span> <span class="attr">ID</span><span class="kwrd">="Button1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Button"</span><span class="attr">OnClick</span><span class="kwrd">="Button1_Click"</span> <span class="kwrd">/></span></pre><br /><br /><p><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style>In the Page 1 code behind,</p><br /><br /><pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Button1_Click(<span class="kwrd">object</span> sender, EventArgs e)<br />{<br /> Server.Transfer(<span class="str">"~/Page 2.aspx"</span>);<br />}</pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>Now, we need to add reference in Page 2 so that it can access Page 1 with no problem.</p><br /><br /><pre class="csharpcode"><span class="asp"><%@ Reference Page="~/_Page_1.aspx" %></span></pre><br /><br /><p><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style>By using reference page, you may need to cast your page object like the code below.</p><br /><br /><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Page_2 : System.Web.UI.Page<br /> {<br /> _Page_1 PostingPage;<br /><br /> <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)<br /> {<br /> <span class="kwrd">if</span> (<span class="kwrd">this</span>.PreviousPage != <span class="kwrd">null</span>)<br /> {<br /> PostingPage = (_Page_1)<span class="kwrd">this</span>.PreviousPage;<br /><br /> Label1.Text = ((Label)PostingPage.FindControl(<span class="str">"Label2"</span>)).Text;<br /> }<br /> <span class="kwrd">else</span><br /> {<br /> Label1.Text = <span class="str">"Previous Page is Null"</span>;<br /> } <br /> }<br /> }</pre><br /><br /><p>Now, Questions raised when come to validation and Cross Page posting. If client-side validation (using javascript) is disabled on a web form, the validation will greatly depend on server-side validation. But using PostbackUrl on button will redirect to a new page. Although the server side validation has been in place, the problem is being ignored.</p><br /><br /><p>What you can do here is to use PreviousPage.IsValid() function.</p><br /><br /><p>See the samples below:</p><br /><br /><pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)<br />{<br /> <span class="kwrd">if</span> (PreviousPage != <span class="kwrd">null</span>)<br /> {<br /> <span class="kwrd">if</span> (PreviousPage.IsValid == <span class="kwrd">true</span> )<br /> {<br /> <span class="rem">//Continue</span><br /> }<br /> <span class="kwrd">else</span><br /> {<br /> <span class="rem">//Return to previous page</span><br /> }<br /> }<br />}</pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style>Hope the content helps. Cross Page posting may come handy when you really need a tight coupling pages like Wizards.<br /><br /><p></p><br /><br /><ol><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style></ol> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com1tag:blogger.com,1999:blog-4702502957422480559.post-13684572939159104072008-08-21T12:09:00.001+08:002008-08-21T12:09:51.117+08:00SQL Server FullText Search service could not be started<p>After you have installed SQL Server 2005 on Window Vista, you might find your the service above could not be started, and it returns you error like "the dependency service is missing or marked for future deletion".</p> <p>The problem is that one of the service named "NTLMSSP" does not exist in Window Vista environment. If you want to know better about NTLMSSP, Live-Search it. </p> <p>The solution is simple, install SQL Server SP2 for Vista. Then you will find the dependency service removed.</p> <p>If the problem persisted, DIY method at below:</p> <ol> <li>type in "regedit" in Search to open Registry Editor.</li> <li>Go to HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Services</li> <li>Select msftesql. Check that the display name is SQL Server FullText Search.</li> <li>Find the item named "DependOnService". Right Click -> Modify</li> <li>remove the NTLMSSP from the list and Click Ok</li> <li>Reboot and you can try starting the service again.</li> </ol> <p>Hope it helps.</p> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-78559492999346836302008-08-21T11:52:00.001+08:002008-08-21T11:52:52.232+08:00SQL Server Management Studio missing after installing SQL Server 2005 on Window Vista<p>Sometimes this could happen when you install or reinstall SQL Server on Window Vista. I am not very sure what is the cause of it but it took away 1-3 days to figure out what was wrong with all these. It will be even worst when you find your Business Intelligence Development Studio missing as well. </p> <p>Ok, do not worry about it.</p> <p>What you need to do is</p> <ol> <li>Do not uninstall it.</li> <li>Go to your Microsoft SQL Server folder -> 90 -> Tools. And rename the Tools folder name to Tools-Bak</li> <li>Insert your SQL Server DVD and Browse it.</li> <li>Find a folder named Tools and execute the installer in the folder. It will basically install the missing tools (Management Studio, etc) and Sample Database.</li> <li>if you have problem with the SQL Server instance attaching the sample databases, do not install it else it will bring more headaches to you.</li> <li>Once you have finished installing the tools.. you will find a new Tools folder appear in your Microsoft SQL Server -> 90 folder. </li> <li>Now it should solve your headaches. Do not think it is finished, Apply Service Pack 2. </li> </ol> <p>Hope It helps.</p> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com1tag:blogger.com,1999:blog-4702502957422480559.post-78128652203462751512008-08-07T15:36:00.000+08:002008-08-07T15:37:10.702+08:00How to deploy Silverlight component on IIS<p>When you publish your website to IIS, most probably you will find your xap file copied along into the server. But when you open it in your web browser, you may not be able to see the Silverlight component in your website. There is one thing that you may need to do in order to see it, it is to </p> <p><b>Register your silverlight extension to MIME type</b></p> <p>Go to your IIS, Add MIME type</p> <p>Extension: .xap</p> <p>Application: application/x-silverlight-app</p> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-11824816219520617722008-08-07T15:34:00.001+08:002008-08-07T15:34:50.371+08:00How to integrate Silverlight component into ASP.Net Website<p>To integrate your Silverlight component into ASP.Net Website, all you need is your xap file. You may find it under Bin folder inside your Silverlight project folder. Before you copy it, make sure you have build and compiled it.</p> <p>Steps:</p> <ol> <li>In your Website project, create a folder named “ClientBin”.</li> <li>Copy the xap file from your Silverlight application project into the ClientBin folder.</li> <li>Open your Website project in VS 2008, and include the ClientBin folder into the solution. To include it, you need to open your Solution Explorer, click on the “Show All File” icon, and then right click on the invisible (ClientBin) folder and select “Include In Project”.</li> <li>Then open the web page that you want to insert your silverlight component. </li> <pre class="csharpcode"><span class="rem"><!-- If ASPX page, use ScriptManager and Silverlight control --></span><br /><span class="kwrd"><</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="attr">style</span><span class="kwrd">="height:100%;"</span><span class="kwrd">></span><br /><span class="kwrd"><</span><span class="html">asp:ScriptManager</span> <span class="attr">ID</span><span class="kwrd">="ScriptManager1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">asp:ScriptManager</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">div</span> <span class="attr">style</span><span class="kwrd">="height:100%;"</span><span class="kwrd">></span><br /><span class="kwrd"> <</span><span class="html">asp:Silverlight</span> <span class="attr">ID</span><span class="kwrd">="Xaml1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Source</span><span class="kwrd">="~/ClientBin/Sample.xap" </span><span class="attr">MinimumVersion</span><span class="kwrd">="2.0.30523"</span> <span class="attr">Width</span><span class="kwrd">="100%"</span> <span class="attr">Height</span><span class="kwrd">="100%"</span> <span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">div</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">form</span><span class="kwrd">></span><br /> <br /><span class="rem"><!-- If HTML page, use Object control --></span><br /><span class="kwrd"><</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">="silverlightControlHost"</span><span class="kwrd">></span><br /><span class="kwrd"><</span><span class="html">object</span> <span class="attr">data</span><span class="kwrd">="data:application/x-silverlight,"</span> <span class="attr">type</span><span class="kwrd">="application/x-silverlight-2-b2"</span> <span class="attr">width</span><span class="kwrd">="100%"</span> <span class="attr">height</span><span class="kwrd">="100%"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">param</span> <span class="attr">name</span><span class="kwrd">="source"</span> <span class="attr">value</span><span class="kwrd">="ClientBin/Sample.xap"</span><span class="kwrd">/></span><br /> <span class="kwrd"><</span><span class="html">param</span> <span class="attr">name</span><span class="kwrd">="background"</span> <span class="attr">value</span><span class="kwrd">="white"</span> <span class="kwrd">/></span><br /> <br /> <span class="kwrd"><</span><span class="html">a</span> <span class="attr">href</span>=<span class="attr">http:</span>//<span class="attr">go</span>.<span class="attr">microsoft</span>.<span class="attr">com</span>/<span class="attr">fwlink</span>/?<span class="attr">LinkID</span>=<span class="attr">115261</span> <span class="attr">style</span><span class="kwrd">="text-decoration: none;"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">img</span> <span class="attr">src</span><span class="kwrd">="http://o.microsoft.com/fwlink/?LinkId=108181"</span> <span class="attr">alt</span><span class="kwrd">="Gt Microsoft Silverlight"</span> <span class="attr">style</span><span class="kwrd">="border-style: none"</span><span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">a</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">object</span><span class="kwrd">></span><br /><br /><span class="kwrd"><</span><span class="html">iframe</span> <span class="attr">style</span><span class="kwrd">='visibility:hidden;height:0;width:0;border:0px'</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">iframe</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">div</span><span class="kwrd">></span></pre><br /> <style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /> <li>Verify it by debugging your website project and view the page.</li><br /></ol> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-40726094906996196262008-08-07T15:28:00.001+08:002008-08-07T15:28:49.551+08:00How to control an animation to be on/off at certain time<p>I find this useful when you want to catch your web user’s attention when they are browsing your website. Besides, animation can make your website look more lively and interactive.</p> <p>In this section, I am not going to explain how to create an animation but how to control it to begin and stop in code behind using C#.</p> <p>Before we go there, we need to create an animation in the first place and name it accordingly. You can create an animation easily using <i>Expression Blend</i>. You just have to click on the Add New Storyboard icon under the <i>Objects and Timeline</i> section and it will start recording. You may try to scale up and down an object or change its color. Let’s look at the following screenshot as an example:-</p> <p><a href="http://lh3.ggpht.com/howkuang.par/SJqkKJhYtTI/AAAAAAAAAN0/ROkK8sy2EBw/s1600-h/clip_image002%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="128" alt="clip_image002" src="http://lh4.ggpht.com/howkuang.par/SJqkKsODfkI/AAAAAAAAAN4/OM_7mPeSGXI/clip_image002_thumb.jpg?imgmax=800" width="138" border="0" /></a></p> <p><a href="http://lh6.ggpht.com/howkuang.par/SJqkLdSqXEI/AAAAAAAAAN8/u6uzmFd7TPc/s1600-h/clip_image004%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="133" alt="clip_image004" src="http://lh5.ggpht.com/howkuang.par/SJqkL_ULJZI/AAAAAAAAAOA/gav8Nu5yZbE/clip_image004_thumb.jpg?imgmax=800" width="140" border="0" /></a></p> <p>If you notice it, you may see the “Bip!” text coming out to represent ringing. So how do I set the animation begin time and stop time? The answer is “<i>it depends on how you want it to be</i>”.</p> <p>Okay now, go to your Page.xaml.cs file.</p> <ol> <li>Create a <i>Storyboard</i> object and set it to null under <i>Page</i> class. </li> <pre class="csharpcode">Storyboard PhoneBip = <span class="kwrd">null</span>;</pre><br /> <style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /> <li>Under the <i>Public Page()</i> constructor, instantiate a <i>Storyboard</i> object. </li><br /><br /> <pre class="csharpcode">PhoneBip = <span class="kwrd">new</span> Storyboard();</pre><br /> <style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /> <li><i>PhoneBip</i> object is a new object that does not have any animation set. So now I want to reference it to the one that I have already created in XAML. </li><br /><br /> <pre class="csharpcode">PhoneBip = (Storyboard)<span class="kwrd">base</span>.FindName(<span class="str">"PhoneRing"</span>);</pre><br /> <style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /> <li>I also want to set its behavior to <i>Stop</i> once it has finished the animation. </li><br /><br /> <pre class="csharpcode">PhoneBip.FillBehavior = FillBehavior.Stop;</pre><br /> <style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /> <li>You have done the necessary set-up, you may try to begin the animation.</li><br /><br /> <pre class="csharpcode">PhoneBip.Begin();</pre><br /> <style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /> <li>You may want to start the animation at certain time, then you can use DispatcherTimer object to control the tick count.</li><br /></ol><br /><br /><p>Below is the sample code:-</p><br /><br /><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Page : UserControl<br /> {<br /> Storyboard PhoneBip = <span class="kwrd">null</span>;<br /> DispatcherTimer t = <span class="kwrd">null</span>;<br /> <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">int</span> tickCount = 0;<br /><br /> <span class="kwrd">public</span> Page()<br /> {<br /> InitializeComponent();<br /><br /> PhoneBip = <span class="kwrd">new</span> Storyboard();<br /> PhoneBip = (Storyboard)<span class="kwrd">base</span>.FindName(<span class="str">"PhoneRing"</span>);<br /> PhoneBip.FillBehavior = FillBehavior.Stop;<br /><br /> t = <span class="kwrd">new</span> DispatcherTimer();<br /> t.Interval = TimeSpan.Zero; <br /> t.Tick += <span class="kwrd">new</span> EventHandler(t_Tick); <br /> t.Start();<br /> <br /> }<br /><br /> <span class="kwrd">protected</span> <span class="kwrd">void</span> t_Tick(<span class="kwrd">object</span> sender, EventArgs e)<br /> {<br /> tickCount += 1;<br /> <span class="kwrd">this</span>.Update();<br /> }<br /><br /> <span class="kwrd">private</span> <span class="kwrd">void</span> Update()<br /> {<br /> <br /> <span class="kwrd">if</span> (tickCount > 300)<br /> {<br /> PhoneBip.Begin();<br /> tickCount = 0;<br /> <br /> }<br /> }<br />…</pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-39411535327154583972008-08-07T15:16:00.000+08:002008-08-07T15:22:40.753+08:00How to create a template for a button type with visual states<p>Silverlight allows user to create template for button with visual states. For example let’s look at the following screenshot:</p> <p><a href="http://lh6.ggpht.com/howkuang.par/SJqh9NFTKPI/AAAAAAAAANc/ngYOYhb_MlY/s1600-h/clip_image002%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="82" alt="clip_image002" src="http://lh4.ggpht.com/howkuang.par/SJqh9-qelPI/AAAAAAAAANg/F00ylPShUC4/clip_image002_thumb.jpg?imgmax=800" width="169" border="0" /></a></p> <p>It is an image button that contains customized template. XAML will look like the following</p> <pre class="csharpcode"><span class="kwrd"><</span><span class="html">Button</span> <span class="attr">Height</span><span class="kwrd">="Auto"</span> <span class="attr">Width</span><span class="kwrd">="Auto"</span> <span class="attr">Content</span><span class="kwrd">="Contact"</span> <span class="attr">Margin</span><span class="kwrd">="10,0,10,0"</span> <span class="attr">x:Name</span><span class="kwrd">="Contact"</span> <span class="attr">Template</span><span class="kwrd">="{StaticResource LeftHeader_Top_Contact}"</span> <span class="attr">Cursor</span><span class="kwrd">="Hand"</span> <span class="attr">Click</span><span class="kwrd">="Contact_Click"</span> <span class="kwrd">></span><br /><br />...<br /><br /><span class="kwrd"></</span><span class="html">Button</span><span class="kwrd">></span></pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><h4></h4><br /><br /><ol><br /> <li>To create this using Expression Blend,</li><br /><br /> <li>Drag a button into the page.</li><br /><br /> <li>Select the button, Right Click and Select <i>Edit Control Parts (Template)</i> -> <i>Create Empty</i>.</li><br /><br /> <li>The button is now assigned with an empty template and the XAML will look similar to the code above.</li><br /><br /> <li>In the <i>Edit Template</i> section, you can put in image, text or create animation using visual states.</li><br /><br /> <li>All of the states are remained in Base state, it means no animation. You may want to create a bit of animation during MouseOver state.                                                                        <a href="http://lh6.ggpht.com/howkuang.par/SJqh-kvJ4FI/AAAAAAAAANk/TPXkFdLC77E/s1600-h/clip_image004%5B6%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="321" alt="clip_image004" src="http://lh3.ggpht.com/howkuang.par/SJqh_Lt4u4I/AAAAAAAAANo/FlKFpB-7gts/clip_image004_thumb%5B3%5D.jpg?imgmax=800" width="336" border="0" /></a> </li><br /><br /> <li>To do that, click on the MouseOver state and it will start recording each change into key frame. For e.g Change color, Scale up and down, etc.</li><br /></ol><br /><br /><p><a href="http://lh4.ggpht.com/howkuang.par/SJqiAOR1rgI/AAAAAAAAANs/6lp6Vz8AdL4/s1600-h/clip_image006%5B8%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="484" alt="clip_image006" src="http://lh5.ggpht.com/howkuang.par/SJqiBNHm_NI/AAAAAAAAANw/0D0LQUtMumE/clip_image006_thumb%5B5%5D.jpg?imgmax=800" width="511" border="0" /></a></p><br /><br /><p>Once you have done, click on the Base state to stop recording.</p> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-9458720710550278062008-08-07T15:13:00.000+08:002008-08-07T15:14:00.841+08:00How to create a tooltip with customized style<p>Tooltip is a very useful tool to provide brief information about an object (usually during mouse hover action) in a web application and Silverlight is flexible enough to let you customized its style. In my case, I am using it on image button.</p> <p><a href="http://lh5.ggpht.com/howkuang.par/SJqgtbcZixI/AAAAAAAAANU/dfJmMalv6Aw/s1600-h/clip_image002%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="82" alt="clip_image002" src="http://lh3.ggpht.com/howkuang.par/SJqgt7_hjAI/AAAAAAAAANY/R5AR5FM51Gk/clip_image002_thumb.jpg?imgmax=800" width="169" border="0" /></a></p> <p>By looking at 3 image button above, you may not understand where the buttons will lead you to. Thus, if you are using tooltip, you will know the information about the image button. For example, above image shown a mouse hover action on a “mail-like” icon, and tooltip appeared and shows “Contacts”.</p> <p><u>XAML</u></p> <pre class="csharpcode"><span class="kwrd"><</span><span class="html">Button</span> <span class="attr">Height</span><span class="kwrd">="Auto"</span> <span class="attr">Width</span><span class="kwrd">="Auto"</span> <span class="attr">Content</span><span class="kwrd">="Contact"</span> <span class="attr">Margin</span><span class="kwrd">="10,0,10,0"</span> <span class="attr">x:Name</span><span class="kwrd">="Contact"</span> <span class="attr">Template</span><span class="kwrd">="{StaticResource LeftHeader_Top_Contact}"</span> <span class="attr">Cursor</span><span class="kwrd">="Hand"</span> <span class="attr">Click</span><span class="kwrd">="Contact_Click"</span> <span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">ToolTipService.ToolTip</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">TextBlock</span> <span class="attr">Height</span><span class="kwrd">="Auto"</span> <span class="attr">Width</span><span class="kwrd">="Auto"</span> <span class="attr">Text</span><span class="kwrd">="Contacts"</span> <span class="attr">TextWrapping</span><span class="kwrd">="Wrap"</span> <span class="attr">Style</span><span class="kwrd">="{StaticResource ToolTipStyle}"</span><span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">ToolTipService.ToolTip</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">Button</span><span class="kwrd">></span></pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>Above code shown inheriting a style from a StaticResource named TooltipStyle. To create a Page level style:</p><br /><br /><pre class="csharpcode"><UserControl.Resources><br /> <Style x:Key=<span class="str">"ToolTipStyle"</span> TargetType=<span class="str">"TextBlock"</span>><br /> <Setter Property=<span class="str">"Foreground"</span> Value=<span class="str">"#FF9A9898"</span> /><br /> <Setter Property=<span class="str">"FontSize"</span> Value=<span class="str">"10"</span>/><br /> <Setter Property=<span class="str">"VerticalAlignment"</span> Value=<span class="str">"Bottom"</span>/><br /> <Setter Property=<span class="str">"FontFamily"</span> Value=<span class="str">"Times New Roman"</span>/><br /> </Style><br /><br />…</pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com1tag:blogger.com,1999:blog-4702502957422480559.post-61682035191661695052008-08-07T15:10:00.000+08:002008-08-07T15:11:18.602+08:00How to create shadow<p>Shadow effect gives 3D experience to the user and it greatly increases UX (user experience) during browsing. Unlike WPF, Silverlight does not have a pre-defined object that can create the effect for you. So to create shadow, you may need to create a shape and color it with black.</p> <p><a href="http://lh5.ggpht.com/howkuang.par/SJqgEqloqwI/AAAAAAAAANM/9sYf1YU5py0/s1600-h/clip_image002%5B7%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="34" alt="clip_image002" src="http://lh6.ggpht.com/howkuang.par/SJqgFd66RjI/AAAAAAAAANQ/R8qmQ2PDdvM/clip_image002_thumb%5B4%5D.jpg?imgmax=800" width="244" border="0" /></a></p> <p>Let’s look at the MENU Bar again, when mouse hover over, the menu item will raise and leave a shadow below it. (“About Us”)</p> <p>The shadow is created using Ellipse. XAML looks like this:</p> <pre class="csharpcode"><span class="kwrd"><</span><span class="html">Ellipse</span> <span class="attr">Height</span><span class="kwrd">="4"</span> <span class="attr">x:Name</span><span class="kwrd">="ellipse"</span> <span class="attr">Width</span><span class="kwrd">="50"</span> <span class="attr">Opacity</span><span class="kwrd">="0.5"</span> <span class="attr">RenderTransformOrigin</span><span class="kwrd">="0.5,0.5"</span> <span class="attr">StrokeThickness</span><span class="kwrd">="0"</span> <span class="attr">Margin</span><span class="kwrd">="0,0,0,0"</span> <span class="attr">VerticalAlignment</span><span class="kwrd">="Stretch"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">Ellipse.Fill</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">RadialGradientBrush</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">="#00000000"</span><span class="kwrd">/></span><br /> <span class="kwrd"><</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">="#FFFFFFFF"</span> <span class="attr">Offset</span><span class="kwrd">="1"</span><span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">RadialGradientBrush</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">Ellipse.Fill</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">Ellipse</span><span class="kwrd">></span></pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>*Noticed that I am using a RadialGradientBrush to create the fading effect at the outer area.</p> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-46754591660814150002008-08-07T15:08:00.001+08:002008-08-07T15:08:54.859+08:00How to create a Silverlight Application<h4></h4> <h4>Technology</h4> <p>Technology Used:</p> <ol> <li> <div align="justify">Microsoft Silverlight 2.0 Beta 2</div> </li> <li> <div align="justify">Microsoft Silverlight 2.0 SDK Beta 2</div> </li> <li> <div align="justify">Microsoft Silverlight 2.0 Tools Beta 2 for Visual Studio 2008</div> </li> <li> <div align="justify">Microsoft Expression Blend 2.5 June 2008 Preview</div> </li> <li> <div align="justify">Microsoft Visual Studio 2008</div> </li> <li> <div align="justify">IIS 7</div> </li> </ol> <h3>Implementation</h3> <h4>How to create a Silverlight Application</h4> <p>Silverlight Application can be created in both Visual Studio 2008 and Expression Blend. It can be opened in both programs too.</p> <p><b>Visual Studio 2008</b></p> <p>To create in VS 2008,</p> <ol> <li>Run Visual Studio 2008 (if Win Vista, run as Administrator)</li> <li>Go to <i>File</i> -> <i>New</i> and click on <i>Project</i>.</li> <li>Select <i>Silverlight</i> at the Project Type panel, and then select <i>Silverlight Application</i> at the Template List panel.</li> <li>Noticed that it prompts you a new window with the title “Add a Silverlight Application”, in this window you may select a default settings and it will create a Website Project and a Silverlight Application Project.</li> <li>Build the solution, and you will notice that a file with the extension .xap is created in the <i>ClientBin</i> folder under the website project.<a href="http://lh5.ggpht.com/howkuang.par/SJpzmRC5sCI/AAAAAAAAAMk/whJzu47IiQs/s1600-h/clip_image002%5B8%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="385" alt="clip_image002" src="http://lh3.ggpht.com/howkuang.par/SJpzpfnjWNI/AAAAAAAAAMo/imkTx0hRN80/clip_image002_thumb%5B5%5D.jpg?imgmax=800" width="644" border="0" /></a></li> <li>You can find 2 XAML files under Silverlight Application project. App.xaml is a XAML file that stores application level resources while Page.xaml is a main page that stores the resources and page elements at page level. To View the Page.xaml file, you will see:- <br /></li> </ol> <div class="csharpcode"> <pre class="alt"><span class="kwrd"><</span><span class="html">UserControl</span> <span class="attr">x:Class</span><span class="kwrd">="SilverlightApplication6.Page"</span><br /></pre><br /><br /> <pre> <span class="attr">xmlns</span><span class="kwrd">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span> </pre><br /><br /> <pre class="alt"> <span class="attr">xmlns:x</span><span class="kwrd">="http://schemas.microsoft.com/winfx/2006/xaml"</span> </pre><br /><br /> <pre> <span class="attr">Width</span><span class="kwrd">="400"</span> <span class="attr">Height</span><span class="kwrd">="300"</span><span class="kwrd">></span><br /></pre><br /><br /> <pre class="alt"> <span class="kwrd"><</span><span class="html">Grid</span> <span class="attr">x:Name</span><span class="kwrd">="LayoutRoot"</span> <span class="attr">Background</span><span class="kwrd">="White"</span><span class="kwrd">></span></pre><br /><br /> <pre class="alt"> <span class="kwrd"></</span><span class="html">Grid</span><span class="kwrd">></span></pre><br /><br /> <pre><span class="kwrd"></</span><span class="html">UserControl</span><span class="kwrd">></span></pre><br /><br /> <pre><br /><br /> </pre><br /></div><br /><br /><p><b>Expression Blend</b> </p><br /><br /><p>To create in Expression Blend, </p><br /><br /><ol><br /> <li>Run Expression Blend 2.5 (if Win Vista, run as Administrator.</li><br /><br /> <li>Click on New Project on the start-up menu.</li><br /><br /> <li>You will see 4 options, <i>WPF Application (.exe)</i>, <i>WPF Control Library</i>, <i>Silverlight 1 Site</i>, and<i> Silverlight 2 Application</i>. You need to select <i>Silverlight 2 Application.</i></li><br /><br /> <li>After it is completed, you will see the same file structure as in Visual Studio 2008 but without the website project. If you build and debug it, it will dynamically generate a test page to display the result.<br /> <br /></li><br /></ol><br /><br /><br /><br /><br /><div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:531c331a-2dab-4e00-85a0-00b951e96248" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">del.icio.us Tags: <a href="http://del.icio.us/popular/Silverlight%202" rel="tag">Silverlight 2</a>,<a href="http://del.icio.us/popular/Visual%20Studio%202008" rel="tag">Visual Studio 2008</a></div> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com2tag:blogger.com,1999:blog-4702502957422480559.post-73953487535324687882008-08-07T15:08:00.000+08:002008-08-07T15:08:09.206+08:00How to use Grid Layout to partition the layout of the website<p>Grid Layout is one of the widely used layouts in Silverlight application. It allows the user to partition it into structural grid like TABLE element in HTML. <p>To create columns/rows, user needs to define the columns and rows first under the <i>Grid</i> tag.<pre class="csharpcode"><span class="kwrd"><</span><span class="html">Grid</span> <span class="attr">x:Name</span><span class="kwrd">="LayoutRoot"</span> <span class="attr">Background</span><span class="kwrd">="White"</span><span class="kwrd">></span><br> <span class="kwrd"><</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">></span><br> <span class="kwrd"><</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">="0.5*"</span><span class="kwrd">/></span><br> <span class="kwrd"><</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">="*"</span><span class="kwrd">/></span><br> <span class="kwrd"><</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">="0.5*"</span><span class="kwrd">/></span><br> <span class="kwrd"></</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">></span><br> <span class="kwrd"><</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">></span><br> <span class="kwrd"><</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="0.3*"</span> <span class="kwrd">/></span><br> <span class="kwrd"><</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="*"</span> <span class="kwrd">/></span><br> <span class="kwrd"></</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">></span><br><span class="kwrd"></</span><span class="html">Grid</span><span class="kwrd">></span></pre><br><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt<br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br><pre class="alt"></pre><br><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt<br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br><br><br /><p>The value “*” means the rest of the remaining space but if value like “0.5*”, it works as a percentage. User may also use pixels as value, for e.g. “300”.<br><br /><p>Once you have finished definining the layout, you can assign them to elements. You can imagine them like Array, their index starts with value “0”. The Border element must be inside the Grid tag.<pre class="csharpcode"><span class="kwrd"><</span><span class="html">Border</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="0"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="0"</span><span class="kwrd">></span><br>...<br><span class="kwrd"></</span><span class="html">Border</span><span class="kwrd">></span></pre><br><br /><p>Or if you want to work with RowSpan or ColumnSpan,<pre class="csharpcode"><span class="kwrd"><</span>Border Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2"</pre><br><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt<br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br><br><br /><p>If you do not want to define the columns and spans, the items under the Grid element can overlap each other, and this can give another type of good effect like<br><br /><p><a href="http://lh3.ggpht.com/howkuang.par/SJp7068JG_I/AAAAAAAAAMs/Po7TacSiFxM/s1600-h/clip_image002%5B6%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="216" alt="clip_image002" src="http://lh4.ggpht.com/howkuang.par/SJp72UwUmAI/AAAAAAAAAMw/H2nTgFMRooI/clip_image002_thumb%5B3%5D.jpg?imgmax=800" width="541" border="0"></a><br><br /><p>The above picture shows 3 Border elements under a Grid element.<br><br /><p></p><br><br /><div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f7df76a0-32b5-45b0-a753-1844cfcdd88d" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">del.icio.us Tags: <a href="http://del.icio.us/popular/Silverlight%202" rel="tag">Silverlight 2</a>,<a href="http://del.icio.us/popular/Visual%20Studio%202008" rel="tag">Visual Studio 2008</a></div> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-90337341519625121352008-08-07T15:07:00.000+08:002008-08-07T15:07:48.204+08:00How to use StackPanel Layout to arrange the items<p>StackPanel layout is another one of the widely used layouts but its behavior differs from other layouts. As the name speaks (Stack), it can stack child elements vertically or horizontally. Thus, you can find it neat and you do not need to adjust the position manually.</p> <p><b>Stack Horizontally</b></p> <p>One scenario that I can think of is Horizontal Menu Bar. Let’s look at the sample screenshot below for more feel of it.</p> <p><a href="http://lh4.ggpht.com/howkuang.par/SJp9hm8bUbI/AAAAAAAAAM0/oflifpNPTj8/s1600-h/clip_image002%5B8%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="40" alt="clip_image002" src="http://lh3.ggpht.com/howkuang.par/SJp9i2N5LZI/AAAAAAAAAM4/LQWGJH6T998/clip_image002_thumb%5B5%5D.jpg?imgmax=800" width="644" border="0" /></a></p> <p><u>XAML</u></p> <pre class="csharpcode"><span class="kwrd"><</span><span class="html">StackPanel</span> <span class="attr">Orientation</span><span class="kwrd">="Horizontal"</span> <span class="attr">x:Name</span><span class="kwrd">="stackPanel_Name"</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">="Right"</span> <span class="attr">Margin</span><span class="kwrd">="0,5,0,0"</span><span class="kwrd">></span><br />…<br /><span class="kwrd"></</span><span class="html">StackPanel</span><span class="kwrd">></span></pre><br /><br /><br /><style type="text/css"><br /><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt<br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><br /><br /><br /><br /><br /><br /><p><b>Stack Vertically</b></p><br /><br /><br /><br /><br /><br /><br /><br /><p>I used this quite often when I was creating shadow effect or reflection effect, and it works perfectly. Let’s look at the next screenshot.</p><br /><br /><br /><br /><br /><br /><br /><br /><p><a href="http://lh5.ggpht.com/howkuang.par/SJp9jyJbrUI/AAAAAAAAAM8/vzks6K9awys/s1600-h/clip_image004%5B3%5D.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="50" alt="clip_image004" src="http://lh5.ggpht.com/howkuang.par/SJp9k8M_UTI/AAAAAAAAANA/ZYYazGclhGY/clip_image004_thumb.jpg?imgmax=800" width="213" border="0" /></a></p><br /><br /><br /><br /><br /><br /><br /><br /><p>XAML</p><br /><br /><br /><br /><br /><br /><br /><br /><pre class="csharpcode"><span class="kwrd"><</span><span class="html">StackPanel</span> <span class="attr">Orientation</span><span class="kwrd">="Vertical"</span> <span class="attr">VerticalAlignment</span><span class="kwrd">="Stretch"</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">="Stretch"</span><span class="kwrd">></span><br />…<br /><span class="kwrd"></</span><span class="html">StackPanel</span><span class="kwrd">></span></pre><br /><br /><br /><style type="text/css"><br /><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt<br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><br /><br /><br /><br /><br /><br /><p></p><br /><br /><br /><br /><br /><br /><br /><br /><div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3a933101-3499-4c8d-977e-60810d19f286" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">del.icio.us Tags: <a href="http://del.icio.us/popular/Silverlight%202" rel="tag">Silverlight 2</a>,<a href="http://del.icio.us/popular/Visual%20Studio%202008" rel="tag">Visual Studio 2008</a></div> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-80501620570334300432008-08-07T15:05:00.000+08:002008-08-07T15:06:52.535+08:00How to create reflection on images and objects<p>Different type of objects may have different way to create reflection in Silverlight. If you wish to brush an image, you may need to use ImageBrush object. Or if you need to brush a video, you may need to use VideoBrush. Or otherwise, just duplicate the object, turn it around by using transform. </p> <p>We are going to use the same sample here.</p> <p><a href="http://lh3.ggpht.com/howkuang.par/SJqfCTSPZYI/AAAAAAAAANE/Z2JAc3liO-k/s1600-h/clip_image002%5B3%5D.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="50" alt="clip_image002" src="http://lh5.ggpht.com/howkuang.par/SJqfC9QT5uI/AAAAAAAAANI/W9zLVWUYlJk/clip_image002_thumb.jpg?imgmax=800" width="213" border="0" /></a></p> <p>Inside the StackPanel, the code will look like this</p> <pre class="csharpcode">//Create an Image inside a ContentPresenter<br /><br /><span class="kwrd"><</span><span class="html">ContentPresenter</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">Image</span> <span class="attr">x:Name</span><span class="kwrd">="imgLogo"</span> <span class="attr">Source</span><span class="kwrd">="images/logo.jpg"</span> <span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">Image</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">ContentPresenter</span><span class="kwrd">></span><br /><br />//Create a Rectangle that will use ImageBrush on the jpg file<br /><br /><span class="kwrd"><</span><span class="html">Rectangle</span> <span class="attr">x:Name</span><span class="kwrd">="rectReflect"</span> <span class="attr">Height</span><span class="kwrd">="28"</span> <span class="attr">Width</span><span class="kwrd">="190"</span> <span class="attr">Opacity</span><span class="kwrd">="0.5"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">Rectangle.OpacityMask</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">LinearGradientBrush</span> <span class="attr">EndPoint</span><span class="kwrd">="0.5,1"</span> <span class="attr">StartPoint</span><span class="kwrd">="0.5,0"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">="#00000000"</span> <span class="attr">Offset</span><span class="kwrd">="0.5"</span><span class="kwrd">/></span><br /> <span class="kwrd"><</span><span class="html">GradientStop</span> <span class="attr">Color</span><span class="kwrd">="#FF000000"</span> <span class="attr">Offset</span><span class="kwrd">="1"</span><span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">LinearGradientBrush</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">Rectangle.OpacityMask</span><span class="kwrd">></span><br /><br /> <span class="kwrd"><</span><span class="html">Rectangle.Fill</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">ImageBrush</span> <span class="attr">ImageSource</span><span class="kwrd">="images/logo.jpg"</span> <span class="attr">Stretch</span><span class="kwrd">="Uniform"</span><span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">Rectangle.Fill</span><span class="kwrd">></span><br /><br /> <span class="kwrd"><</span><span class="html">Rectangle.RenderTransform</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">TransformGroup</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">ScaleTransform</span> <span class="attr">CenterY</span><span class="kwrd">="0.5"</span> <span class="attr">ScaleX</span><span class="kwrd">="1"</span> <span class="attr">ScaleY</span><span class="kwrd">="-1"</span><span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">TransformGroup</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">Rectangle.RenderTransform</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">Rectangle</span><span class="kwrd">></span></pre><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style> Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-29886667692890357992008-07-30T16:55:00.003+08:002008-07-31T11:15:54.388+08:00SQL Server 2005 SP2 for Window Vista<p>In order for SQL Server 2005 to run in Window Vista environment, you need to apply SQL Server 2005 Service Pack 2.</p><p>You may find the download page <a title="Microsoft SQL Server 2005 SP2" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=D07219B2-1E23-49C8-8F0C-63FA18F26D3A&displaylang=en" target="_blank" rel="tag">here</a></p><h2>Overview</h2><p><a name="Description"></a>Service Pack 2 for Microsoft SQL Server 2005 is now available. SQL Server 2005 service packs are cumulative, and this service pack upgrades all service levels of SQL Server 2005 to SP2. You can use these packages to upgrade any of the following SQL Server 2005 editions:</p><ul><li>Enterprise </li><li>Enterprise Evaluation </li><li>Developer </li><li>Standard </li><li>Workgroup </li></ul>Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-55852330697466342762008-07-28T22:37:00.003+08:002008-07-30T16:18:57.310+08:00SSAS service couldnt be started after applying SQL Server 2005 SP 2<a href="http://3.bp.blogspot.com/_m_bPMRM-lFc/SJAjNNA418I/AAAAAAAAAMY/5WSKI3Hva5E/s1600-h/RegionalLanguage.jpg"><img id="BLOGGER_PHOTO_ID_5228717877115803586" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_m_bPMRM-lFc/SJAjNNA418I/AAAAAAAAAMY/5WSKI3Hva5E/s320/RegionalLanguage.jpg" border="0" /></a><br /><p>You may find errors when trying to start the Analysis Services service after you have applying SQL Server 2005 Service Pack 2 under Window Vista environment. Usually you will come across it when trying to run the User Provisioning Tool right after the SP2 installation as it requires the services to be started.</p><br /><p>To solve the problem,</p><p>1.) Go to Control Panel->Regional and Language.</p><p>2.) Click on Administrative tab</p><p>3.) Change System Locale to English (United States)</p><p>4.) Click on Copy to Reserved Accounts, and apply it to appropriate accounts.</p><p>5.) Restart your Window and try to start the SSAS service again.</p><p>It should work fine now.</p><p>Cheers </p>Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-15759975763751026762008-07-25T11:36:00.004+08:002008-07-30T16:21:14.798+08:00Repository Factory for VS 2008This has been awhile and Thanks Daniel for pointing it out!! Guys, whoever wanting this for a long time, please visit the link below and leave a comment.<br /><br />Thanks a lot to Ratnakar.<br /><br /><a href="http://ratnakarg.wordpress.com/2008/04/07/repository-factory-for-vs-2008/#comment-52">http://ratnakarg.wordpress.com/2008/04/07/repository-factory-for-vs-2008/#comment-52</a><br /><br />You may also leave a comment here and I can email it to you.<br /><br />CheersChris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-32511158235834613542008-06-23T14:00:00.007+08:002008-07-30T16:31:51.481+08:00Intergrating Web Client Software Factory and Repository FactoryFor those who uses Web Client Software Factory, you may find that it doesnt create a Data Access Layer for you and you might have wasted more than 1 day to write all the data access classes. Thanks to Codeplex, we have a repository factory that handle all them the data access functions for you.<br /><br />If you are new to Repository Factory, please read the <a href="http://chrispar.blogspot.com/2008/06/creating-data-access-layer-using.html">introduction </a>first.<br /><br />In this post, I will explain on how to integrate both of them into a web application to speed up your development as well as to cut down your maintenance cost.<br /><br />First, Create Web Client Software Factory solution, and name it. Let's say "SampleWebApp". WCSF will generate all the default structures and files for ya.<br /><br />Now, right click on the Solution, and Select Add-> New Project. You need to create 3 Class Library projects and name it as following:-<br />1.) Repository.Host<br />2.) Repository.DataAccess<br />3.) Repository.BusinessEntities<br /><br /><span style="font-size:85%;"><blockquote><span style="font-size:85%;">You may want to ask why 3? Good question, usually 1 is<br />sufficient but there are some bugs with the Connection String. Repository<br />Factory requires you to use a project to host the connection string and most of<br />us uses website project to hold the reponsibility, but Connection String couldnt<br />be found by the Repository Factory wizards when we create Business Modules/Views<br />using WCSF first before creating data repository class files. So if you are<br />using 1 Class Library project, make sure you start from repository project<br />first.</span><br /><span style="font-size:85%;"></span><br /><span style="font-size:85%;">Besides, using 3 Class Library projects are alot easier to<br />maintain. For example, when you are creating Data Access or Business Entities,<br />the namespace of the class files will follow the Class Library project name, for<br />instance "Repository". So it will be very messy if Business Entities and Data<br />Access files fall into the same namespace. If you want to split them up in the<br />namespace, it will take some time for you to manually change the namespace of<br />each file into Repository.DataAccess or<br />Repository.BusinessEntities.</span><br /></blockquote></span><br />Next, assign the Reponsibility of each Class Library projects by right click each Class Library projects and select Repository Factory -> specify project responsibility<br />1.) Repository.Host -> Host<br />2.) Repository.DataAccess -> Data Access<br />3.) Repository.BusinessEntities -> Business Entities<br /><br />Now, setup the database:-<br />1.) Create database<br />2.) Create tables<br /><br />You have done all the necessary setup. You may start with :-<br /><br /><strong><u>Create and Assign Connection String</u></strong><br /><em>1.) Connection String for Repository Factory</em><br />Right Click the Repository.Host project, Select Repository Factory -> Add Database Connection<br /><br /><em>2.) Connection String for Website</em><br />Go to the website node, and search for the master web.config. Right Click and Select Repository Factory -> Add Database Connection to Configuration file. Once you have created it, Right Click the web.config and Select Edit Enterprise Library Configuration. Select Data Access Application Block node and open Properties. Assign the default Database to the Connection String that you just created.<br /><br /><strong><u>Create a business module and a page under the module</u></strong><br />Using WCSF, right click Modules section and select Web Client Factory -> Add a Business Module(C#/VB). For example, named it "Member".<br /><br />Under the website node, you will noticed that a Member folder is created. Right Click and select Web Client Factory -> Add a View(C#/VB). Then an aspx page will be created under Member module. To verify it, you will notice that a presenter class file is created along under the Member module node. For instance, "CreateMember.aspx"<br /><br /><strong><u>Create Business Entities</u></strong><br />Go to Repository.BusinessEntities project, right click and select Repository Factory->Create business entities from database. It will prompt you a wizard. Follow the wizards and complete the process.<br /><br />1.) First, select the Host Project, it should be Repository.Host, and the connection string and then Click Next.<br />2.) Then, select the tables that you want.<br />3.) View the attributes and Click Finish.<br /><br />The business entities class files for the tables you want are created under the project.<br /><br /><strong><u>Create Stored Procedure</u></strong><br />Go to Repository.DataAccess project, right click and select Repository Factory->Create CRUD Stored Procedure. Follow through the wizard again.<br /><br />1.) First, select the Host Project, and the connection string and then click next.<br />2.) Select the tables that you want.<br />3.) Then you will notice that the wizard provide 5 common operations for each table. If there is any that you do not need, uncheck the checkbox for the particular operation. Change the SP name if necessary. Then click Next.<br />4.) In the last screen, input a file name. And click Finish.<br /><br />Repository Factory has created a SQL file for you to create the stored procedures. Copy and Paste the script into Management Studio and execute it.<br /><br />Before you execute it, make sure to change all the Alter Procedure to Create Procedure. Click Check and Execute. If there are errors saying procedures' names existed, Change all the Create Procedure back to Alter. Then execute it again.<br /><br />Note that if you are using SQL Server 2000, there are some syntax taht you need to remove, for example, remove<br /><br /><em>begin try, end try, begin catch, end catch, RethrowError procedure</em><br /><br />and replace<br /><br /><em>sys.objects->sysobjects</em><br /><br />Once you have successfully execute the script, you can find all SP in the database. If you want to create a customized SP, you may need to create them manually in the Management Studio.<br /><br /><strong><u>Create Data Repository Classes</u></strong><br />Now it's time to create Data Repository classes. Right Click Repository.DataAccess and select Repository Factory->Create data repository classes from business entities.<br /><br />Go through the wizard again.<br />1.) Select the Host project and connection string and click Next<br />2.) Select the business entities project and click Next<br />3.) Select the entity that you want and click Next<br />4.) Then, in this screen you will find that the wizard has created all the common operations for you except GetBy operations.<br /><br />Auto Created Operations: Insert, Update, Delete, and GetAll<br /><br />5.) Now you need to create GetByPK (Get One) by clicking add, select the right stored proc and check the mapping. if correct click finish.<br />6.)Then you need to create GetByFK (this one usually Get Many) if applicable.<br /><br />I assume you know how to create them. Once you have done, click finish and all the data repository classes will be created.<br /><br />If you want to modify the namespace, you may do so. Else save and build it. Make sure you do not have any error.<br /><br /><span style="color:#ff0000;">NOTE: Do not overwrite any repository classes. Must Remember! Delete it before you copy over.</span><br /><br /><strong><u>Create function to access Data Access Layer</u></strong><br />Go to Module section, look for Member module (if you are working on member module)<br />1.) right click References and select Add References.<br />2.) under the Projects tab, add Repository.BusinessEntities and Repository.DataAccess. (So that you have the reference to those projects and use their fucntions).<br />3.) you will also need to add reference for Microsoft.Practises.Repository.dll into the module references. you can find it in C:/Program Files/Microsoft Patterns & Practices/Data Access Guidance Package Setup/.<br />4.) Open the controller file. In this case, MemberController.cs and insert the following codes:<br /><br /><span style="font-size:85%;"><blockquote><span style="font-size:85%;">using Repository.BusinessEntities;</span><br /><span style="font-size:85%;">using Repository.DataAccess;</span><br /><span style="font-size:85%;">using Repository.DataAccess.MemberRepositoryArtifacts;</span><br /><span style="font-size:85%;"></span><br /><span style="font-size:85%;">//In the MemberController Class, insert the following codes:</span><br /><span style="font-size:85%;"></span><br /><span style="font-size:85%;">IMemberRepository _member;</span><br /><span style="font-size:85%;"></span><br /><br /><span style="font-size:85%;">public void CreateMember(member obj)<br />{<br />_member = new memberRepository();<br />_member.Add(obj);<br />}</span><br /></blockquote></span><br />5.) Save and Close.<br /><br /><strong><u>Create a business function for insert member operation in Presenter</u></strong><br />If you have created a View/Page under Member module, for e.g. CreateMember.aspx, you will notice a CreateMemberPresenter file in the same module under View folder.<br /><br />1.) Open it and if the controller object is commented, uncomment it.<br />2.) Create a function as follow:-<br /><br /><span style="font-size:85%;"><blockquote><span style="font-size:85%;">public void OnCreateMember(member obj)</span><br /><span style="font-size:85%;">{</span><br /><span style="font-size:85%;">_controller.CreateMember(obj);</span><br /><span style="font-size:85%;">}</span><br /></blockquote></span><br /><strong><u>To simulate the outcome</u></strong><br />1.) create a link button in Default.aspx under Member folder in the website node.<br />2.) In the code behind, insert the following codes into the link button OnClick event handler.<br /><br /><span style="font-size:85%;"><blockquote><span style="font-size:85%;">Response.Redirect("/DevelopmentWebsite/Member/CreateMember.aspx");</span></blockquote></span><br />Then, Im going to simulate an insert during a page initialize/load.<br /><br />3.) Open CreateMemberPresenter.cs or vb.<br />4.) Look for the function OnViewInitialized().<br />5.) In the function write the following codes:<br /><br /><br /><span style="font-size:85%;"><blockquote><span style="font-size:85%;">public override void OnViewInitialized()</span><br /><span style="font-size:85%;">{</span><br /><span style="font-size:85%;">member mem = new member();</span><br /><span style="font-size:85%;">// I did not insert value for "id" because it is set auto-increment in the table.</span><br /><span style="font-size:85%;"></span><br /><span style="font-size:85%;">mem.name = "Chris";</span><br /><span style="font-size:85%;">mem.age = 26; </span><br /><span style="font-size:85%;"></span><br /><span style="font-size:85%;">this.OnCreateMember(mem);</span><br /><span style="font-size:85%;">}</span><br /></blockquote></span><br /><strong><u>Finish</u></strong><br />In real project, you may want to supply the data using form or by user input. So you may ignore the Simulate section as it is just to verify the result.<br /><br />Hope it helps.Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com2tag:blogger.com,1999:blog-4702502957422480559.post-5754560171556732862008-06-23T09:58:00.006+08:002008-06-23T13:59:52.511+08:00Performing Insert, Update and Delete using ObjectContainerDataSourceIt is very easy and effective to use <span class="blsp-spelling-error" id="SPELLING_ERROR_0">ObjectContainerDataSource</span> to handle insert, update and delete event. When the user performs an update operations, insert operation, or delete operation in a data-bound control, the data source control raises the following events.<br /><br />C#<br /><br />public event <span class="blsp-spelling-error" id="SPELLING_ERROR_1">EventHandler</span><objectcontainerdatasourcestatuseventargs> Updated;<br />public event <span class="blsp-spelling-error" id="SPELLING_ERROR_2">EventHandler</span><objectcontainerdatasourcestatuseventargs> Inserted;<br />public event <span class="blsp-spelling-error" id="SPELLING_ERROR_3">EventHandler</span><objectcontainerdatasourcestatuseventargs> Deleted;<br /><br />For example, if you are using <span class="blsp-spelling-error" id="SPELLING_ERROR_4">DetailsView</span> and <span class="blsp-spelling-error" id="SPELLING_ERROR_5">ObjectContainerDataSource</span> in your page to create a Insert form,<br /><br />1.) Named your <span class="blsp-spelling-error" id="SPELLING_ERROR_6">ObjectContainerDataSource</span>, like <span class="blsp-spelling-error" id="SPELLING_ERROR_7">MemberDataSource</span><br />2.) Set your <span class="blsp-spelling-error" id="SPELLING_ERROR_8">DataObjectTypeName</span>.<br />3.) Named your Details View, like <span class="blsp-spelling-error" id="SPELLING_ERROR_9">dvCreateMember</span><br />4.) Set the <span class="blsp-spelling-error" id="SPELLING_ERROR_10">DataKeyNames</span>="id" in Details View, most of the time it should be the primary key.<br />5.) Set the <span class="blsp-spelling-error" id="SPELLING_ERROR_11">DataSourceID</span>="<span class="blsp-spelling-error" id="SPELLING_ERROR_12">MemberDataSource</span>" Details View<br />6.) Set the <span class="blsp-spelling-error" id="SPELLING_ERROR_13">DefaultMode</span>="Insert" in Details View<br />7.) In the <span class="blsp-spelling-error" id="SPELLING_ERROR_14">ObjectContainerDataSource</span>, set the <span class="blsp-spelling-corrected" id="SPELLING_ERROR_15">OnInserted</span> event name.<br /><br />Codes will look like this:-<br /><br /><span style="font-size:85%;"><blockquote><span style="font-size:85%;"><br /><div><br /><asp:DetailsView ID="dvCreateMember" DataKeyNames="id" DefaultMode="Insert" runat="server" AutoGenerateRows="False" DataSourceID="MemberDataSource"><br /><Fields><br /><asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /><br /><asp:BoundField DataField="age" HeaderText="Age" SortExpression="age" /><br /><asp:CommandField ButtonType="Button" InsertText="Create" NewText="Add New" ShowInsertButton="True" /><br /></Fields><br /></asp:DetailsView><br /><br /><br /></div><br /><pp:ObjectContainerDataSource ID="MemberDataSource" runat="server" DataObjectTypeName="Repository.BusinessEntities.member" OnInserted="MemberDataSource_Inserted" /></span></blockquote></span>In the Code Behind Page, the event handler function will look like this:-<br /><br /><br /><span style="font-size:85%;"><blockquote><p><span style="font-size:85%;">using Microsoft.Practices.Web.UI.WebControls;</span></p><p><span style="font-size:85%;">protected void MemberDataSource_Inserted(object sender,<br />ObjectContainerDataSourceStatusEventArgs<br />e)<br />{<br />_presenter.onCreateMember((member)e.Instance);<br />}</span></p></blockquote></span><br />The data that inserted into the details view will be automatically stored into the e.instance when it is passed to ObjectContainerDataSource. Hence, there is no need to have extra code to map the data from UI to back end codes.<br /><br />Noticed that there is a function onCreateMember() being called in the Inserted event. It is the function defined in Presenter Layer.<br /><br /><blockquote>### Presenter Class File###</blockquote><br /><br /><span style="font-size:85%;"><blockquote><span style="font-size:85%;">public void onCreateMember(member<br />obj)<br />{<br />_controller.CreateMember(obj);<br />}</span></blockquote></span><br />And, CreateMember() function is defined in Controller layer.<br /><br /><blockquote>###Controller Class File###</blockquote><br /><br /><span style="font-size:85%;"><blockquote><span style="font-size:85%;">public void CreateMember(member obj)<br />{<br />_member = new memberRepository();<br />_member.Add(obj);<br />}</span></blockquote></span><br />In the above function, it is call the add function from Data Access layer. You may use Repository Factory to generate those.Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-50676417573954269032008-06-20T16:47:00.009+08:002008-06-23T09:57:05.622+08:00ObjectContainerDataSource in Web Client Software FactoryThe Web Client Software Factory contains the data source control ObjectContainerDataSource. This control implements data binding in a way that easily integrates with the View-Presenter pattern.<br /><br />You can think of the ObjectContainerDataSource control as a container of objects. You programmatically populate the container, and the container raises events when changes occur to any of the contained objects. This design allows the view (Web page) to delegate the responsibility of performing select operations, update operations, delete operations, and insert operations to the presenter.<br /><br /><strong><u>How to Use ObjectContainerDataSource?</u></strong><br /><br />To add ObjectContainerDataSource controll into the toolbox:<br /><em><span style="font-size:85%;">right-click the Data tab in the Toolbox, and then select Choose Items. On the .NET FrameworkComponents tab, click Browse, select the Microsoft.Practices.Web.UI.WebControls.dll assembly, and then click Open. Select the ObjectContainerDataSource control in the list of components, and then click OK.</span></em><br /><br />to use it, Drag and drop the control into the UI. Then<br />1.) Go into Design Mode and click on the Show Smart Tag, and select Configure Data Source..<br />2.) Noticed that you need to specify a Data Object Type. Select an appropriate object.<br />3.) Named the container. for instance, MemberDataSource.<br /><br />For example, to show items when view loads:-<br />1.) First create a property for set operation in the page code behind.<br /><br /><blockquote>Public IList<member> memberDS<br />{<br />set { MemberDataSource.DataSource = value};<br />}<br /></blockquote><br /><br />2.)To be visible in Presenter, Open IMemberView in the Member module and add a definition as following:<br /><br /><br /><blockquote>IList<member> memberDS {set;}</blockquote><br /><br />3.) go to MemberPresenter, inside the OnViewInitialized method, put this the code.<br /><br /><blockquote>This.View.memberDS = data... ;</blockquote><br /><br />4.) In the page, drag and drop a Grid View, and set its data source attribute to MemberDataSource.Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0tag:blogger.com,1999:blog-4702502957422480559.post-12431832001437110302008-06-20T15:46:00.003+08:002008-06-20T16:42:35.442+08:00Business Module, Foundation Module and Page in Web Client Software Factory v1.1Dear all,<br /><br />It has been some time I have not posted anything about web client software factory as I was busy with my rl work. Web Client Software Factory is my favourite tool when creating a web client. I suggest everybody should give a try on it.<br /><br />Recently, I have given a sharing session about Web Client Software Factory for a bunch of interns who are about to graduate from university (Multimedia University) and I realized I should continue writing more about it so that it can help others to get more details on what exactly WCSF does.<br /><br />If you do not know what Web Client Software Factory is, please visit Introduction to <a href="http://chrispar.blogspot.com/2008/03/1.html">Web Client Software Factory</a> post to have some kick starts. Web Client Software Factory uses Model-View-Presenter architectural pattern to encourage reuse of the individual User Controls (referred to in CAB as "SmartParts") by not coupling them with their underlying data elements or presentation code.<br /><br />The structure will look like this:<br /><br />Page <--> Presenter <--> Controller<br /><br />In this post, I will cover a few essential fundamentals about WCSF.<br />1.) Business Modules<br />2.) Foundational Modules<br />3.) Page/View<br /><br /><strong><u>1.0 What is a Business Modules?</u></strong><br />Business Module is a type of Module that encapsulate a set of concerns of the application at Module Level. The logics created in a particular business module will be shared accross the module. When a user create a business module in WCSF, a default web page will be created under the website node in the module name's folder.<br /><br /><strong>Files Created by WCSF:-</strong><br /><em>Website Node:</em> a folder named as the module name which contains a web.config, Default.aspx and Default.aspx Code Behind.<br /><em>Module Node:</em> a folder named as the module name which contains a Presenter Class file for Default.aspx, and View Interface for Default.aspx, Controller Class file and ModuleIntializer Class file.<br /><br /><strong><u>1.1 How to Create a Business Modules</u></strong><br />To Create a Business Module, select the MODULE node and right Click. You will notice a menu item named "Web Client Factory". Click on it and Select "Add Business Module (C# or VB)".<br /><br />An add business module wizard will appear:-<br />1.) Add New Project: Give a name to the module and give a path(if it is different from the default).<br />2.) Module Details: Check the checkbox for Unit Test if you require it.<br />3.) Click Finish.<br />4.) Debug it and you will notice a new menu named as the module name added into the website.<br /><br /><strong><u>2.0 What is Foundational Module</u></strong><br />It is quite similar to Business Module, but it does not allow you to create Page/View under this module. Which means, Foundational Module does not have Presenters nor have Controller. It also will not create a folder with default page in the website node like how Business Module does. The set of concerns that encapsulate in this type of module is shared across the whole application. Usually, Global services are created in this module and each application will have only 1 foundational module.<br /><br /><strong><u>2.1 How to create a Foundational Module</u></strong><br />To Create a Foundational Module, select the MODULE node and right Click. You will notice a menu item named "Web Client Factory". Click on it and Select "Add Foundational Module (C# or VB)".<br /><br />An add foundational module wizard will appear:-<br />1.) Add New Project: Give a name to the module and give a path(if it is different from the default).<br />2.) Module Details: Check the checkbox for Unit Test if you require it.<br />3.) Click Finish and Verify it at the MODULE node.<br /><br /><u><strong>3.0 What is a Page/View</strong></u><br />Page is a web page so it has .aspx extension and a Code Behind Class file. User can add UI elements to a page.<br /><br /><strong><u>3.1 How to Create a Page</u></strong><br />To create a page, you need to consider which business module it belongs to. For instance, a CreateMember.aspx will fall into Member module or it is directly under the root node (Website node).<br />1.) Right click on the module folder under the website node or right click on the root node<br />2.) Select "Web Client Factory" and Click on Add a View(C#/VB).<br /><br />a Wizard will be appeared and Change the name for the particular View and click Finish.<br /><br />You will notice that (for e.g CreateMember) a CreateMember.aspx created under the Member folder(if it is created in Member folder), and under the Member module, CreateMemberPresenter and ICreateMemberView are created.<br /><br />I hope this will give you more understanding on how Web Client Software Factory does.Chris Parhttp://www.blogger.com/profile/00757434122032023339noreply@blogger.com0