tag:blogger.com,1999:blog-30554207311153902012024-03-13T05:01:48.595+05:30Good? Bad? Who knows?Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-3055420731115390201.post-48423417595126895072018-07-26T16:37:00.000+05:302018-08-03T16:39:57.642+05:30Install Visual Studio 2015 after 2017<div style="text-align: justify;">
When working with different projects at <a href="https://www.99xtechnology.com/">99X Technology</a>, sometimes you may have to adjust your development environment accordingly.</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6mFQCZpWqHVXbHnKsWMVb5yA0FmR_FzYVXOb9ubYeC0yGKjPtEUCAoxmuJPoDW6cHbcWUchJE65CJoKp3y5_MTYiVmac34d2nt2JdTUvmlD7teK3ltfQG_zPbCsTy4UGJSVtjJcnOS1k/s1600/VS2015.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="644" data-original-width="460" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6mFQCZpWqHVXbHnKsWMVb5yA0FmR_FzYVXOb9ubYeC0yGKjPtEUCAoxmuJPoDW6cHbcWUchJE65CJoKp3y5_MTYiVmac34d2nt2JdTUvmlD7teK3ltfQG_zPbCsTy4UGJSVtjJcnOS1k/s400/VS2015.PNG" width="285" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Presently I'm working with the <a href="https://www.compello.com/">Compello</a> team, develops and delivers solutions for EDI, eInvoice and Invoice Approval. I had to work on a product that developed in Visual Studio 2015. I had already installed Visual Studio 2017 development environment but it was not supported by the product due to some C++ dependencies. Further, team was still not decided to migrate the product to 2017. Therefore I had to install Visual Studio 2015 top of 2017 without knowing the consequence. I have Windows 10 in my development environment and noticed that the Visual Studio 2015 setup was stuck middle of the installation. Therefore I had to cancel the installation forcefully. </div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Noticed that my operating system is getting slower after this incident. Fortunately I was able to restore the OS to the previous state with a restore point created before Visual Studio 2015 installation. When I searched on this further, found that some <a href="https://msdn.microsoft.com/en-us/library/ms246609.aspx">articles</a> says this is possible but not recommended. For me it did not work and had to uninstall 2017 and then install 2015.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Lesson learned from this was it is recommend to install Visual Studio versions in the order in which they were released. If you are trying it other way round, better to create a <a href="https://www.windowscentral.com/how-use-system-restore-windows-10">restore point</a> and so that we can restore the operating system to the stable state if something goes wrong. </div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.com0Colombo, Sri Lanka6.9270786 79.8612430000000596.8009751 79.69988150000006 7.0531821 80.022604500000057tag:blogger.com,1999:blog-3055420731115390201.post-19894199022784295922011-10-09T15:10:00.000+05:302011-10-09T15:13:06.099+05:30Problem with Using SharePoint Lookup Columns in Word DocumentsDocument properties give you a rich user experience to maintain SharePoint metadata in word documents. You can create a document content type based word templates and add SharePoint metadata to it through the Quick Parts (in Ribbon go to: Insert ► Quick Parts ► Document Properties) easily.<br />
<br />
One of the <a href="http://www.blogger.com/www.puzzlepart.com">puzzlepart</a> assignment, I had an issue on maintaining lookup fields in word templates. Lookup fields are displayed as dropdown in word template. The issue was some of the items were missing in the dropdown (which is available in lookup list). When I investigated it I found that the dropdown item count decided based on the default view of the lookup list. <br />
<br />
For an example if the default view restricted to display 100 items, then in dropdown shows only 100 items. Same way you can configure the filtering or sorting order in the default view of the lookup list if you want to filter out or sort the items in word template dropdown lookup.Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.com1tag:blogger.com,1999:blog-3055420731115390201.post-70131036589315964422011-02-20T13:58:00.004+05:302011-02-20T18:19:07.052+05:30How to Set SharePoint People Picker Default Value to Current User through JavaScriptWith the common SharePoint field types you can specify “[Me]” in the default value property to set the current logged in user. But for the <b>Person or Group field</b> type they haven’t enable this feature. This is a common requirement and I needed to find a good standard approach.<br />
<br />
<b>We can achieve this in two scenarios:</b><br />
<ol><li><b>After the list item save:</b> We can trigger a workflow and programmatically set the logged in user to the field</li>
<li><b>Before the list item save:</b> We can modify the <i>list item add new form</i> page to set the current logged in user using JavaScript</li>
</ol>In my case, the requirement was second scenario and this blog post is mainly focused on that.<br />
<br />
If we are modifying the list item add new form page to achieve this, we need to consider two things:<br />
<br />
<b>How to get the current user information in SharePoint context via JavaScript</b><br />
<br />
For this I had to refer <a href="http://praveenbattula.blogspot.com/2010/02/sharepoint-2010-client-object-model.html">SharePoint 2010 - Client Object Model</a> and <a href="http://praveenbattula.blogspot.com/2010/02/sharepoint-2010-ecmascript-how-to-know_26.html">how to get the logged in user information using SharePoint JavaScript api</a>.<br />
<br />
<b>How to set the value to the People Picker control</b><br />
<br />
I found the post on <a href="http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx">how to manipulate a list form fields using JavaScript</a> but it doesn’t mention how to do it for the People Picker control. Unlike other form fields we can’t uniquely identify the People Picker control in html markup (Other form fields can be identified by the <b>title</b> attribute. Title attribute has set to the field name of list item). Therefore in my approach I had to know the parent element of the People Picker control to identify the People Picker control.<br />
<br />
I have bundled this functionality to a JavaScript class and we can reuse it whenever needed. One thing that I learned working with <a href="http://puzzlepart.com/">Puzzlepart</a> team was you must simplify your implementation as much as possible and isolate it in a generic manner that we can reuse it other places. <br />
<br />
<b>PeoplePicker Class</b><br />
<pre class="csharpcode"><span class="kwrd"><</span><span class="html">script</span> <span class="attr">type</span><span class="kwrd">="text/javascript"</span><span class="kwrd">></span>
<span class="kwrd">function</span> PeoplePicker(){
<span class="kwrd">this</span>.context = <span class="kwrd">null</span>;
<span class="kwrd">this</span>.web = <span class="kwrd">null</span>;
<span class="kwrd">this</span>.currentUser = <span class="kwrd">null</span>;
<span class="kwrd">this</span>.parentTagId = <span class="kwrd">null</span>
<span class="kwrd">this</span>.SetParentTagId = <span class="kwrd">function</span>(id){
<span class="kwrd">this</span>.parentTagId = id;
}
<span class="kwrd">this</span>.SetLoggedInUser = <span class="kwrd">function</span>(){
<span class="kwrd">if</span>(<span class="kwrd">this</span>.parentTagId != <span class="kwrd">null</span>){
<span class="kwrd">this</span>.getWebUserData();
}
}
<span class="kwrd">this</span>.getWebUserData = <span class="kwrd">function</span>(){
<span class="kwrd">this</span>.context = <span class="kwrd">new</span> SP.ClientContext.get_current();
<span class="kwrd">this</span>.web = <span class="kwrd">this</span>.context.get_web();
<span class="kwrd">this</span>.currentUser = <span class="kwrd">this</span>.web.get_currentUser();
<span class="kwrd">this</span>.currentUser.retrieve();
<span class="kwrd">this</span>.context.load(<span class="kwrd">this</span>.web);
<span class="kwrd">this</span>.context.executeQueryAsync(Function.createDelegate(<span class="kwrd">this</span>, <span class="kwrd">this</span>.onSuccessMethod),
Function.createDelegate(<span class="kwrd">this</span>, <span class="kwrd">this</span>.onFailureMethod));
}
<span class="kwrd">this</span>.onSuccessMethod = <span class="kwrd">function</span>(){
<span class="kwrd">this</span>.setDefaultValue(<span class="kwrd">this</span>.currentUser.get_title());
}
<span class="kwrd">this</span>.onFailureMethod = <span class="kwrd">function</span>(){
alert(<span class="str">'request failed '</span> + args.get_message() + <span class="str">'\n'</span> + args.get_stackTrace());
}
<span class="kwrd">this</span>.setDefaultValue = <span class="kwrd">function</span>(value){
<span class="kwrd">var</span> parentTag = document.getElementById(<span class="kwrd">this</span>.parentTagId);
<span class="kwrd">if</span> (parentTag != <span class="kwrd">null</span>) {
<span class="kwrd">var</span> peoplePickerTag = <span class="kwrd">this</span>.getTagFromIdentifierAndTitle(parentTag, <span class="str">'div'</span>,
<span class="str">'UserField_upLevelDiv'</span>, <span class="str">'People Picker'</span>);
<span class="kwrd">if</span> (peoplePickerTag) {
peoplePickerTag.innerHTML = value;
}
}
}
<span class="kwrd">this</span>.getTagFromIdentifierAndTitle = <span class="kwrd">function</span>(parentElement, tagName, identifier, title){
<span class="kwrd">var</span> len = identifier.length;
<span class="kwrd">var</span> tags = parentElement.getElementsByTagName(tagName);
<span class="kwrd">for</span> (<span class="kwrd">var</span> i = 0; i < tags.length; i++) {
<span class="kwrd">var</span> tempString = tags[i].id;
<span class="kwrd">if</span> (tags[i].title == title && (identifier == <span class="str">""</span> ||
tempString.indexOf(identifier) == tempString.length - len)) {
<span class="kwrd">return</span> tags[i];
}
}
<span class="kwrd">return</span> <span class="kwrd">null</span>;
}
}
<span class="kwrd"></</span><span class="html">script</span><span class="kwrd">></span>
</pre><b>Now you can reuse this in your aspx markup:</b><br />
<pre class="csharpcode"><span class="kwrd"><</span><span class="html">asp:Content</span> <span class="attr">ContentPlaceHolderId</span><span class="kwrd">="PlaceHolderMain"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">sharepoint:scriptlink</span> <span class="attr">localizable</span><span class="kwrd">="false"</span> <span class="attr">name</span><span class="kwrd">="SP.js"</span> <span class="attr">ondemand</span><span class="kwrd">="true"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">script</span> <span class="attr">type</span><span class="kwrd">="text/javascript"</span><span class="kwrd">></span>
ExecuteOrDelayUntilScriptLoaded(SetWebUserData, <span class="str">"sp.js"</span>);
<span class="kwrd">function</span> SetWebUserData() {
<span class="kwrd">var</span> pplPicker = <span class="kwrd">new</span> PeoplePicker();
<span class="rem">// Set the parent tag id of the people the picker.</span>
pplPicker.SetParentTagId(<span class="str">'ctl00_UserField_containerCell'</span>);
pplPicker.SetLoggedInUser();
}
<span class="kwrd"></</span><span class="html">script</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:Content</span><span class="kwrd">></span></pre><style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New", Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.com19tag:blogger.com,1999:blog-3055420731115390201.post-8973676129248318572010-09-25T13:31:00.005+05:302010-09-25T13:46:21.436+05:30Set Styles on Gaia Window Control<div style="text-align: justify;">Recently I had to use one of the coolest controls of <a href="http://gaiaware.net/">Gaia</a>, the <a href="http://samples.gaiaware.net/Extensions/Window/Overview">Window control</a> which mimics the behavior of a normal desktop Window within the web page. I had some issues with that, when it came to set styles on the layout of the window. They haven’t properly documented about that.</div><br />
<div style="text-align: justify;">Using <a href="http://getfirebug.com/">Firebug</a> I analyzed the html markup, that rendered by the window control and got to know that you need to maintain separate CSS classes with predefined suffixes (defined by <a href="http://gaiaware.net/">Gaia</a> team) for each main content areas in the window.</div><br />
<div style="text-align: justify;">For an example if you set the Window <b>CssClass</b> property to “<b>update-line</b>”, then you need to create below CSS classes with predefined suffixes to style the Window layout (only the main content areas described here) </div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtJp7sd0gWU7ilqCc0PZFCmMrOdo1iljDEO8GmfexSQRLyEbyYsfK-Gg09xqrqCiJIzsUEr7foHY-7XIfACwNSfhwWy6HDVx_4384DZ5YIph3h52r0iQNtXmSY0CH3gAdxLUUuns-U1g8/s1600/window-markup.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtJp7sd0gWU7ilqCc0PZFCmMrOdo1iljDEO8GmfexSQRLyEbyYsfK-Gg09xqrqCiJIzsUEr7foHY-7XIfACwNSfhwWy6HDVx_4384DZ5YIph3h52r0iQNtXmSY0CH3gAdxLUUuns-U1g8/s1600/window-markup.png" /></a></div><div><table border="0" cellpadding="0" cellspacing="0" style="height: 100px; width: 450px;"><tbody>
<tr style="font-weight: bold;"> <td><br />
<b>Area</b></td> <td><br />
<b>Suffix</b></td> <td><br />
<b>CSS Class Example</b></td> </tr>
<tr> <td><br />
Whole window</td> <td><br />
"-window"</td> <td><br />
update-line-window</td> </tr>
<tr> <td><br />
Content area</td> <td><br />
"-window-content"</td> <td><br />
update-line-window-content</td> </tr>
<tr> <td><br />
Caption area</td> <td><br />
"-window-top"</td> <td><br />
update-line-window-top</td> </tr>
</tbody></table></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4dVN88-eNbhPPsEvzaQ8BtkOIwmlG6y76IL3_TemB69ccvwLCc2Wqg8eIA48zKfEtZjrwcnnOnbV2fwqOIH3L39_cmY18pbw3xo5omkVzlOfvjXYniukF-W57mrq17neRI63uYStS8EI/s1600/gaiax-window.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4dVN88-eNbhPPsEvzaQ8BtkOIwmlG6y76IL3_TemB69ccvwLCc2Wqg8eIA48zKfEtZjrwcnnOnbV2fwqOIH3L39_cmY18pbw3xo5omkVzlOfvjXYniukF-W57mrq17neRI63uYStS8EI/s1600/gaiax-window.png" /></a></div><div class="separator" style="clear: both; text-align: center;"></div>Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.com0tag:blogger.com,1999:blog-3055420731115390201.post-80654164308001884092010-09-17T20:49:00.004+05:302010-09-17T20:59:26.023+05:30Outlook 2010 Quick Steps FeatureRecently I have upgraded my MS Office package to 2010 and it was really cool. The Quick Steps feature that comes with the Outlook 2010 made me easier to manage my mail inbox. This feature allows you to create single-click links to perform tasks that normally require multiple steps. In my case I used this to move my emails to specific folders that I have organized in my mail box. For an example if you need to move your office related emails to the “Office” folder once you have read that. You can setup a single-click link for this and it’ll be visible in Ribbon’s Home tab in your Outlook.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_MkW9Onapej_nrtl69MFVsL5WYwXp6SB-RzjT-f25nB0XtA503Q2__eb6y3ceidZg6UapiDjuu8RpwvuSgX4LADu3MMHlK5K5NXzlolpf-kR9V3b-4lASYrf0ezljOYGQHul3MRVk1ug/s1600/Outlook.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="170" qx="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_MkW9Onapej_nrtl69MFVsL5WYwXp6SB-RzjT-f25nB0XtA503Q2__eb6y3ceidZg6UapiDjuu8RpwvuSgX4LADu3MMHlK5K5NXzlolpf-kR9V3b-4lASYrf0ezljOYGQHul3MRVk1ug/s640/Outlook.png" width="640" /></a></div><br />
Currently at <a href="http://www.eurocenterddc.com/">office</a> I’m using two email accounts. One is for the <a href="http://www.eurocenterddc.com/">office</a> related work and the other one for the <a href="http://www.puzzlepart.com/">customer</a> related work. Coolest thing is based on your mail box, the single-click links will be changed on the Ribbon section.<br />
<br />
For more Office 2010 features - <a href="http://blogs.techrepublic.com.com/10things/?p=900">10 Things</a>Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.com0tag:blogger.com,1999:blog-3055420731115390201.post-16386534437677173732010-09-02T20:55:00.010+05:302010-09-03T08:04:40.763+05:30Decorator PatternCurrent <a href="http://www.puzzlepart.com/">project</a> we are working on, they heavily used <a href="http://en.wikipedia.org/wiki/Design_pattern">design patterns</a> in their codebase and when it comes to do the modifications and new enhancements, we must have a good understanding on how the <a href="http://en.wikipedia.org/wiki/Design_pattern">design patterns</a> behave and how we can apply in a real world situation to make it more maintainable and optimizable codebase.<br />
<br />
Therefore recently I started to do some research on this and got a clear understanding on the <b>Decorator</b> design pattern initially.This pattern is quite useful when you need to extend an object’s behavior dynamically. This ability to dynamically attach new behavior to objects is done by a <b>Decorator </b>class that wraps itself around the original class.<br />
<br />
Following example illustrates the usage of the <b>Decorator </b>pattern and the way I illustrated the example was bit funny and it was an incident recently I experienced.<br />
<br />
<b style="color: #e06666;">Let’s</b> take a real world entity called <b>Girl </b>for this example. Every girl has a unique feature <b>Smile</b>. So we can create an interface for the <b>Girl</b>, that specifying we need to implement the <b>Smile</b>:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4HozVrfXHZmbBRLaEwuU2PdMFABMIAiLsSwsLPRPg8laPZZHabO0X0KScOKEk3PWrkU4wqrcIQUEtYH1C8fDqrJhy2mMI2Q-owPy0pPIkkB4GfdbdaV_cwRWtKtVqmQNycQqwh5lCMP8/s1600/Interface.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="120" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4HozVrfXHZmbBRLaEwuU2PdMFABMIAiLsSwsLPRPg8laPZZHabO0X0KScOKEk3PWrkU4wqrcIQUEtYH1C8fDqrJhy2mMI2Q-owPy0pPIkkB4GfdbdaV_cwRWtKtVqmQNycQqwh5lCMP8/s640/Interface.png" width="640" /></a></div><br />
Now we can create an Office girl (<i>concrete class</i>) using the <b>Girl </b>interface and implement the <b>Smile </b>for the Office girl.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhd8RadszdmGZHJ0s9J-9qdHpWZhancdBEQ8grUXSflf-BIKVL8P3X_86TozbXRsoaIs3k6dFoU_G4YH6XK4W_0murYMNhOH7KQ7Lmb1vM4wCmWsACa4EMkfveuzaWz4eMWbZRGLyBa4-4/s1600/OfficeGirl.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="468" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhd8RadszdmGZHJ0s9J-9qdHpWZhancdBEQ8grUXSflf-BIKVL8P3X_86TozbXRsoaIs3k6dFoU_G4YH6XK4W_0murYMNhOH7KQ7Lmb1vM4wCmWsACa4EMkfveuzaWz4eMWbZRGLyBa4-4/s640/OfficeGirl.png" width="640" /></a></div><br />
Following creates an instance from <b>OfficeGirl </b>and check the <b>Smile</b>:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmwfYgAg1kAkXm6IBALNErnWTeM7Em5BceT-hqFQso-5j1n6AXq_0tAyvbV-6Jjl1nawEM1hWEz_w7uws4-f8rBGv0bYfoeOOXuTBXmZMev6ZM4hGABY2yW_ZcQxHySV1TpYO-p7fkUtw/s1600/Test1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmwfYgAg1kAkXm6IBALNErnWTeM7Em5BceT-hqFQso-5j1n6AXq_0tAyvbV-6Jjl1nawEM1hWEz_w7uws4-f8rBGv0bYfoeOOXuTBXmZMev6ZM4hGABY2yW_ZcQxHySV1TpYO-p7fkUtw/s640/Test1.png" width="640" /></a></div><br />
The output would be:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ1q7OU0PPayC93c0a1u2B4U42S_LHr5kLeOC-mPTK6GssMmxEgzRaT3PJE_Rc-97PdLXZFqIxLx0STqFmzUgY7kk-E60IWbV9t7bLDGUpaytqzZXskozcsJvy_Wma4IrVAyzJxfu7cOk/s1600/Output1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="142" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ1q7OU0PPayC93c0a1u2B4U42S_LHr5kLeOC-mPTK6GssMmxEgzRaT3PJE_Rc-97PdLXZFqIxLx0STqFmzUgY7kk-E60IWbV9t7bLDGUpaytqzZXskozcsJvy_Wma4IrVAyzJxfu7cOk/s640/Output1.png" width="640" /></a></div><br />
<b style="color: #e06666;">Now</b> let’s say there is another office girl who wanted <b>Smile </b>and at the same time she needs to do something else too. Let's say for an example flirting. How she can achieve this? <br />
<br />
Now the <b>Decorator </b>pattern is coming to the picture. By using it, we can decorate this office girl to do the flirting thingy at the run time!<br />
<br />
Following is how we can achieve this using a <b>Decorator </b>class:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU9PbhM0bXPkLKs-Ym3Onaow37OV16TdZj9FyVUHPWeZqqEkklR6k-3TBbcsc10VDF1oIntwTuqTEroGx-ljVxOLBaYMrfwX8GivB_aB7yQgfL_mNbiRyLFl8ap8Ve1tE4x546bFupaLw/s1600/Decorator.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="568" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU9PbhM0bXPkLKs-Ym3Onaow37OV16TdZj9FyVUHPWeZqqEkklR6k-3TBbcsc10VDF1oIntwTuqTEroGx-ljVxOLBaYMrfwX8GivB_aB7yQgfL_mNbiRyLFl8ap8Ve1tE4x546bFupaLw/s640/Decorator.png" width="640" /></a></div><br />
Following creates an instance from <b>OfficeGirl </b>and decorate it via <b>OfficeGirlDecorator </b>and check the <b>Smile</b>:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMx_0iOAfDNGFEiklnRRb-xhl_cJY_w9WcRzGJ7e5y9uxYFxWhZNUjSNKedi5X8u8QI55xlsXHJupEMSS1lrQTv4jpzNvBzSGKI4jxHN7OxCGlrzC6KkVG9JNRLeAnc7R_mtXntUadwmE/s1600/Test2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="288" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMx_0iOAfDNGFEiklnRRb-xhl_cJY_w9WcRzGJ7e5y9uxYFxWhZNUjSNKedi5X8u8QI55xlsXHJupEMSS1lrQTv4jpzNvBzSGKI4jxHN7OxCGlrzC6KkVG9JNRLeAnc7R_mtXntUadwmE/s640/Test2.png" width="640" /></a></div><br />
The output would be:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2JPoJz4TR9xFdBfDHQ4tzGjpXz77j-IUUe__D298IqqdidOZqNYenaTGYk1JyRS8RwWVcGnzShjLgfzEo9jJ-uAzPneNp8VefA2vmbmfHZblZVQ6zqmRgo_N9ugR2L0jG6W4QT48lxsA/s1600/Output2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="142" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2JPoJz4TR9xFdBfDHQ4tzGjpXz77j-IUUe__D298IqqdidOZqNYenaTGYk1JyRS8RwWVcGnzShjLgfzEo9jJ-uAzPneNp8VefA2vmbmfHZblZVQ6zqmRgo_N9ugR2L0jG6W4QT48lxsA/s640/Output2.png" width="640" /></a></div><br />
In this example if you look at the <b>Decorator</b> class, it can invoke just like the original class. In most cases, method calls are delegated to the original class and then the results are acted upon, or decorated, with additional functionality.<br />
<br />
Still not got it? For more information visit <a href="http://www.dofactory.com/Patterns/Patterns.aspx">Gang of Four</a>, <a href="http://en.wikipedia.org/wiki/Decorator_Pattern">Wikipedia</a>Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.com4tag:blogger.com,1999:blog-3055420731115390201.post-18158355074348107722010-08-24T13:45:00.004+05:302010-08-24T16:23:04.506+05:30Circular Positioning in ASP .Net<div class="separator" style="clear: both; text-align: center;"></div>In <a href="http://www.puzzlepart.com/">Puzzlepart</a> projects several occasions I had to find a good solution for the circular positioning on html markup. There are many ways to do this and the team wanted to tryout using pure css styles that support in cross browsers.<br />
<br />
Below sample code illustrates how to achieve this using css positing styles and the bit of mathematics. It’ll rotate the image based on selected angle.<br />
<br />
<div><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-right: 1em; text-align: left;"><tbody>
<tr> <td style="text-align: center;"><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC1xy_8Pjgs1JiPFo0KiyGBTBoWtlK_rM9gm2ZFsaIO36PUFiN28EyeRUKD6FB0KZHcx8FOhGUS3FlzWd0MtivEP5VU1Bd3DidLeMGUeMDLPHaE9rpm4tgXzB-NTbBWY8nUa4hSsJFRd0/s1600/sample.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC1xy_8Pjgs1JiPFo0KiyGBTBoWtlK_rM9gm2ZFsaIO36PUFiN28EyeRUKD6FB0KZHcx8FOhGUS3FlzWd0MtivEP5VU1Bd3DidLeMGUeMDLPHaE9rpm4tgXzB-NTbBWY8nUa4hSsJFRd0/s400/sample.png" width="382" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>Page View</b></td></tr>
</tbody></table></div><br />
<b>Code:</b><br />
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Drawing;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">namespace</span> RotationTest
{
<span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Rotation : Page
{
<span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">double</span> Radius = 155;
<span class="kwrd">private</span> <span class="kwrd">readonly</span> Point Origin = <span class="kwrd">new</span> Point(190, 195);
<span class="kwrd">protected</span> <span class="kwrd">string</span> PositionStyle
{
get
{
var style = <span class="str">"visibility:hidden;"</span>;
<span class="kwrd">if</span> (!<span class="kwrd">string</span>.IsNullOrEmpty(dropDownAngle.SelectedValue))
{
var angle = Convert.ToDouble(dropDownAngle.SelectedValue);
var position = GetPointOnCircle(Origin, Radius, angle);
style = <span class="kwrd">string</span>.Format(
<span class="str">"left: {0}px; top: {1}px;"</span>,
position.X, position.Y);
}
<span class="kwrd">return</span> style;
}
}
<span class="kwrd">private</span> <span class="kwrd">static</span> Point GetPointOnCircle(Point origin, <span class="kwrd">double</span> radius, <span class="kwrd">double</span> angleInDegrees)
{
<span class="rem">// Convert from degrees to radians via multiplication by PI/180 </span>
var x = (<span class="kwrd">int</span>)Math.Round(radius * Math.Cos(angleInDegrees * Math.PI / 180.0),
MidpointRounding.ToEven) + origin.X;
var y = (<span class="kwrd">int</span>)Math.Round(radius * Math.Sin(angleInDegrees * Math.PI / 180.0),
MidpointRounding.ToEven) + origin.Y;
<span class="kwrd">return</span> <span class="kwrd">new</span> Point(x, y);
}
}
}
</pre><b>Markup:</b><br />
<pre class="csharpcode1"><span class="asp"><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Rotation.aspx.cs"
Inherits="RotationTest.Rotation" %></span>
<span class="kwrd"><</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">="server"</span>>
<<span class="html">title></span>Rotation Test<<span class="kwrd">/</span><span class="html">title</span><span class="kwrd">></span>
<span class="kwrd"><span class="html">head</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">body</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">="form"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">div</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">div</span> <span class="attr">style</span><span class="kwrd">="width: 400px; height: 402px; background-image: url(circular-image.png);
background-repeat: no-repeat;"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">img</span> <span class="attr">src</span><span class="kwrd">="position-image.png"</span> <span class="attr">alt</span><span class="kwrd">="position image"</span>
<span class="attr">style</span><span class="kwrd">="position: absolute; <%= PositionStyle %>"</span> <span class="kwrd">/></span>
<<span class="kwrd">/</span><span class="html">div</span><span class="kwrd">></span>
Select Angle -
<span class="kwrd"><</span><span class="html">asp:DropDownList</span> <span class="attr">ID</span><span class="kwrd">="dropDownAngle"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">AutoPostBack</span><span class="kwrd">="True"</span><span class="kwrd">></span>
<<span class="kwrd"></span><span class="html">asp:ListItem</span> <span class="attr">Selected</span><span class="kwrd">="True"></span><span class="kwrd"></span>0<span class="kwrd"><span class="html">asp:ListItem</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:ListItem</span><span class="kwrd">></span>60<span class="kwrd"></</span><span class="html">asp:ListItem</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:ListItem</span><span class="kwrd">></span>90<span class="kwrd"></</span><span class="html">asp:ListItem</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:ListItem</span><span class="kwrd">></span>150<span class="kwrd"></</span><span class="html">asp:ListItem</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:ListItem</span><span class="kwrd">></span>240<span class="kwrd"></</span><span class="html">asp:ListItem</span><span class="kwrd">></span>
<<span class="kwrd"></span><span class="html">asp:ListItem</span><span class="kwrd">></span>320<span class="kwrd"></</span><span class="html">asp:ListItem</span><span class="kwrd">></span>
<span class="kwrd"><span class="html">asp:DropDownList</span><span class="kwrd">></span>
<span class="kwrd"><span class="html">div</span><span class="kwrd">></span>
<<span class="kwrd">/</span><span class="html">form</span><span class="kwrd">></span>
<span class="kwrd"><span class="html">body</span><span class="kwrd">></span>
<span class="kwrd"><span class="html">html</span><span class="kwrd">></span> </span></span></span></span></span></span></pre><br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0zbp78JUdViPDA6E85iT-DE2Knve0R6pBNZTAgO-G98hUCIDE0MAYnIVNp01CI0HvTtZMXXOs4FSIHsHQg0Rj4Ow4UYZqou_NndRi05D2AWh7B9KHnQf-u2Ar0yWTV6svZXD560qmBDk/s1600/circular-image.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0zbp78JUdViPDA6E85iT-DE2Knve0R6pBNZTAgO-G98hUCIDE0MAYnIVNp01CI0HvTtZMXXOs4FSIHsHQg0Rj4Ow4UYZqou_NndRi05D2AWh7B9KHnQf-u2Ar0yWTV6svZXD560qmBDk/s320/circular-image.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>Circular Image</b></td></tr>
</tbody></table><br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEim6eXO4khcgKXuK12LnEqn2OrVpCEt292Sr6HFxy4-IGLx72zO9N_D8sAHbLgcJNpghkJuku_4izyAaAUrfAB9QF7xs_6_YwL0vqqPasF5_G5dj5u2oequLgYtiTlqLF6-TwaeffGFqlQ/s1600/position-image.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEim6eXO4khcgKXuK12LnEqn2OrVpCEt292Sr6HFxy4-IGLx72zO9N_D8sAHbLgcJNpghkJuku_4izyAaAUrfAB9QF7xs_6_YwL0vqqPasF5_G5dj5u2oequLgYtiTlqLF6-TwaeffGFqlQ/s320/position-image.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>Position Image</b></td></tr>
</tbody></table><style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New", Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><br />
<style type="text/css">
.csharpcode1, .csharpcode1 pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New", Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode1 pre { margin: 0em; }
.csharpcode1 .rem { color: #008000; }
.csharpcode1 .kwrd { color: #0000ff; }
.csharpcode1 .str { color: #006080; }
.csharpcode1 .op { color: #0000c0; }
.csharpcode1 .preproc { color: #cc6633; }
.csharpcode1 .asp { background-color: #ffff00; }
.csharpcode1 .html { color: #800000; }
.csharpcode1 .attr { color: #ff0000; }
.csharpcode1 .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode1 .lnum { color: #606060; }
</style>Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.com0tag:blogger.com,1999:blog-3055420731115390201.post-62308079945435356862010-07-16T18:42:00.014+05:302018-07-26T09:39:17.657+05:30Design UI Mockups<div style="text-align: justify;">Presently I’m engaged with <a href="http://puzzlepart.com/">Puzzlepart</a> <a href="http://puzzlepart.com/Team.aspx">team</a> that one of the best <a href="http://en.wikipedia.org/wiki/SharePoint">SharePoint</a> solution providers in Norway and working on their <a href="http://puzzlepart.com/Products.aspx">SharePoint products</a>, external customers. Working with them reminds me one of the great projects that I worked in <a href="http://www.virtusa.com/">Virtusa</a>, that changed my whole thinking pattern of software development.</div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;">Few weeks ago we had a workshop for one of their upcoming <a href="http://puzzlepart.com/Products.aspx">product</a> and it was mainly focused on <a href="http://en.wikipedia.org/wiki/Sprint_%28scrum%29">sprint</a> planning for that product. The process we are using is <a href="http://en.wikipedia.org/wiki/Scrum_%28development%29">Scrum</a> and according to that we picked few <a href="http://en.wikipedia.org/wiki/User_story">user stories</a> from the user story board and create a <a href="http://en.wikipedia.org/wiki/Scrum_%28development%29#Product_backlog">product back log</a> and did the estimation for that. Each user story represents the main functionalities of the product and based on that, we decided how we are going to design user interfaces for the product. Previously I was only familiar with the <a href="http://en.wikipedia.org/wiki/RUP">RUP</a> development and still new to the Scrum. </div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;">The interesting thing was how we done the UI design for this product. Usually this will be done by an UI designer and based on their wireframes we do the actual implementation. But in here everybody was involved and it was a new experience to me. </div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;"><span style="font-size: large;"><b>How we did:</b></span></div><ul style="text-align: justify;"><li>Team is get together and pick up one user story from the planning <a href="http://en.wikipedia.org/wiki/Sprint_%28scrum%29">sprint</a>. Discuss the <a href="http://en.wikipedia.org/wiki/User_story">user story</a> scenario and the functionality that we need to implement.</li>
</ul><ul style="text-align: justify;"><li>After that each team member need to present his UI mockup for the functionality (draw it in a paper and show it to the team). Others will discuss if there were missing functionalities in the UI, discuss whether it is implementable.</li>
</ul><ul style="text-align: justify;"><li>UI designer will consider all UI mockups given by the team and aware about the technical limitations and the functionality.</li>
</ul><div style="text-align: justify;"><br />
</div><div style="text-align: justify;">Using this approach developers will have a good feeling that they have contributed something for the UI design and they are responsible to implement that. That time this was one of the key thing that we were able deliver the sprint successfully.</div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;">One lesson I learned was when design UI mockups it should contains the actual data that relevant to the user story not dummy data.</div>Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.com0tag:blogger.com,1999:blog-3055420731115390201.post-39396268801772946642010-07-03T14:07:00.001+05:302010-07-03T14:19:32.797+05:30Enum to Description<span style="font-family: inherit; font-size: small;">Recently we had an issue with maintaining <a href="http://msdn.microsoft.com/en-us/library/sbbt4032%28VS.80%29.aspx">enum</a> descriptions in our project. The problem was descriptions duplicated several places in codebase and when it came to modify descriptions we had to modify the description everywhere. From the maintainability perspective this not a good practice and we came up with a solution by using the coolest feature <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx">Extensions methods</a> that comes with the .NET 3.5. Following is the sample code of the solution.</span><br />
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.ComponentModel;
<span class="kwrd">using</span> System.Reflection;
<span class="kwrd">namespace</span> EnumToDescriptionTest
{
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> EnumExtensions
{
<span class="rem">// Extension method to get the enum description.</span>
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> ToDescription(<span class="kwrd">this</span> Enum val)
{
Type type = val.GetType();
<span class="kwrd">string</span> name = Enum.GetName(type, val);
FieldInfo field = type.GetField(name);
<span class="rem">// Check for the Description Attribute.</span>
DescriptionAttribute[] attributes = (DescriptionAttribute[])field.GetCustomAttributes(
<span class="kwrd">typeof</span>(DescriptionAttribute), <span class="kwrd">false</span>);
<span class="kwrd">return</span> attributes.Length > 0 ? attributes[0].Description : name;
}
}
<span class="kwrd">class</span> Program
{
<span class="rem">// Define the enum with description.</span>
<span class="kwrd">public</span> <span class="kwrd">enum</span> UserMode
{
[Description(<span class="str">"Add User"</span>)]
Add = 0,
[Description(<span class="str">"Update User"</span>)]
Update = 1,
[Description(<span class="str">"Delete User"</span>)]
Delete = 2
}
<span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
{
<span class="rem">// Get the enum description.</span>
Console.WriteLine(UserMode.Add.ToDescription());
Console.ReadLine();
}
}
}
</pre><style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New" , Courier, Monospace;
background-color: #ffffff; /*white-space: pre;*/
}
.csharpcode pre
{
margin: 0em;
}
.csharpcode .rem
{
color: #008000;
}
.csharpcode .kwrd
{
color: #0000ff;
}
.csharpcode .str
{
color: #006080;
}
.csharpcode .op
{
color: #0000c0;
}
.csharpcode .preproc
{
color: #cc6633;
}
.csharpcode .asp
{
background-color: #ffff00;
}
.csharpcode .html
{
color: #800000;
}
.csharpcode .attr
{
color: #ff0000;
}
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum
{
color: #606060;
}
</style>Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.com0tag:blogger.com,1999:blog-3055420731115390201.post-46888617112880274362008-10-18T10:38:00.029+05:302010-07-03T08:37:22.845+05:30Maintain Session Variables in ASP .Net Projects<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-family: arial; font-size: 85%;"><span class="Apple-style-span">Most of the ASP .net web projects maintain their session variables in an inconsistent way. Sometimes it’s harder to read and maintain. Here is a best way to maintain session variables in your web project. </span></span><span class="Apple-style-span" style="font-size: 85%;"><span class="Apple-style-span" style="font-weight: normal;"><span class="Apple-style-span" style="font-family: arial;"><span class="Apple-style-span">This will increase the maintainability and readability. </span></span></span></span><br />
<br />
<div class="MsoNormal" style="font-weight: bold; line-height: normal; margin-bottom: 0.0001pt;"><span class="Apple-style-span" style="font-size: 85%;"><span class="Apple-style-span" style="font-family: arial; font-weight: normal;"><span class="Apple-style-span"><span style="font-weight: bold;">Approach</span><b>:</b> </span></span><span class="Apple-style-span" style="font-weight: normal;"><span class="Apple-style-span" style="font-family: arial;"><span class="Apple-style-span">Add a new class to the web project and expose session objects as static properties.</span></span></span></span></div></div><style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New" , Courier, Monospace;
background-color: #ffffff; /*white-space: pre;*/
}
.csharpcode pre
{
margin: 0em;
}
.csharpcode .rem
{
color: #008000;
}
.csharpcode .kwrd
{
color: #0000ff;
}
.csharpcode .str
{
color: #006080;
}
.csharpcode .op
{
color: #0000c0;
}
.csharpcode .preproc
{
color: #cc6633;
}
.csharpcode .asp
{
background-color: #ffff00;
}
.csharpcode .html
{
color: #800000;
}
.csharpcode .attr
{
color: #ff0000;
}
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum
{
color: #606060;
}
</style><br />
<div class="csharpcode"><pre><span class="lnum">1: </span><span class="kwrd">using</span> System;</pre><pre><span class="lnum">2: </span><span class="kwrd">using</span> System.Web;</pre><pre><span class="lnum">3: </span> </pre><pre><span class="lnum">4: </span><span class="kwrd">namespace</span> SessionTest</pre><pre><span class="lnum">5: </span>{</pre><pre><span class="lnum">6: </span> <span class="rem">/// <summary></summary></span></pre><pre><span class="lnum">7: </span> <span class="rem">/// Hold all session variables
</span></pre><pre><span class="lnum">8: </span> <span class="rem">/// <summary></summary></span></pre><pre><span class="lnum">9: </span> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> ApplicationSession</pre><pre><span class="lnum">10: </span> {</pre><pre><span class="lnum">11: </span> <span class="rem">/// <summary></summary></span></pre><pre><span class="lnum">12: </span> <span class="rem">/// Hold the search key
</span></pre><pre><span class="lnum">13: </span> <span class="rem">/// <summary></summary></span></pre><pre><span class="lnum">14: </span> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> SearchKey</pre><pre><span class="lnum">15: </span> {</pre><pre><span class="lnum">16: </span> get</pre><pre><span class="lnum">17: </span> {</pre><pre><span class="lnum">18: </span> <span class="kwrd">return</span> Convert.ToString(HttpContext.Current.Session[<span class="str">"SearchKey"</span>]);</pre><pre><span class="lnum">19: </span> }</pre><pre><span class="lnum">20: </span> set</pre><pre><span class="lnum">21: </span> {</pre><pre><span class="lnum">22: </span> HttpContext.Current.Session[<span class="str">"SearchKey"</span>] = <span class="kwrd">value</span>;</pre><pre><span class="lnum">23: </span> }</pre><pre><span class="lnum">24: </span> }</pre><pre><span class="lnum">25: </span> }</pre><pre><span class="lnum">26: </span>}</pre><pre> </pre></div><span class="Apple-style-span" style="font-family: arial; font-size: 85%;"><span class="Apple-style-span"><b>Web Page</b></span></span><br />
<div class="csharpcode"><pre><span class="lnum"> </span></pre><pre><span class="lnum">1: </span><span class="kwrd">using</span> System;</pre><pre><span class="lnum">2: </span><span class="kwrd">using</span> System.Web.UI;</pre><pre><span class="lnum">3: </span> </pre><pre><span class="lnum">4: </span><span class="kwrd">namespace</span> SessionTest</pre><pre><span class="lnum">5: </span>{</pre><pre><span class="lnum">6: </span> <span class="rem">/// <summary></summary></span></pre><pre><span class="lnum">7: </span> <span class="rem">/// Code behind for the page</span></pre><pre><span class="lnum">8: </span> <span class="rem">/// <summary></summary></span></pre><pre><span class="lnum">9: </span> <span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> SessionTest : Page</pre><pre><span class="lnum">10: </span> {</pre><pre><span class="lnum">11: </span> <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)</pre><pre><span class="lnum">12: </span> {</pre><pre><span class="lnum">13: </span> <span class="kwrd">if</span> (!IsPostBack)</pre><pre><span class="lnum">14: </span> {</pre><pre><span class="lnum">15: </span> <span class="rem">// Access the session
</span></pre><pre><span class="lnum">16: </span> <span class="kwrd">string</span> currentSearchKey = ApplicationSession.SearchKey;</pre><pre><span class="lnum">17: </span> </pre><pre><span class="lnum">18: </span> <span class="rem">// Set new value
</span></pre><pre><span class="lnum">19: </span> ApplicationSession.SearchKey = <span class="str">"Customer"</span>;</pre><pre><span class="lnum">20: </span> }</pre><pre><span class="lnum">21: </span> }</pre><pre><span class="lnum">22: </span> }</pre><pre><span class="lnum">23: </span>}</pre></div>Janaka Jeewanthahttp://www.blogger.com/profile/04584233349957138719noreply@blogger.com2