tag:blogger.com,1999:blog-14547851027652911912024-03-28T12:48:41.981+05:30ASP.NET, C# and .NETBlog to share the knowledge, problems, technical challenges and their solutions I face in my day to day development activity.Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.comBlogger51125tag:blogger.com,1999:blog-1454785102765291191.post-79538272279807592062015-06-01T14:42:00.000+05:302015-10-19T14:55:22.504+05:30Estimate a release in Scrum<p>In <a title="Agile" href="http://en.wikipedia.org/wiki/Agile_software_development" target="_blank">Agile</a>, time and again people ask this question "How would you estimate a release for a product?". When it comes from management they want to know the following:</p> <ul> <li>Calculate the man hours which is at their disposal to get to the release date</li> <li>Risk assessment</li> <li>How many people we need, can we expedite the development if we pump in more man power?</li></ul> <p>There are many more questions. In some cases they want to use some complex prediction algorithm to come up with the release date. Oh!! My god, I think, at the end of the day who is going to implement the features? Can an algorithm do an exact implementation? Can you use the available man hours?<br> <br>I would say no. There is danger in using man hours. We don't take into account the diversity of a team. It can have people with experience levels. A person with ten years of experience may be able to finish a task in four hours, while another person with five years may take a day and someone less experienced may take two or more days. How does an algorithm include these differences? Or the team may be comprised of a tester, developer, BA etc. Each one has different work to do and you can't consider everyone to complete the different kind of work in the same hours at their disposal. Many a time management either doesn't understand or doesn't want to come out of its traditional way of running business.<br> <br>There is an easy solution to this. No fancy algorithm, no man hour calculation, nothing. If you are aware of Agile concepts then what I am going to say may sound familiar. You can use the velocity of the team to come up with more accurate predictions. But before we see how we can predict release, we need to understand what velocity is.<br> <br>Velocity is the story points a team can deliver in each sprint. A sprint can be anywhere between two to four weeks. I like to have smaller sprints of two weeks. Thinking that a sprint is of two weeks in length, let's examine further how velocity is calculated. Below is a table showing the sprint and the <a title="Story points" href="https://msdn.microsoft.com/en-us/library/hh273055(v=vs.88).aspx" target="_blank">story points</a> achieved in each sprint.</p> <table cellspacing="0" cellpadding="2" width="482" border="1"> <tbody> <tr> <td valign="top" width="133"><strong>Sprint #</strong></td> <td valign="top" width="155"><strong>Story points per sprint</strong></td> <td valign="top" width="192"><strong>Velocity</strong></td></tr> <tr> <td valign="top" width="133">Sprint 1</td> <td valign="top" width="155"> <p align="center">1</p></td> <td valign="top" width="192">1</td></tr> <tr> <td valign="top" width="133">Sprint 2</td> <td valign="top" width="155"> <p align="center">3</p></td> <td valign="top" width="192">(1+3)/2 = 2</td></tr> <tr> <td valign="top" width="133">Sprint 3</td> <td valign="top" width="155"> <p align="center">3</p></td> <td valign="top" width="192">(1+3+3)/3 = 2.3</td></tr> <tr> <td valign="top" width="133">Sprint 4</td> <td valign="top" width="155"> <p align="center">5</p></td> <td valign="top" width="192">(1+3+3+5)/4 = 3</td></tr> <tr> <td valign="top" width="133">Sprint 5</td> <td valign="top" width="155"> <p align="center">3</p></td> <td valign="top" width="192">(1+3+3+5+3)/5 = 3</td></tr></tbody></table> <p>So from the above table you can see how a team's velocity is calculated. In the first sprint (two weeks) it achieved one story point (SP). In the second it gained three SPs. So velocity is the total number of SPs achieved in all sprints divided by the number of sprints. In the third sprint the velocity was 2.3 and by the end of fifth sprint the velocity stabilized to three SPs. With that knowledge of what velocity is, let's tackle the problem of calculating a release date for a set of features.</p> <p>There are two ways to do this. One is where the team has historical data to calculate velocity and second where the team is new and there is no historical data. Let's see the easy one first.</p> <p><strong>When the team has Velocity data?</strong><br>This situation is applicable for teams that have been working on products for a long time and has historical SP data to calculate its velocity. The product owner gets a set of ten new features from the client and he wants to know how quickly the team can deliver these.</p> <p>The solution is simple. Give the ten new requirements to the team and ask them to come up with estimate. Here is the process which needs to be followed.</p> <ol> <li>The team (dev, QA, BA) gets into a quick release planning (not really release planning) meeting with the product owner.</li> <li>The team and Product Owner (PO) go through the list of features and try to understand each one of them. There is no need to know the nitty gritty of the requirements as they may be pulled out in future. The team needs to get enough information so that it can estimate.</li> <li>Once the team has enough understanding about a feature it can estimate the user stories (features). The estimate is done in terms of SPs. The team plays <a title="Planning Poker Game" href="https://en.wikipedia.org/wiki/Planning_poker" target="_blank">planning poker</a>. Below is the table showing the SPs estimated by the team for the features.</li></ol> <table cellspacing="0" cellpadding="2" width="400" border="1"> <tbody> <tr> <td valign="top" width="200">Features</td> <td valign="top" width="200">Story points</td></tr> <tr> <td valign="top" width="200">Feature 1</td> <td valign="top" width="200">5</td></tr> <tr> <td valign="top" width="200">Feature 2</td> <td valign="top" width="200">3</td></tr> <tr> <td valign="top" width="200">Feature 3</td> <td valign="top" width="200">3</td></tr> <tr> <td valign="top" width="200">Feature 4</td> <td valign="top" width="200">8</td></tr> <tr> <td valign="top" width="200">Feature 5</td> <td valign="top" width="200">5</td></tr> <tr> <td valign="top" width="200">Feature 6</td> <td valign="top" width="200">8</td></tr> <tr> <td valign="top" width="200">Feature 7</td> <td valign="top" width="200">3</td></tr> <tr> <td valign="top" width="200">Feature 8</td> <td valign="top" width="200">3</td></tr> <tr> <td valign="top" width="200">Feature 9</td> <td valign="top" width="200">5</td></tr> <tr> <td valign="top" width="200">Feature 10</td> <td valign="top" width="200">2</td></tr></tbody></table> <ol> <li>After all the ten features have been estimated calculate the total SPs for the ten user stories. From the above table the total SPs is 45. <li>From the first table we know the team's velocity is 3 and the total SPs estimated for 10 stories is 45. If the team can deliver three SPs a sprint then to deliver 45 SPs it will take 15 (45/3) sprints. 15 sprints = 30 (15 * 2) weeks. 30 weeks = 7.5 months. So the team will take 7.5 months to finish the ten new features. To this you need to add the regression, stabilization and any other phases required for delivering a quality product. In essence the time taken is 7.5 months + Time required for Regression + any other stage.</li></ol>For fairly new team that doesn't have historical data <ol> <li>Follow the above steps from 1 to 4. Let's go with the same 45 SPs as the estimate. <li>Now we don't have historical data to calculate the release date. What can be done? The team can decide and assume a number as its velocity. Say the team has decided two SPs as its velocity. Based on the team's assumption of its velocity you can calculate the release date. <li>As the sprints end the team can start re-calculating its velocity and adjust the release dates.</li></ol> <p>From my experience a team reaches a stable velocity within four to six iterations. So in two months you can exactly predict the release date.</p> <p><b>What happens if we don't meet the target?</b><br>During the release planning the team needs to fix dates on feature <a href="http://en.wikipedia.org/wiki/Freeze_%28software_engineering%29">freeze</a> and code <a href="http://en.wikipedia.org/wiki/Freeze_%28software_engineering%29">freeze</a> based on the overall estimate. By the time you reach the feature <a href="http://en.wikipedia.org/wiki/Freeze_%28software_engineering%29">freeze</a> date the team will have a good idea on whether it is going to deliver all the promised features. If the team is not able to keep the commitment -- if it has promised ten features and only eight will be completed --then the team members need not panic. The approach would be to ask the product owner to start negotiating with the client. Either the client has to accept the product with eight features or extend the time to get the whole set of features. This is quite normal and from my experience if you have a good product owner who has good negotiating skills the client will accept any of the above options.<br>Another advantage to Agile is that the client need not wait for years to get features. At the end of every end of the sprint the client gets a feature delivered. And I have seen except for few scenarios, client are quite accommodative. The reason is that client can see the ROI every two weeks and this actually builds confidence.</p> <p><b>What happens if the client cuts short the estimate from x to y?</b><br>The answer is simple. You tell the client that X will be the time taken to deliver ten features and if you cut the time short then in Y time frame you can deliver only six features.</p> <p><b>What happens if the client adds new requirements?</b><br>If the client adds more requirement and wants it in the same timeframe, then the team needs to tell the product owner that if you add new features then out of the previously committed ten features we may have to drop few to accommodate the new ones. This can happen only when prioritization comes into play.<br>The product owner and client need to decide the priorities for the features. Based on the priorities the team will tackle higher priority items first. Once the higher priorities are targeted it will pick up the lesser priority items. The product owner either needs to buy more time to include the new features or need to get few items off the list so that new items can be accommodated in the timeframe.</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com105tag:blogger.com,1999:blog-1454785102765291191.post-64726651182485521732015-04-20T23:58:00.001+05:302015-04-20T23:58:09.269+05:30Documentation in Agile<p>Documentation is a big contentious issue in Agile. There is a reason for this. When you start your presentation on Agile you start by going through the 4 statements of <a href="https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB4QFjAA&url=http%3A%2F%2Fagilemanifesto.org%2F&ei=tRQsVaOcKNOxogTl9oHwDA&usg=AFQjCNHwXRVf_KP8rGFX8ts0m0mI78Wc5Q&sig2=Xv-GSu8pi_bw1XpcrmQjfA&bvm=bv.90491159,d.aWw">agile manifesto</a>. As soon as you go to the second statement, traditional waterfall guys start frowning their eyes. The second statement in the manifesto says this. <blockquote><b>Working software</b> over comprehensive documentation</blockquote> <p>Seeing the statement people assume that documentation is not part of the agile process. It completely ignores documentation. Here comes questions. Without documenting the process flow how do you know what is the process we need to follow? Without document how do you know what is the requirement? Without document how do you know what has been implemented? Without document how is a new dev/qa going to understand what is coded/system all about? And if it is someone from CMMi background, then god can only help you to convince him/her.<br>The key thing people forget is that processes are there to help people get their work done faster. Deliver software faster to the end user. Faster delivery will help you capture market compared to your competitors. In software development you are not delivering document to the end user rather a working software. The above statement never said documentation is not needed, just that the emphasis is on delivering value to the end user.<br>Now let’s try to address some of the questions raised above.</p> <p><b>Process flow documentation</b><br><a href="http://en.wikipedia.org/wiki/Agile_software_development">Agile</a> is well documented. If you search the internet you will get not hundreds but thousands of documentation. Just put a few links to the website and that forms your document. I would say there is no need to re-create something which is freely available on the net. If you really want to have off-line document then use the save feature of your browser and save the pages. Make sure you have the permission to do the same. Or copy paste the contents and put it in a document with a link to the original article.<br>One of the best way of explaining your process is to have a pictorial representation of the same. If you search <a href="https://www.google.com/search?q=agile+process&safe=off&rlz=1C1CHFX_en-GBIN630IN630&espv=2&biw=1366&bih=623&source=lnms&tbm=isch&sa=X&ei=m40qVZbMA6iwsAT3pYDYBw&ved=0CAYQ_AUoAQ#imgrc=aDh3Xlhsy8aNzM%253A%3BJZvYUWqDzulYoM%3Bhttp%253A%252F%252F35qk152ejao6mi5pan29erbr9.wpengine.netdna-cdn.com%252Fwp-content%252Fuploads%252F2013%252F05%252FScrum_Framework.jpg%3Bhttp%253A%252F%252Fwww.agileforall.com%252Fintro-to-agile%252F%3B2997%3B1683">agile process</a> in Google you will find lot of high quality diagrams. Click <a href="https://www.google.com/search?q=agile+process&safe=off&rlz=1C1CHFX_en-GBIN630IN630&espv=2&biw=1366&bih=623&source=lnms&tbm=isch&sa=X&ei=m40qVZbMA6iwsAT3pYDYBw&ved=0CAYQ_AUoAQ#imgrc=aDh3Xlhsy8aNzM%253A%3BJZvYUWqDzulYoM%3Bhttp%253A%252F%252F35qk152ejao6mi5pan29erbr9.wpengine.netdna-cdn.com%252Fwp-content%252Fuploads%252F2013%252F05%252FScrum_Framework.jpg%3Bhttp%253A%252F%252Fwww.agileforall.com%252Fintro-to-agile%252F%3B2997%3B1683">here</a> to see few. Take appropriate permission and paste the same all over the office. I am of the opinion that if you want to implement some process don’t file it in a word, excel or powerpoint document. Rather display it to the whole world by pasting them in prominent places across the office. Make use of information radiator concept from Agile. Information radiator according to <a href="http://guide.agilealliance.org/guide/information-radiator.html">Alistair Cockburn</a> is:</p> <blockquote><i>An Information radiator is a display posted in a place where people can see it as they work or walk by. It shows readers information they care about without having to ask anyone a question. This means more communication with fewer interruptions.</i></blockquote><b>Requirements document</b><br>Yes you need to have requirements but not the traditional way of gathering requirement. In traditional way you write pages after pages of requirement, spend too much time up front (before the project even starts) gathering requirement. Agile says don’t spend too much time up front on gathering requirement. The reason, tomorrow the client’s requirement would change, so gather as much as you can but don’t over do it. Requirements are written in the form of <a href="http://www.mountaingoatsoftware.com/agile/user-stories">User Stories</a>. Typically user stories are written on a piece of paper or sticky notes. The template is as given below <blockquote>As a <<i>user type</i>>, I want <<i>some ability or action</i>> so that <<i>some result</i>>.</blockquote> <p>If the team is using JIRA, TFS (Team Foundation Server), Rally etc to manage the agile process, then the requirements can be captured in them. Each application has features to capture the nitty gritties of a user story. For e.g. JIRA has description column where one can elaborate on what the story is all about. In agile importance is given to discussions and understanding of the requirement within the team. Also user stories are not elaborated until they are worked upon. Again the reason is <a href="http://www.mountaingoatsoftware.com/agile/scrum/product-backlog">product backlog</a> (where user stories are captured) gets re-prioritised every now and then. So one user story having high priority today can have a low priority tomorrow. To save everyone’s effort from getting wasted the user stories are elaborated or discussed in detail during implementation in a sprint. Typically in a <a href="http://www.mountaingoatsoftware.com/agile/scrum/sprint-planning-meeting">sprint planning meeting</a>.<br>In short the way requirements are captured have changed. You use different tools and techniques to capture requirement. JIRA, TFS, Rally etc have taken the place of traditional document. Oh I forgot to mention sticky notes.</p> <p><b>Without document how can one know what the team has implemented?</b><br>The modern agile teams have moved away from the traditional way of maintaining records in document format. Agile teams use <a href="http://www.mountaingoatsoftware.com/agile/scrum/sprint-review-meeting">sprint review meeting</a> to show what has been implemented in the current sprint. Sprint review meeting is a casual demo of what features have been developed in a sprint. If you want to know what the implementation looks like attend the sprint review meeting. Advantages are that one need not spend time reading pages after pages of boring document. Rather you get to see a demo of a working feature. If you are an end user you can visualise how it will fit in your scheme of things.<br>Ok, you are not satisfied, still want a document evidence? No problem, record the demo and keep it as a documented evidence. Again another advantage, you are not spending extra time in writing document. Optimisation at it’s best. Recorded video is acting as a document.</p> <p><b>Without documents how a new developer/QA will get up to speed with the product? </b><br>I have been a developer and in my career of nearly 12 years I have never understood a system by reading documents. Developers understand only one language and that is the language in which they code. They understand C#, Java, JavaScript etc. The only thing they need is cleanly written code or in other words <a href="http://blog.goyello.com/2013/01/21/top-9-principles-clean-code/">clean code</a>. Developers understand a system by reading the code. They understand by pairing up with other developers. They understand by making bug fixes. Any new developer is thrown into the water and he learns to swim. Most of the projects, developers are asked to start with bug fixes and as and when they are comfortable they are given features to develop.<br>If you are following <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test Driven Development (TDD)</a>, then tests are the place to start. Tests help a developer to understand a feature/application very well. By looking at tests he/she will understand what the piece of code is doing. Having tests will give confidence to a developer to fix code and get early feedback whether the fix has broken anything.<br>As highlighted for a developer documentation is clean code and tests.</p> <p><b>Let go of your traditional understanding of documentation</b><br>From my experience what I feel is that people need to come out of their traditional view of having document for each and everything. Document need not be in the form of word, excel or powerpoint. The world has moved on. Document can be in the form of videos, can be in the form record entries in tools like JIRA, TFS, Rally etc. Can be in the form of display charts, cards,<a href="http://en.wikipedia.org/wiki/Kanban_board">Kanban board</a>, sticky notes, mobile pictures of a white board discussion, audio recording, webex recording, goto meeting recording, any link to an article to a website etc. Did I miss anything?<br>The key is not to burden development team in writing documents which are not adding value to the customer. For me if it doesn’t add value to the customer then there is no point in spending time on documentation. One needs to leave the technical documentation part to the team to decide. I understand when someone leaves a company he takes along with him good amount of knowledge. The way to tackle this is to have videos, good tests and clean code.<br>The agile manifesto doesn’t say no documentation. The way to look at document has changed. In the bad olden days of CMMi/waterfall, development team use to spend too much of time in creating documents for requirement, design (<a href="http://en.wikipedia.org/wiki/High-level_design">HLD/LLD</a>) etc. Even from developer’s perspective, hardly 1% of them use to read these. People understood that and they wanted the development team to focus more on what they do best i.e. development and testing. So the onus is on delivering value to a customer by giving a working software every sprint/iteration than writing documents.<br>This is my personal opinion. In the not so distant history, documents were used as a proof so that nothing went wrong. I feel the trust quotient was not there. People wanted to have this and that and what not kind of document to hold people responsible for their action. With agile that has change. It is not about individual, but about team. It is about empowering team and trusting them. Documents have also taken new forms like sticky notes pasted on a kanban board, videos, casual demo etc. With trust being an integral part I feel document has taken lower precedence. <br>In essence the definition of document has taken new forms. They have moved from the traditional written document format to include more visual forms.</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com7tag:blogger.com,1999:blog-1454785102765291191.post-11469891319641930302013-06-26T11:06:00.001+05:302013-06-26T11:06:48.033+05:30VS debugger not getting attach to IE<p align="justify">Recently I had this weird error where Microsoft Visual Studio 2010 (VS 2010) debugger was not getting attached to Microsoft Internet Explorer (IE). The only change was that IE was upgraded from IE 9 to IE 10. Till before the upgrade everything was working fine. The error is pasted below.</p> <blockquote> <p align="justify"><font color="#ff0000">Attaching the Script debugger to process '[XXXX] iexplore.exe' on machine 'XX-XX-XXX' failed. A debugger is already attached.</font></p></blockquote> <p align="justify">The solution for the above problem is pretty simple as well. Open the command prompt (cmd) in “Run as Admin” mode. Run the following command.</p> <blockquote> <p>regsvr32.exe "%ProgramFiles(x86)%\Common Files\Microsoft Shared\VS7Debug\msdbg2.dll”</p></blockquote> <p align="justify">“regsvr32” is a command line utility provided my Microsoft to register and unregister dlls in the Windows Registry. </p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com5tag:blogger.com,1999:blog-1454785102765291191.post-59831901247070880532011-12-09T18:55:00.002+05:302011-12-23T21:09:09.487+05:30Readonly v/s Constants<p>Many a times people have asked me the difference between a readonly variable and a constant. With this article I hope to clarify that. I would also delve on when to use readonly and when to use constant variables.</p> <p><strong>Readonly variables</strong></p> <p>readonly variables are also know as runtime constants. One can initialize the value of readonly variable to any type. One can have one’ own custom object as a readonly variable. Once initialized the readonly variables cannot be tinkered with other than in the constructor. If one really wants to change the value then that can only be done in the constructor. E.g. is shown below.</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Demo</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">readonly</span> Person p = <span style="color: #0000ff">new</span> Person();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> Demo ()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">this</span>.p = <span style="color: #0000ff">new</span> Person { Name = <span style="color: #006080">"P1"</span>, Age = 43};</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> Demo(Person pp)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">this</span>.p = pp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Person</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Name</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> get; set;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Age</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> get; set;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p>Also when you compile your code the readonly variable will have a reference to the actual object. readonly variable are slightly slower than constants in performance. readonly variables can be static.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> DateTime time = DateTime.Now;</pre><!--CRLF--></div></div><p>The above e.g. shows the readonly variable as static and the value is decided at runtime. readonly variables cannot be initialized inside a method. As readonly variables can be assigned in the constructor each instance of a class can have its own instance of the readonly object. </p><strong>Const variables</strong><br /><p>const variables are compile time constants. By compile time constants it means the actual value is replaced and saved in the IL (Intermediate Language). For this reason one can only use primitive types as const variables. Enum and strings can also be used as const variables. Primitive types, enum and string are the only datatypes which can be replaced with literal values. DateTime variable cannot be used as a const variable. Though it is of value type it cannot be used as a const variable. The reason is that compile time constants cannot be initialized using the new keyword. const variables are static by default. Few e.g. of const variables are pasted below.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ConstantsEG</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> maxValue = 2000;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">double</span> minValue = -.34343;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> VIBGYOR yellow = VIBGYOR.Yellow;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> SomeMethod()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> con = <span style="color: #006080">"const"</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Console.WriteLine(con);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Console.WriteLine(<span style="color: #006080">"MaxValue: {0}, MinValue: {1}, Yellow: {2} "</span>, maxValue, minValue, yellow);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">enum</span> VIBGYOR</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Violet,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Indigo,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Blue,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Green,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Yellow,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Orange,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Red</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p>In the above e.g. we have primitive types along with string and enum type as well. We have also declared a const variable inside a function as well. If you use readonly in a method scope you will get the following error.</p><blockquote><br /><p><span><em>The modifier 'readonly' is not valid for this item</em></span></p></blockquote><p>One thing to note is that readonly keyword will not be available in the intellisense of a VS inside a method. Just to highlight the difference I have pasted two classes below and their respective IL code.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ReadOnlyEG</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">readonly</span> <span style="color: #0000ff">int</span> minValue = 100;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">readonly</span> <span style="color: #0000ff">double</span> maxValue = -.3432323;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">readonly</span> <span style="color: #0000ff">string</span> someString = <span style="color: #006080">"Some string."</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">readonly</span> Person person = <span style="color: #0000ff">new</span> Person() { FirstName = <span style="color: #006080">"Sandeep"</span>, LastName = <span style="color: #006080">"P.R"</span>};</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> ReadOnlyEG()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> someString = <span style="color: #006080">"Changed string"</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Print()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Console.WriteLine(<span style="color: #006080">"MinValue: {0}, MaxValue: {1}, someString: {2}, FirstName: {3} & LastName: {4}"</span>, </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> minValue, maxValue, someString, person.FirstName, person.LastName);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Person</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FirstName</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> { get; set; }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> LastName</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> { get; set; }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p>The above classes highlights the different uses of a readonly variable. We are using int, double, string and user defined type. Also highlighted is the manipulation of a readonly string variable inside a constructor. Below IL code.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">.<span style="color: #0000ff">class</span> <span style="color: #0000ff">public</span> auto ansi beforefieldinit ReadOnlyEG</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> extends [mscorlib]System.Object</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .method <span style="color: #0000ff">public</span> hidebysig specialname rtspecialname instance <span style="color: #0000ff">void</span> .ctor() cil managed</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .maxstack 3</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .locals init (</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> [0] <span style="color: #0000ff">class</span> ReadOnlyConst.Person <>g__initLocal0)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0000: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0001: ldc.i4.s 100</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0003: stfld int32 ReadOnlyConst.ReadOnlyEG::minValue</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0008: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0009: ldc.r8 -0.3432323</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0012: stfld float64 ReadOnlyConst.ReadOnlyEG::maxValue</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0017: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0018: ldstr <span style="color: #006080">"Some string."</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_001d: stfld <span style="color: #0000ff">string</span> ReadOnlyConst.ReadOnlyEG::someString</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0022: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0023: newobj instance <span style="color: #0000ff">void</span> ReadOnlyConst.Person::.ctor()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0028: stloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0029: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_002a: ldstr <span style="color: #006080">"Sandeep"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_002f: callvirt instance <span style="color: #0000ff">void</span> ReadOnlyConst.Person::set_FirstName(<span style="color: #0000ff">string</span>)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0034: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0035: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0036: ldstr <span style="color: #006080">"P.R"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_003b: callvirt instance <span style="color: #0000ff">void</span> ReadOnlyConst.Person::set_LastName(<span style="color: #0000ff">string</span>)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0040: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0041: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0042: stfld <span style="color: #0000ff">class</span> ReadOnlyConst.Person ReadOnlyConst.ReadOnlyEG::person</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0047: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0048: call instance <span style="color: #0000ff">void</span> [mscorlib]System.Object::.ctor()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_004d: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_004e: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_004f: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0050: ldstr <span style="color: #006080">"Changed string"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0055: stfld <span style="color: #0000ff">string</span> ReadOnlyConst.ReadOnlyEG::someString</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_005a: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_005b: ret </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .method <span style="color: #0000ff">public</span> hidebysig instance <span style="color: #0000ff">void</span> Print() cil managed</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .maxstack 4</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .locals init (</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> [0] <span style="color: #0000ff">object</span>[] CS$0$0000)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0000: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0001: ldstr <span style="color: #006080">"MinValue: {0}, MaxValue: {1}, someString: {2}, FirstName: {3} & LastName: {4}"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0006: ldc.i4.5 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0007: newarr <span style="color: #0000ff">object</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_000c: stloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_000d: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_000e: ldc.i4.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_000f: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0010: ldfld int32 ReadOnlyConst.ReadOnlyEG::minValue</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0015: box int32</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_001a: stelem.<span style="color: #0000ff">ref</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_001b: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_001c: ldc.i4.1 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_001d: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_001e: ldfld float64 ReadOnlyConst.ReadOnlyEG::maxValue</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0023: box float64</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0028: stelem.<span style="color: #0000ff">ref</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0029: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_002a: ldc.i4.2 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_002b: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_002c: ldfld <span style="color: #0000ff">string</span> ReadOnlyConst.ReadOnlyEG::someString</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0031: stelem.<span style="color: #0000ff">ref</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0032: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0033: ldc.i4.3 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0034: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0035: ldfld <span style="color: #0000ff">class</span> ReadOnlyConst.Person ReadOnlyConst.ReadOnlyEG::person</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_003a: callvirt instance <span style="color: #0000ff">string</span> ReadOnlyConst.Person::get_FirstName()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_003f: stelem.<span style="color: #0000ff">ref</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0040: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0041: ldc.i4.4 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0042: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0043: ldfld <span style="color: #0000ff">class</span> ReadOnlyConst.Person ReadOnlyConst.ReadOnlyEG::person</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0048: callvirt instance <span style="color: #0000ff">string</span> ReadOnlyConst.Person::get_LastName()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_004d: stelem.<span style="color: #0000ff">ref</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_004e: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_004f: call <span style="color: #0000ff">void</span> [mscorlib]System.Console::WriteLine(<span style="color: #0000ff">string</span>, <span style="color: #0000ff">object</span>[])</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0054: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0055: ret </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .field <span style="color: #0000ff">private</span> initonly float64 maxValue</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .field <span style="color: #0000ff">private</span> initonly int32 minValue</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .field <span style="color: #0000ff">private</span> initonly <span style="color: #0000ff">class</span> ReadOnlyConst.Person person</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .field <span style="color: #0000ff">private</span> initonly <span style="color: #0000ff">string</span> someString</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p>If you see the above IL you will notice against all the value we have defined there are some instruction like “ldc.i4.s”, “ldc.r8” and “ldstr”. Each instruction has its own meaning. ldc.i4.s means push a number value onto the stack as an integer, ldc.r8 implies that push a float onto the stack and ldstr is an instruction to push a string object. If you further go down and take a peek into the print function you can see few IL instructions which are basically instruction to push and pop data to stack and finally replace the reference value from the stack.</p><p align="justify">Now let’ see the code where a class has const variables.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ConstantsEG</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> maxValue = 2000;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">double</span> minValue = -.34343;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> VIBGYOR yellow = VIBGYOR.Yellow;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> test = <span style="color: #006080">"Test text"</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> SomeMethod()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> con = <span style="color: #006080">"const"</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Console.WriteLine(con);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Console.WriteLine(<span style="color: #006080">"MaxValue: {0}, MinValue: {1}, Yellow: {2}, Test: {3} "</span>, maxValue, minValue, yellow, test);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">enum</span> VIBGYOR</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Violet,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Indigo,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Blue,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Green,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Yellow,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Orange,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Red</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p>The above class is similar to the one we have already seen above except for a public const string variable added. The IL generated for the above code is pasted below.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">.<span style="color: #0000ff">class</span> <span style="color: #0000ff">public</span> auto ansi beforefieldinit ConstantsEG</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> extends [mscorlib]System.Object</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .method <span style="color: #0000ff">public</span> hidebysig specialname rtspecialname instance <span style="color: #0000ff">void</span> .ctor() cil managed</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .maxstack 8</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0000: ldarg.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0001: call instance <span style="color: #0000ff">void</span> [mscorlib]System.Object::.ctor()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0006: ret </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .method <span style="color: #0000ff">public</span> hidebysig instance <span style="color: #0000ff">void</span> SomeMethod() cil managed</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .maxstack 4</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .locals init (</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> [0] <span style="color: #0000ff">object</span>[] CS$0$0000)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0000: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0001: ldstr <span style="color: #006080">"const"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0006: call <span style="color: #0000ff">void</span> [mscorlib]System.Console::WriteLine(<span style="color: #0000ff">string</span>)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_000b: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_000c: ldstr <span style="color: #006080">"MaxValue: {0}, MinValue: {1}, Yellow: {2}, Test: {3} "</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0011: ldc.i4.4 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0012: newarr <span style="color: #0000ff">object</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0017: stloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0018: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0019: ldc.i4.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_001a: ldc.i4 0x7d0</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_001f: box int32</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0024: stelem.<span style="color: #0000ff">ref</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0025: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0026: ldc.i4.1 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0027: ldc.r8 -0.34343</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0030: box float64</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0035: stelem.<span style="color: #0000ff">ref</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0036: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0037: ldc.i4.2 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0038: ldc.i4.4 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0039: box ReadOnlyConst.VIBGYOR</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_003e: stelem.<span style="color: #0000ff">ref</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_003f: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0040: ldc.i4.3 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0041: ldstr <span style="color: #006080">"Test text"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0046: stelem.<span style="color: #0000ff">ref</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0047: ldloc.0 </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_0048: call <span style="color: #0000ff">void</span> [mscorlib]System.Console::WriteLine(<span style="color: #0000ff">string</span>, <span style="color: #0000ff">object</span>[])</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_004d: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> L_004e: ret </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .field <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> literal int32 maxValue = int32(0x7d0)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .field <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> literal float64 minValue = float64(-0.34343)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .field <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> literal <span style="color: #0000ff">string</span> test = <span style="color: #0000ff">string</span>(<span style="color: #006080">'Test text'</span>)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> .field <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> literal valuetype ReadOnlyConst.VIBGYOR yellow = int32(4)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p>If you notice the IL code above all the const variables have been replaced by the actual values. At the bottom you can see the variables hold the actual value rather than only declaration as in the case with readonly variables. If you analyze the method (SomeMethod) in the IL you will notice that instead of some instruction to use the value by reference the actual values are used. In the case of readonly variable there were instruction to use the values by reference. But with const variables the actual values are being used.</p><p>With above IL code it is clear how readonly and const variables behave.</p><p><strong>When to use readonly/const variables?</strong></p><p>From the above most of you may be clear when to use const and when to use readonly variables. const variables can be used when the value of the variable is rarely going to change like the value of PI. Readonly can be used when you want to use the variables by reference or you want to inject runtime values. Also const variables are faster than readonly. By faster I don’t mean they are lighting fast. They give small performance benefit over readonly variables. Here one should use due diligence as const variables don’t provide any flexibility. Once assigned const variables cannot be changed.</p><p><strong>Note:</strong></p><p>A real time problem we faced in one of our projects. In one of our projects we had defined const and readonly variables in a separate project and added a reference of it in another project. After the release of the project we got requests from client to change few things. As a result we had to make changes in the const variables. Since the changes were only in few places, our team decided to just distribute the changed project and not to reinstall the whole application. So as a patch release we included few dlls in the installer and installed the same at the client place. But behold, the changes were not showing. The reason, the const variables used in other parts of the applications were not updated as only few projects were compiled and not the whole of the application. Because of this const values which were replaced were not updated. Confused? Let’ see this with an example. Below is a sample code which has a const and readonly variable in a separate project.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">using</span> System;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">using</span> System.Collections.Generic;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">using</span> System.Linq;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">using</span> System.Text;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">namespace</span> SeparateProject</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Values</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">double</span> PI = 3.14;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">readonly</span> <span style="color: #0000ff">double</span> Value1 = 40000;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p>The above code is pretty straight forward. In a namespace called SeparateProject, we have a class called Values. Values class has one const variable called PI. Another readonly variable called “Value1” having 40000 as the value. The above project is referenced and used in the below project. The code is pasted below.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">namespace</span> ReadOnlyConst</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">class</span> Program</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Console.WriteLine(<span style="color: #006080">"Constant: {0}"</span>, SeparateProject.Values.PI);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Console.WriteLine(<span style="color: #006080">"Readonly: {0}"</span>, SeparateProject.Values.Value1);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> Console.ReadLine(); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p>The above code is pretty straight forward. It is a console app which prints “3.14” and “40000” respectively. Now let’ change the values inside Values class and compile only that project.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">namespace</span> SeparateProject</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Values</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">const</span> <span style="color: #0000ff">double</span> PI = 3.14159;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">readonly</span> <span style="color: #0000ff">double</span> Value1 = 80000;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p>What we have done here is changed both the variable’ values and compiled only the “SeparateProject” project. Also we have replaced the dlls in the debug folder of the bin directory of “ReadOnlyConst” project with the latest compiled dll of “SeparateProject” project. If you run the console app, you will see the value of PI printed as “3.14” whereas the value of “Value1” printed as “80000”. You can see the value of PI has not been updated but the value of “Value1” has been updated. The reason is where ever const variables are used the values have been replaced where as in the case of readonly there is reference to the actual variable. In other words, in the main function the value of PI has been replaced by the actual value and that of “Value1” has reference. As we have not compiled this part of the application the substitution has not happened. Just to shed more light lets see the IL for the console app.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> .method <span style="color: #0000ff">private</span> hidebysig <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args) cil managed</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> .entrypoint</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> .maxstack 8</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> L_0000: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> L_0001: ldstr <span style="color: #006080">"Constant: {0}"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> L_0006: ldc.r8 3.14</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> L_000f: box float64</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> L_0014: call <span style="color: #0000ff">void</span> [mscorlib]System.Console::WriteLine(<span style="color: #0000ff">string</span>, <span style="color: #0000ff">object</span>)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> L_0019: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span> L_001a: ldstr <span style="color: #006080">"Readonly: {0}"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span> L_001f: ldsfld float64 [ConstReadonly]SeparateProject.Values::Value1</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span> L_0024: box float64</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14"> 14:</span> L_0029: call <span style="color: #0000ff">void</span> [mscorlib]System.Console::WriteLine(<span style="color: #0000ff">string</span>, <span style="color: #0000ff">object</span>)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15"> 15:</span> L_002e: nop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16"> 16:</span> L_002f: call <span style="color: #0000ff">string</span> [mscorlib]System.Console::ReadLine()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17"> 17:</span> L_0034: pop </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18"> 18:</span> L_0035: ret </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19"> 19:</span> }</pre><!--CRLF--></div></div><p>The above pasted IL is that of the main method of the console app. At line no 7, you can see the value of PI. Whereas at line no 12 instead of any value we have some IL instructions. Since we have not compiled the console application the altered values have not been updated. </p>Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com4tag:blogger.com,1999:blog-1454785102765291191.post-26166097299978581172010-09-07T20:38:00.002+05:302010-11-15T15:33:03.699+05:30MS Pivot<p align="justify">Recently I had this opportunity to work with a radically new tool called MS Pivot or simply Pivot. I know many of you may be thinking what is this stuff called pivot? Is it something to do with the Pivot table? No it has nothing to do with pivot table, rather it is a new technology from the Microsoft’ live lab.</p> <p align="justify"><strong><u>What is Pivot?</u></strong></p> <p align="justify">I would say Pivot is new way of searching information on the net. Till now we use to search information based on text. With Pivot one can search information based on images and text.Using the various features of Pivot one cab narrow down the search based on various filters as well. Pivot is a new technology to look at the vast amount of information scattered around us. It is a pictorial plus textual representation of information in graph and other format which make more sense to a human being than large chunks of textual data. The information can be anything which one can dream of. There is no limit to what you can display as a Pivot content as long as you have images and data for it. To display content in pivot one has to convert the data into a format which is understandable by Pivot. The format which Pivot understand is in the form of an XML and the format of that XML is called CXML. CXML stands for “CollectionXML”. The images which are rendered by the Pivot control needs to be converted into a format called “Deep Zoom Format”. Now you may be saying “Oh! no two new formats needs to be learnt?”. Don’t worry these two, CXML and Deep Zoom Format, are not difficult. “Deep Zoom Format” is the same technology used in “Seadragon”. In “Deep Zoom Format” the image is converted to a pyramid of images i.e. the original image is converted to very minute image, increasing in size to the original image. This is done to help the Pivot control to seamlessly zoom the image. To know more about the “Deep Zoom Format” please refer the following site. </p> <p align="justify"><a title="http://www.seadragon.com" href="http://www.seadragon.com/">http://www.seadragon.com</a></p> <p align="justify">Since pivot is all about pictorial representation I would like you to have a look at the below video and get amazed.</p> <p><object type="application/x-silverlight-2" data="data:application/x-silverlight-2," width="430" height="326"><param name="source" value="http://img.microsoft.com/showcase/silverlight/player/1/player.xap"><param name="initParams" value="Uuid=0be6bc92-a3e5-4184-a26d-caa026887074,Autoplay=False,ShowMenu=True,Tabs=Embed;Email;Share;Info;Downloads,ShowRelatedVideos=False,ShowMarketingOverlay=False,MiscControls=FullScreen;Detached,VideoUrl=http://www.microsoft.com/presspass/videos/default.mspx?VideoGUID=0be6bc92-a3e5-4184-a26d-caa026887074,Mode=Player"><param name="enableHtmlAccess" value="true"><param name="allowHtmlPopupwindow" value="true"><param name="background" value="#FFFFFFFF"><param name="minRuntimeVersion" value="3.0.40624.0"><param name="autoUpgrade" value="true"><a href="http://go.microsoft.com/fwlink/?LinkID=149156" style="text-decoration: none;" onmousedown="javascript:new Image().src = 'http://m.webtrends.com/dcsygm2gb10000kf9xm7kfvub_9p1t/dcs.gif?dcsdat=' + new Date().getTime() + '&dcssip=www.microsoft.com&dcsuri=' + window.location.href + '&WT.tz=-8&WT.bh=16&WT.ul={0}&WT.cd=32&WT.jo=Yes&WT.ti=&WT.js=Yes&WT.jv=1.5&WT.fi=Yes&WT.fv=10.0&WT.sli=Not%20Installed&WT.slv=Version%20Unavailable&WT.dl=1&WT.seg_1=Not%20Logged%20In&WT.vt_f_a=2&WT.vt_f=2&WT.vt_nvr1=2&WT.vt_nvr2=2&WT.vt_nvr3=2&WT.vt_nvr4=2&vp_site=Embedded&wtEvtSrc=' + window.location.href + '&vp_sli=Embedded'"><img src="http://img.microsoft.com/showcase/silverlight/player/1/img/en/install.gif" alt="Get Microsoft Silverlight" style="border-style: none" /></a><noscript><div><img alt="DCSIMG" id="DCSIMG" width="1" height="1" src="http://m.webtrends.com/dcsygm2gb10000kf9xm7kfvub_9p1t/njs.gif?dcsuri=/nojavascript&WT.js=No" /></div></noscript></object></p> <p align="justify"><strong><u>What is CXML?</u></strong></p> <p align="justify">As specified above CXML stands for “Collection XML”. It is the format which defines what should be displayed by pivot. Now let us understand what constitutes a CXML. As it is with any XML the content of a CXML is enclosed in a root element called “Collection”. The “Collection” root node has a “Name” attribute the value of which is displayed as title in the title bar of pivot control. “Icon” and “BrandImage” are the few other attributes for displaying icon and brand image related to the collection. </p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff"><?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">="1.0"</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">="utf-8"</span>?<span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff"><</span><span style="color: #800000">Collection</span> <span style="color: #ff0000">xmlns:p</span><span style="color: #0000ff">="http://schemas.microsoft.com/livelabs/pivot/collection/2009"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #ff0000">SchemaVersion</span><span style="color: #0000ff">="1.0"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="First excel collection images"</span> <span style="color: #ff0000">p:AdditionalSearchText</span><span style="color: #0000ff">="Ms-Pivot"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/collection/metadata/2009"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">FacetCategories</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">FacetCategory</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Living Being"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="String"</span><span style="color: #0000ff">></</span><span style="color: #800000">FacetCategory</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">FacetCategory</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Others"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="String"</span><span style="color: #0000ff">></</span><span style="color: #800000">FacetCategory</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">FacetCategory</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Count"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="Number"</span><span style="color: #0000ff">></</span><span style="color: #800000">FacetCategory</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">FacetCategory</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Link"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="Link"</span><span style="color: #0000ff">></</span><span style="color: #800000">FacetCategory</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">FacetCategories</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Items</span> <span style="color: #ff0000">ImgBase</span><span style="color: #0000ff">="First_Excel_Collection_files\tgpdq4lj.ano.xml"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Item</span> <span style="color: #ff0000">Id</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">Img</span><span style="color: #0000ff">="#0"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Owl"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Description</span><span style="color: #0000ff">></span>The image is that of an owl. Owl is a nocturnal bird.<span style="color: #0000ff"></</span><span style="color: #800000">Description</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Facets</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Facet</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Living Being"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">String</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">="Bird"</span><span style="color: #0000ff">></</span><span style="color: #800000">String</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Facet</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Facet</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Link"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Link</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Link"</span> <span style="color: #ff0000">Href</span><span style="color: #0000ff">="http://www.google.com"</span><span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Facet</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Facets</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Item</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Item</span> <span style="color: #ff0000">Id</span><span style="color: #0000ff">="1"</span> <span style="color: #ff0000">Img</span><span style="color: #0000ff">="#1"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Headphone"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Description</span><span style="color: #0000ff">></span>Philips headphone.<span style="color: #0000ff"></</span><span style="color: #800000">Description</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Facets</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Facet</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Others"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">String</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">="Gadget"</span><span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Facet</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Facet</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Count"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Number</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">="2"</span><span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Facet</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Facet</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Link Test"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Link</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Link test2"</span> <span style="color: #ff0000">Href</span><span style="color: #0000ff">="about:none"</span><span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Facet</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Facets</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Item</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Items</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff"></</span><span style="color: #800000">Collections</span><span style="color: #0000ff">></span></pre><!--CRLF--></div></div><p align="justify"><strong><u>FacetCategories & FacetCategory</u></strong></p><p align="justify">Next in hierarchy is the “FacetCategories” node which is nothing but a collection of “FacetCategory” nodes. “FacetCategories” as such don’t have any attributes. “FacteCategories” have “FacetCategory” as their child nodes. “FacetCategory” is nothing but a classification of you collection data into different categories. All “FacetCategory” is displayed in the Pivot filter panel on the left hand side of the Pivot control. I would say they serve as group heading and under each “FacetCategories” you have sub classification which is nothing but “Facet”. Following are the attributes of FacetCategory.</p><p align="justify"><strong>Name</strong>: Name to be given to the FacetCategory. The name is displayed in the filter panel on the left.</p><p align="justify"><strong>Format</strong>: Format attribute takes .NET numeric format strings as their value.</p><p align="justify"><strong>Type</strong>: Data type of the FacetCategory. The data types supported are string, long string, numeric, DateTime and link.</p><p align="justify"><strong><u>Items & Item</u></strong></p><p align="justify">Next in hierarchy is Items node. Again from the name one can make it out that it acts as a collection for Item node. It has got only one attribute called ImgBase to specify relative path to a DZC (Deep Zoom Collection) or XML file which contains the collection’ image details.</p><p align="justify">Item node holds each item which is displayed in the main window of the pivot control. Item node can have a Description node and a Facets node. Following are the attributes in a Item node.</p><p>Img: Hold the uri of the image. Normally Img attribute has a “#” symbol followed by a number. This number corresponds to the Id attribute in the DZC or XML file specified in the ImgBase attribute of the Items node. To understand better lets see the typical content of DZC or XML file mentioned in the ImgBase attribute of the Items node.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff"><?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">="1.0"</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">="utf-8"</span>?<span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff"><</span><span style="color: #800000">Collection</span> <span style="color: #ff0000">MaxLevel</span><span style="color: #0000ff">="7"</span> <span style="color: #ff0000">TileSize</span><span style="color: #0000ff">="256"</span> <span style="color: #ff0000">Format</span><span style="color: #0000ff">="jpg"</span> <span style="color: #ff0000">NextItemId</span><span style="color: #0000ff">="8"</span> <span style="color: #ff0000">ServerFormat</span><span style="color: #0000ff">="Default"</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/deepzoom/2009"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Items</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">I</span> <span style="color: #ff0000">Id</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">N</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">Source</span><span style="color: #0000ff">="images/53794121.GreatHornedOwlCloseUp.xml"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Size</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="800"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="554"</span> <span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">I</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">I</span> <span style="color: #ff0000">Id</span><span style="color: #0000ff">="1"</span> <span style="color: #ff0000">N</span><span style="color: #0000ff">="1"</span> <span style="color: #ff0000">Source</span><span style="color: #0000ff">="images/Commercial-product-photography-of-headphones.xml"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Size</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="950"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="485"</span> <span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">I</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">I</span> <span style="color: #ff0000">Id</span><span style="color: #0000ff">="2"</span> <span style="color: #ff0000">N</span><span style="color: #0000ff">="2"</span> <span style="color: #ff0000">Source</span><span style="color: #0000ff">="images/GreatCrestedGrebe20.xml"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Size</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="800"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="566"</span> <span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">I</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">I</span> <span style="color: #ff0000">Id</span><span style="color: #0000ff">="3"</span> <span style="color: #ff0000">N</span><span style="color: #0000ff">="3"</span> <span style="color: #ff0000">Source</span><span style="color: #0000ff">="images/great-northern-diver-dsg.xml"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Size</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="700"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="500"</span> <span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">I</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"></</span><span style="color: #800000">Items</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff"></</span><span style="color: #800000">Collection</span><span style="color: #0000ff">></span></pre><!--CRLF--></div></div><p align="justify">You can see from the above DZC or XML file content that it uses numbers starting from 0 to whatever the max number as the Id attribute. Whatever is mentioned in the Img attribute of the Item node relates to the Id attribute in this DZC file. The logic is that the XML file url mentioned in the Source attribute will hold some image related attributes and there will be a folder with the same name as that of the XML file mentioned in the Source attribute. The folder with the same name as that of the XML file mentioned in the Source attribute will hold all the images for the particular Item. Huff explaining this simple logic is really a pain. Anyways lets see the content of the XML file mentioned in the Source attribute.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff"><?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">="1.0"</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">="utf-8"</span>?<span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff"><</span><span style="color: #800000">Image</span> <span style="color: #ff0000">TileSize</span><span style="color: #0000ff">="254"</span> <span style="color: #ff0000">Overlap</span><span style="color: #0000ff">="1"</span> <span style="color: #ff0000">Format</span><span style="color: #0000ff">="jpg"</span> <span style="color: #ff0000">ServerFormat</span><span style="color: #0000ff">="Default"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/deepzoom/2009"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff"><</span><span style="color: #800000">Size</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="800"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="554"</span> <span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff"></</span><span style="color: #800000">Image</span><span style="color: #0000ff">></span></pre><!--CRLF--></div></div><p>The above XML contents details about the images like its format, TileSize, Width etc. The other attributes of the item node are as follows.</p><p><strong>Id</strong>: Next attribute in the Item node is Id which gives an unique ID to the item in the Items collection.</p><p><strong>Href</strong>: Href attribute will have a url clicking on which the user will navigated to the url. The url can be anything which gives more info about the product.</p><p><strong>Name</strong>: The name of the item. Name attribute will be displayed in the info panel on the right side of the pivot control.</p><p><strong><u>Description node</u></strong></p><p>The Description node is child node in the Item node. The Description node has an explanation about the node and this description gets displayed in the info panel just below the header name in the info panel. </p><p><strong><u>Facets</u></strong></p><p>The next child node in the CXML is the Facets node. The node is just a collection container which contains one or more Facet node.</p><p><strong><u>Facet</u></strong></p><p align="justify">Facet node is the child element of the Facets node in a Item node. The Facet node has only one attribute called Name. Name provided in this attribute should match the Name attribute of the FacetCategory node. Facet node acts as a container for defining the various properties of the FacetCategory of an item. You can think Facet as container which defines the sub categories of the FacetCategory to which the Item belongs. An Item can belong to more than one FacetCategory. The Facet can have only any of the following as child elements.</p><ul><li><strong>String</strong>: Can contain a string value for the Facet node.<br /></li><li><strong>LongString</strong>: The value provided in the value string will not be displayed in the filter panel. LongString value will be displayed on the info panel on the right side of the pivot control. LongString is used to display long descriptions about the item in the info panel.<br /></li><li><strong>Number</strong>: Used to provide number value for the item. If number type is used one will get a slider in the filter panel to drag and filter between the numbers values defined.<br /></li><li><strong>DateTime</strong>: Needs to be used to provide DateTime value.<br /></li><li><strong>Link</strong>: The Link node has two attributes namely Name and Href. Href takes a URL or “about:none” text as the value. Name can be used to provide name to the Link node.</li></ul><p>That’s about the CXML. There are other nodes as well but just for the beginning this will serve the purpose.</p><p align="justify">To create Deep Zoom Images one can make use Deep Zoom Composer or Deep Zoom Tools command line utilities. Deep Zoom Composer is a Graphical User Interface (GUI) for creating DZCs where as Deep Zoom Tools command line utilities are part of the Deep Zoom tools library which can be freely downloaded. It consists of two executable name DZConvert.exe to convert image files into DZI formats and DZCollection.exe to convert DZI to DZC. Now developers will ask how they can programmatically convert images to DZI and DZC formats. Developers can make use of the DeepZoomTools.dll to convert images to the required format.</p><p align="justify">Whenever you have search requirement where you want to give a different experience to the end user with the help of images then go ahead and download Pivot control for Silverlight and convert your data to CXML and there you go. Silverlight PivotViewer can be downloaded from <a href="http://www.silverlight.net/learn/pivotviewer/" target="_blank">here</a>. </p>Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com8tag:blogger.com,1999:blog-1454785102765291191.post-29967398831147543412010-05-05T16:00:00.003+05:302010-08-17T22:08:02.151+05:30Calling web service using javascript. Part -3<p align="justify">In the <a href="http://sandblogaspnet.blogspot.com/2010/03/calling-web-service-using-javascript.html" target="_blank">part 1</a> of this blog we saw how to invoke web service methods using pure javascript and in <a href="http://sandblogaspnet.blogspot.com/2010/04/calling-web-service-using-javascript.html" target="_blank">part 2</a> we made use of web service behavior to invoke web methods. The previous two blogs were not dependent on server technologies used by the user but this blog will have that constraint because we will have a look at how to invoke web methods using “ScriptManager”. “ScriptManager” is an ASP.NET server side control which is key to AJAX functionality in ASP.NET. Without any further delay let’ see our first web method invocation using “ScriptManager”. For this blog we will making use of the same web service as we have used in our previous two blogs. Below is the code for the first web service method we are going to invoke. </p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background- margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 200px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:#f4f4f4;" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"><span style="color:#0000ff;">namespace</span> ScriptManagerService</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> <span style="color:#008000;">//The attribute which makes the web service callable from script.</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> [System.Web.Script.Services.ScriptService]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> TestService : System.Web.Services.WebService</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> [WebMethod]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> HelloWorld()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> <span style="color:#0000ff;">return</span> <span style="color:#006080;">"Hello World"</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;">}</pre><!--CRLF--></div></div><p align="justify">The above web service code is pretty straight forward. We have a simple “HelloWorld” method which returns a string. What makes this web service special is the “[System.Web.Script.Services.ScriptService]” attribute added on top of the “TestService” web service class. The attribute makes the web service callable from JavaScript. Also when the proxy classes are generated the attribute generates JavaScript object corresponding to the web service class. Once the web service is created now we need to create our web page to invoke the web method. Create a new aspx page and add a “ScriptManager” control to it. Sample aspx page with the “ScriptManager” tag is added below.</p><div face="'Courier New', courier, monospace" size="8pt" color="#f4f4f4" style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background- margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 200px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"><body></pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"><script language=<span style="color:#006080;">"javascript"</span> type=<span style="color:#006080;">"text/javascript"</span>></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;">function invokeSimpleWebMethod()</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> ScriptManagerService.TestService.HelloWorld(handleResult); </pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">} </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> </pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">function handleResult(result)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;">{</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> alert(result);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;">}</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"></script></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> <form id=<span style="color:#006080;">"form1"</span> runat=<span style="color:#006080;">"server"</span>></pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> <div></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"> <asp:ScriptManager ID=<span style="color:#006080;">"scrMgr"</span> runat=<span style="color:#006080;">"server"</span>></pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> <Services></pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:ServiceReference Path=<span style="color:#006080;">"TestService.asmx"</span> /> </pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> </Services></pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> </asp:ScriptManager></pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:Button ID=<span style="color:#006080;">"btnHW"</span> runat=<span style="color:#006080;">"server"</span> Text=<span style="color:#006080;">"Hello World"</span> OnClientClick=<span style="color:#006080;">"invokeSimpleWebMethod();"</span> /></pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> </div></pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> </form> </pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"></body></pre><!--CRLF--></div></div><p align="justify">In the above code we can see that we have a “ScriptManager” server control added. And inside the “Services” tag we have added reference to our local web service using the “ServiceReference” tag. The path attribute of the “ServiceReference” tag has the url of the web service which needs to be invoked. You can add multiple web services by adding additional “ServiceReference” tags. What ASP.NET does here is that it generates JavaScript proxy classes for each of the web services mentioned in the “ServiceReference” tag. All the auto generated JavaScript proxy classes derive from “Sys.Net.WebServiceProxy”.</p><p align="justify">Also we have an ASP.NET Button server control which calls a “invokeSimpleWebMethod” javascript method on its “OnClientClick” event. In the “invokeSimpleWebMethod” javascript method we have made use of the namespace (in which the web service is defined) followed by the web service name and finally the method name which needs to be invoked. Behind the scene ASP.NET has done the extra work of registering the namespace and creating the proxy classes and also adding the methods defined inside the web service into a proxy JavaScript class. If you notice the “HelloWorld” method takes an argument. The argument is nothing but the name of the JavaScript function which needs to be invoked when the web service method has been successfully executed and results are returned to the browser. You can also pass the name of the function which needs to be invoked when the web service method invocation request fails. We will see the same shortly. The “handleResult” JavaScript method gets called when the asynchronous request is successfully returned. The method gracefully displays the result in an alert message box.</p><p align="justify">That’ about how to use the “ScriptManager” server control to invoke a web service methods i.e. namespace followed by class name followed by the method name. One thing to note is that “ScriptManager” control can only be used to call web services in the same domain. Now lets see how to pass parameters to web methods.</p><p align="justify"><strong><u>Passing parameters to web method</u></strong></p><p align="justify">We will use the following web method to see how we can pass parameters by using “ScriptManager”.</p><div face="'Courier New', courier, monospace" size="8pt" color="#f4f4f4" style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background- margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 200px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;" id="codeSnippet"><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">[WebMethod]</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> CombineName(<span style="color:#0000ff;">string</span> firstName, <span style="color:#0000ff;">string</span> midleName, <span style="color:#0000ff;">string</span> lastName)</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">string</span>.Concat(<span style="color:#0000ff;">string</span>.Concat(firstName, <span style="color:#006080;">" - "</span>, midleName), <span style="color:#006080;">" - "</span>, lastName);</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p align="justify">The above method is pretty straight and it is the same method which I have used in my <a href="http://sandblogaspnet.blogspot.com/2010/04/calling-web-service-using-javascript.html" target="_blank">previous blog</a>. The method takes three string arguments and concatenates them and returns them as a single string. Now lets see how we can pass the three parameters from JavaScript.</p><p align="justify">Below is the JavaScript method which invokes the web method with the three string parameters.</p><div class="csharpcode"><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;" id="codeSnippet"><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">function</span> webMethodWithParams()</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">{ </pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> ScriptManagerService.TestService.CombineName(<span style="color:#006080;">"Sandeep"</span>, <span style="color:#006080;">" "</span>, <span style="color:#006080;">"P.R"</span>, handleResult, handleError);</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div></div><br /><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>In the above JavaScript function we are invoking the “CombineName” method the same way we invoked the “HelloWorld” web method. But the difference here is that instead of the callback function as the first argument we are passing the arguments first, followed by the success callback function name and then the failure callback function. The funda behind is simple, if your web method accepted three parameters pass them first in the same order as defined in the web method followed by the callback methods. Similarly if the web method takes different number of parameters then make sure that, that many number of parameters are passed first followed by the success callback function. Success callback and error callback functions are optional. Our “handleError” javascript function looks something like this.<br /><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;" id="codeSnippet"><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">function</span> handleError(error)</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> alert(error.get_message());</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p align="justify">The above “handleError” javascript function is pretty straight forward. It takes an error object as one of the argument. The error object passed by the system has various methods and properties to retrieve the details of the exception happened on the server side. Some of the methods and properties are as follows.</p><ol><li><div align="justify">get_exceptionType method or _exceptionType field/property can be used to get the type of exception raised by the server like “System.Exception”.</div></li><li><div align="justify">get_message method or _message field/property can be used to get the error message returned by the server.</div></li><li><div align="justify">_stackTrace field/property or get_stackTrace method can be used to get the stack trace of the error from the server.</div></li><li><div align="justify">get_statusCode method or _statusCode field/property can be used to retrieve the HTML status code returned from the server.</div></li></ol><p align="justify">The error object which is passed to the “handleError” JavaScript function is of type “Sys.Net.WebServiceError”. “Sys.Net.WebServiceError” is a simple class with the above explained methods or fields/properties.</p><p align="justify">Now the next step is to pass complex objects from JavaScript to a web method. Lets see how that can be accomplished.</p><p align="justify"><strong><u>Passing complex objects</u></strong></p><p align="justify">Let see the code of the web method which accepts a complex object and processes it.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;" id="codeSnippet"><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">[WebMethod]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> GetCar(Car car)</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">return</span> <span style="color:#006080;">"Model: "</span> + car.Model + <span style="color:#006080;">", Color: "</span> + car.Color; <span style="color:#008000;">//", Cubic capacity: ";//+ car.CC + </span></pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p>The above web method doesn’t have rocket science in it, it just takes a complex object of type “Car” and concatenates the properties and returns it as a string. Now lets the “Car” class. Its same as that we have used in our previous examples.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background- margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:#f4f4f4;" id="codeSnippetWrapper"><div face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Car</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> Model</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> { get; set; } </pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> Color</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> { get; set; }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">public</span> Engine CarEngine</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> { get; set; }</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Engine</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> CC</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> { get; set; }</pre><!--CRLF--><pre face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> Cylinders</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> { get; set; }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p align="justify">The “Car” class has three properties namely “Model”, “Color” and “CarEngine”. “Model” and “Color” are of type string and “CarEngine” is again a complex object of type “Engine”. The “Engine” class has two properties of type int namely “CC” and “Cylinders”. The above “Car” class is the one which we will be passing to the web method from within JavaScript using ScripManager. The code is pasted below.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background- margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:#f4f4f4;" id="codeSnippetWrapper"><div face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">function</span> sendComplexObject()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#008000;">//Create a new Object and assign the same properties as those in the Car class.</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">var</span> car = <span style="color:#0000ff;">new</span> Object();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> car.Model = <span style="color:#006080;">"Ferrari California"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> car.Color = <span style="color:#006080;">"Ferrari Red"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> car.CarEngine = <span style="color:#0000ff;">new</span> Object()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> car.CarEngine.CC = 4500</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> car.CarEngine.Cylinders = 12</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#008000;">//Execute the web method.</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> ScriptManagerService.TestService.GetCar(car, handleResult, handleError);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p align="justify">In the “sendComplexObject” method we are first creating a “Car” object by creating an object of type “Object”. Then to that object we are adding all the properties that the “Car” class has. Since JavaScript is a dynamic language you can add all the properties by just giving the name and the value. As the “Car” class has another complex object, Engine, as one of its property named “CarEngine” we are also creating the complex engine object also the same way. Once we have created the object we are finally executing the web method in the final line of code. Isn’t simple to pass complex objects from JavaScript to server. To help us to do write such a simple code the ScriptManager does the extra work converting the JavaScript objects to server objects. </p><p align="justify">Below is the JSON way of creating the complex Car object.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background- margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:#f4f4f4;" id="codeSnippetWrapper"><div face="'Courier New', courier, monospace" size="8pt" color="black" style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">function</span> sendComplexObject()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#008000;">//Create an object of type "ScriptManagerService.Car" and pass all the properties </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#008000;">//as a javascript string array.</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">var</span> car = <span style="color:#0000ff;">new</span> ScriptManagerService.Car({<span style="color:#006080;">"Model"</span> : <span style="color:#006080;">"Ferrari California"</span>, <span style="color:#006080;">"Color"</span> : <span style="color:#006080;">"Ferrari Red"</span>, <span style="color:#006080;">"CarEngine"</span> : {<span style="color:#006080;">"CC"</span> : <span style="color:#006080;">"100"</span>, <span style="color:#006080;">"Cylinders"</span> : <span style="color:#006080;">"5"</span>}})</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#008000;">//Invoke the web method.</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> ScriptManagerService.TestService.GetCar(car, handleResult, handleError);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p align="justify">In the above code we are trying to create a “ScriptManagerService.Car” object. This is possible because the ScriptManager generates the Proxy classes automatically for us. Now lets see handling a complex type returned from the server. It also is quite simple.</p><p align="justify"><strong><u>Handling a complex object returned by the server</u></strong></p><p align="justify">Lets see the web service which returns the complex object.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background- margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:#f4f4f4;" id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">[WebMethod]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">public</span> Car GetCarObject()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> Car</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> Model = <span style="color:#006080;">"Ferrari"</span>,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> Color = <span style="color:#006080;">"Ferrari Red"</span>,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> CarEngine = <span style="color:#0000ff;">new</span> Engine { CC = 2500, Cylinders = 8 },</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> test = <span style="color:#006080;">"test"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> };</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p align="justify">The above web method does the hard work of creating a car object and returning the same. We are going to invoke the above web method using the ScriptManager and use the very complex object in JavaScript. The JavaScript code is pasted below.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background- margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:#f4f4f4;" id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">function</span> receiveUseComplexObject()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#008000;">//Invoking the web method that returns complex object.</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> ScriptManagerService.TestService.GetCarObject(handleResult, handleError);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#008000;">//Modified handleResult function</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">function</span> handleResult(result)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#008000;">//Using the complex object returned by the web method in JavaScript.</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">var</span> carDef = <span style="color:#006080;">"Model: "</span> + result.Model + <span style="color:#006080;">", Color: "</span> + result.Color + <span style="color:#006080;">", Engine-CC: "</span> + result.CarEngine.CC;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> carDef += <span style="color:#006080;">", Engine-Cylinders: "</span> + result.CarEngine.Cylinders;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> alert(carDef);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p align="justify">In the “receiveUseComplexObject” we are not doing any drastic than invoking the “GetCarObject” web method. The main work is done by the modified “handleResult” function. The web method returns a “Car” object, the parameter of the “handleResult” also is the JavaScript proxy “Car” object representing the server object. The ScriptManager does all the work of converting the returned object as a JSON “Car” object. This is why we are able to use the properties of the “Car” object as we would do in a normal OOPS programming language.</p><p align="justify"><strong><u>Calling methods in a page</u></strong></p><p align="justify"> Using “ScriptManager” one can access method of a web page as well. One catch here is that you can execute only static page methods. To call a page method from JavaScript by making use of “ScriptManger” you need to add the “WebMethod” attribute to the method you want to call. Lets see “.cs” file of a web page.</p><div face="'Courier New', courier, monospace" size="8pt" color="#f4f4f4" style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background- margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> TestPage : System.Web.UI.Page</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">void</span> Page_Load(<span style="color:#0000ff;">object</span> sender, EventArgs e)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> { }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> [System.Web.Services.WebMethod]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">string</span> HelloWorld()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color:#0000ff;">return</span> <span style="color:#006080;">"Hello world"</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div><p align="justify">As mentioned above, we have added the “WebMethod” attribute to a static method and that’ it you need to do to make a page method callable by “ScriptManager”. In “ScriptManager” you need to set “EnablePageMethods” property to “true”. What this property does is it generates a “PageMethods” JavaScript class which has the necessary code to call all the static page methods which are decorated by the “WebMethod” attribute. Lets see the ASPX page and the JavaScript.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><%@ Page Language=<span style="color:#006080;">"C#"</span> AutoEventWireup=<span style="color:#006080;">"true"</span> CodeBehind=<span style="color:#006080;">"WebSerCalServiceMngr.aspx.cs"</span> Inherits=<span style="color:#006080;">"WebServiceUsingJS.WebSerCalServiceMngr"</span> %></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><!DOCTYPE html PUBLIC <span style="color:#006080;">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span> <span style="color:#006080;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span>></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><html xmlns=<span style="color:#006080;">"http://www.w3.org/1999/xhtml"</span> ></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><head runat=<span style="color:#006080;">"server"</span>></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <title>Untitled Page</title></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"></head></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><body></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><script language=<span style="color:#006080;">"javascript"</span> type=<span style="color:#006080;">"text/javascript"</span>></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">function callPageMethods()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> PageMethods.HelloWorld(handleResult);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"></script></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><form id=<span style="color:#006080;">"form1"</span> runat=<span style="color:#006080;">"server"</span>></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <div></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:ScriptManager ID=<span style="color:#006080;">"scrMgr"</span> runat=<span style="color:#006080;">"server"</span> EnablePageMethods=<span style="color:#006080;">"true"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </asp:ScriptManager></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><asp:Button ID=<span style="color:#006080;">"Button3"</span> runat=<span style="color:#006080;">"server"</span> Text=<span style="color:#006080;">"Call page method."</span> OnClientClick=<span style="color:#006080;">"callPageMethods();"</span> /></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </div></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </form></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"></body></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"></html></pre><!--CRLF--></div></div><p align="justify">In the above code we have set “EnablePageMethods” property to true and on the click of a button we are calling “callPageMethods()” JavaScript function. Inside the “callPageMethods” JavaScript function we are making use of “PageMethods” proxy class to execute our page method. So with “ScriptManager” doing all the extra work at the back, as a developer we are having great time. </p><br /><p align="justify">Try to know more</p><br /><p align="justify">Sandeep.</p>Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com7tag:blogger.com,1999:blog-1454785102765291191.post-7034445650360441602010-04-20T20:20:00.001+05:302012-07-04T14:46:43.177+05:30Calling web service using javascript. Part - 2<p align="justify">In the first <a href="http://sandblogaspnet.blogspot.com/2010/03/calling-web-service-using-javascript.html" target="_blank">part</a> of the blog we saw how to invoke web methods using javascript. In this blog we will take a look at how to invoke web service methods using Webservice behavior (HTC file). WebService behavior is a component which helps in invoking web service methods using SOAP protocol. The HTC file can be freely downloaded from Microsoft’ <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=1A3F25CA-0387-49A9-8EDC-B8BC0309A2E1&displaylang=en" target="_blank">site</a>. By default HTC file support asynchronous invocation of web service methods. One can enable synchronous way of invocation as well, but do keep in mind that synchronous invocation can freeze the screen (browser) till the web method execution is completed, which may not be desired in web application.</p> <p><strong><u>Making use of WebService behavior (HTC file)</u></strong></p> <p align="justify">To make use of WebService behavior to invoke web service methods we need to download webservice.htc file from <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=1A3F25CA-0387-49A9-8EDC-B8BC0309A2E1&displaylang=en" target="_blank">here</a>. Once you have downloaded the HTC file save it in any folder in your website. Once the “webservice.htc” file has been downloaded and saved in your application the next thing is to hook up the “htc” file to any of the html control using the style attribute. Once you have attached the “htc” file to a control then you can use the various methods in the “htc” file to invoke web service methods. Sample javascript code and web service is pasted below. </p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="508" bgcolor="#ffffff"> <tbody> <tr> <td width="506"> <p><body> <br><script language="javascript" type="text/javascript"> <br>function callWebService() <br>{ <br> var webSer = document.getElementById("webServiceHTC"); <br> webSer.useService(“<a href="http://localhost:3150/TestService.asmx?wsdl”">http://localhost:3150/TestService.asmx?wsdl”</a>, "ServiceTest"); <br> var uniqueID = webSer.ServiceTest.callService(handleResult, "HelloWorld"); <br>} <br>function handleResult(result) <br>{ <br> alert(result.value); <br>} <br></script> <br> <form id="form1" runat="server"> <br> <input type=”text” id="webServiceHTC" style="behavior:url(htc/webservice.htc)"/> <br> <asp:Button ID="javascripWSInvoke" runat="server" Text="Invoke" OnClientClick="javascript:callWebService(); return false;" /> <br> </form> <br></body> </p> <p>//Web service method </p> <p>[WebMethod] <br>public string HelloWorld() <br>{ <br> return "Hello World"; <br>}</p></td></tr></tbody></table> <p align="justify">In the code pasted above, we are attaching the “webservice.htc” file using the html “style” property of an html control. Once the “webservice.htc” file is attached to a html control you can access the “htc” file by retrieving the control using the “getElementById” javascript method. As you can see, from the above code, we are retrieving the textbox control using the “getElementById” method and we are making use of the “useService” method defined in the “webservice.htc” file. Using the “useService” method one can register a web service and give it a friendly name. The method takes two arguments, first is the url of the web service and the second is the friendly name. The friendly name is then used along with the control to invoke web service methods, as pasted in the above code, where we are using the friendly name along with “callService” method to invoke web method. “callService” method has optional first argument which is the name of the javascript function which will handle the result returned from the web method, second argument is the name of the web method which needs to be invoked and then list of parameters separated by comma. </p> <p align="justify">“handleResult” method handles the result returned from the web service method. The method takes an argument which will hold the value returned from the web service method. In the “handleResult” we are showing the output in a alert message. The result argument will have four properties namely “error”, “id”, “raw” and “value”. “error” is a boolean value which indicates whether there was any error, “id” holds the unique id returned while invoking the web method, “raw” will have the raw XML and “value” will have the actual value returned from the web service method. “value” property can have simple as well as complex objects. </p> <p align="justify"><strong><u>Passing parameters to a web method.</u></strong></p> <p align="justify">The above sample was a simple web method invocation without parameters. Now, lets see how to pass parameters to a web method.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="509" bgcolor="#ffffff"> <tbody> <tr> <td width="507"> <p>function passParameter() <br>{ <br> //Getting the htc file attached object. <br> var txtCntl = document.getElementById("divHTC"); <br> //Assigning the web service url. <br> txtCntl.useService("<a href="http://localhost:3150/TestService.asmx?wsdl"">http://localhost:3150/TestService.asmx?wsdl"</a>, "webServ"); <br> //Variables to pass as arguments to the web method. <br> var fName = "Sandeep"; <br> var lName = "P R"; <br> var mName = ""; <br> //Invoking the "CombineName" web method. <br> var uniqueID = txtCntl.webServ.callService(handleResult, "CombineName", fName, mName, lName); <br>} </p></td></tr></tbody></table> <p align="justify">The above code is pretty much the same as the one we have previously used to invoke a web method. The only difference here is that we are passing arguments as a comma separated list to “callService” method. As explained before the first two arguments of “callService” method take the name of the javascript function which handles the response and second argument is the name of the web method to be invoked. The next set of arguments starting from the third arguments are the parameters which needs to be passed to the web method. You can pass any number of arguments separated by comma. Once the web method returns the output the control is passed to “handleResult” javascript method which does nothing other than elegantly showing output in a alert box. </p> <p align="justify">Lets see the code for the web method invoked in the above javascript method.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="509" bgcolor="#ffffff"> <tbody> <tr> <td width="507"> <p>[WebMethod] <br>public string CombineName(string firstName, string midleName, string lastName) <br>{ <br> return string.Concat(string.Concat(firstName, " - ", midleName), " - ", lastName); <br>}</p></td></tr></tbody></table> <p align="justify">The above web method is pretty straight forward. It concatenates all the arguments passed into it and returns it as a single string. </p> <p align="justify"><strong><u>Sending complex objects to a web method</u></strong></p> <p align="justify">We have invoked web method without parameter, with parameters and next is what? Obviously, passing complex objects to a web service method. It is very much possible to pass complex objects to a web method using web service behavior. Below seeing the javascript code in action lets see the code for the web service method and complex object which forms the method argument.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="509" bgcolor="#ffffff"> <tbody> <tr> <td width="507"> <p>//Web service method which takes complex object "Car" as an argument. <br>[WebMethod] <br>public string GetCar(Car car) <br>{ <br> return "Model: " + car.Model + ", Cubic capacity: " + car.CC + ", Color: " + car.Color; <br>} </p> <p>//The "Car" class. <br>public class Car <br>{ <br> public string Model <br> { <br> get; <br> set; <br> } </p> <p> public int CC <br> { <br> get; <br> set; <br> } </p> <p> public string Color <br> { <br> get; <br> set; <br> } <br>}</p></td></tr></tbody></table> <p align="justify">The above web method is pretty straight forward, it takes a complex object (Car) as one of its argument and concatenates all the properties of the “Car” class and returns it as a string. Now lets see how to pass the complex “Car” object to the web method using javascript and webservice behavior.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="507" bgcolor="#ffffff"> <tbody> <tr> <td width="505"> <p>//Javascript method which sends complex "Car" object as an argument to web service method. <br>function sendComplexObject() <br>{ <br> var ccar = new Object(); <br> ccar.Model = "Ferrari"; <br> ccar.CC = 2345; <br> ccar.Color = "Ferrari Red"; <br> ccar.Blah = "dlkjs"; <br> var txtCntl = document.getElementById("divHTC"); <br> txtCntl.useService("<a href="http://localhost:3150/TestService.asmx?wsdl"">http://localhost:3150/TestService.asmx?wsdl"</a>, "webServ"); <br> var uniqueID = txtCntl.webServ.callService(handleResult, "GetCar", ccar); <br>} <br>//Method which handles the response. <br>function handleResult(result) <br>{ <br> alert(result.value); <br>}</p></td></tr></tbody></table> <p align="justify">In the above “sendComplexObject” javascript function we are first creating a javascript object of type “Object”. Once the object of type “Object” is created, we are dynamically adding properties to the object. One thing to note here is that the dynamically added properties should have the same name as that of the server side object properties and it is case sensitive. If you closely notice the above code we have added an extra property called “Blah” to the “Car” object. Now, you may be thinking how is this object of “Object” type getting converted to a strongly typed .NET object. When the web method is invoked using “callService” method, the HTC file has got the necessary code to read the schema and infer the type of argument the method takes and converts the properties into a XML and sends to the web service method. In the web service side the .NET runtime takes care of serializing the XML to respective .NET object. We have added an additional “Blah” property to the object which during serialization is not converted as there is no corresponding server side property.</p> <p align="justify">Note: If you have any value type in your complex object (like “CC” property in the “Car” object) then make sure that you assign them a value (default) even if you are not going to use it in the server side, else while invoking the web method the server can throw “System.FormatException”. The details of the exception which was thrown while not assigning the “CC” property of the “Car” object is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="479" bgcolor="#ffffff"> <tbody> <tr> <td width="477"> <p><font color="#ff0000">System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (7, 22). ---> System.FormatException: Input string was not in a correct format. <br> at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) <br> at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) <br> at System.Xml.XmlConvert.ToInt32(String s) <br> at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read3_Car(Boolean isNullable, Boolean checkType) <br> at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read8_GetCar() <br> at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer8.Deserialize(XmlSerializationReader reader) <br> at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) <br> --- End of inner exception stack trace --- <br> at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) <br> at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle) <br> at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() <br> --- End of inner exception stack trace --- <br> at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() <br> at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</font></p></td></tr></tbody></table> <p><strong><u>How to handle complex objects returned from the server?</u></strong></p> <p align="justify">There can be scenarios where the server may return complex objects back to the caller. How to handle complex objects in javascript? Don’t worry with HTC file that is also a child’ play. Below is a web method which returns a complex “Car” object. We have slightly altered the “Car” class.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="508" bgcolor="#ffffff"> <tbody> <tr> <td width="506"> <p>//Method that returns a complex Car object. <br>[WebMethod] <br>public Car GetCarObject() <br>{ <br> return new Car { Model = "Ferrari", Color = "Ferrari Red", CarEngine = new Engine { CC = 2500, Cylinders = 8 } }; <br>} </p> <p>//Car class. <br>public class Car <br>{ <br> public string Model <br> { get; set; } <br> public string Color <br> { get; set; } <br> public Engine CarEngine <br> { get; set; } <br>} <br>//Engine class which is a property in Car class <br>public class Engine <br>{ <br> public int CC <br> { get; set; } <br> public int Cylinders <br> { get; set; } <br>}</p></td></tr></tbody></table> <p align="justify">In the web method we are creating an instance of the “Car” class and returning it. The “Car” class is quite simple, it has a number of properties and in those properties one of the property is again a complex object of type “Engine”. Below is the javascript code which handles the complex object returned from the web service.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="513" bgcolor="#ffffff"> <tbody> <tr> <td width="511"> <p>function receiveComplexObject() <br>{ <br> var txtCntl = document.getElementById("divHTC"); <br> txtCntl.useService("<a href="http://localhost:3150/TestService.asmx?wsdl"">http://localhost:3150/TestService.asmx?wsdl"</a>, "webServ"); <br> var uniqueID = txtCntl.webServ.callService(handleComplexObject, "GetCarObject"); <br>} <br>//Function handling the complex object. <br>function handleComplexObject(result) <br>{ <br> var carObj = result.value; <br> var carProperties = "Model: " + carObj.model + ", Color: " + carObj.Color + ", CarEngine.CC: " + carObj.CarEngine.CC + ", CarEngine.Cylinders: " <br> + carObj.CarEngine.Cylinders; <br> alert(carProperties); <br>}</p></td></tr></tbody></table> <p align="justify"><strong>“</strong>handleComplexObject” function handles the complex “Car” object returned from the server. The “value” property of the result object holds the complex object. You can access the various properties and fields in a complex object by specifying the names of the properties or fields as done in the above e.g.</p> <p><strong><u>How to handle server errors in client Side?</u></strong></p> <p align="justify">We have seen the different ways of invoking a web method with parameters, without parameters and with complex parameters. As we all know everything doesn’t work according our plan, so what happens if the server throws an error? Handling errors from server is also pretty much simple.The method which is specified in “callService” method to handle the result takes an argument. The result object passed as an argument to the callback function which handles the request from the service has got the necessary information to handle errors. Lets see with e.g.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="509" bgcolor="#ffffff"> <tbody> <tr> <td width="507"> <p>//Javascript function which is supposed to throw error. <br>function sendComplexObject() <br>{ <br> var ccar = new Object(); <br> ccar.Model = "Ferrari"; <br> ccar.Color = "Ferrari Red"; <br> var txtCntl = document.getElementById("divHTC"); <br> txtCntl.useService("<a href="http://localhost:3150/TestService.asmx?wsdl"">http://localhost:3150/TestService.asmx?wsdl"</a>, "webServ"); <br> var uniqueID = txtCntl.webServ.callService(handleError, "GetCar", ccar); <br>} <br>//Function which handles server side error. <br>function handleError(result) <br>{ <br> if (result.error) <br> { <br> var errorDetails = "Error code: " + result.errorDetail.code; <br> errorDetails += "\nError string: " + result.errorDetail.string; <br> errorDetails += "\nError soap format: " + result.errorDetail.raw.xml; <br> alert(errorDetails); <br> } <br> else <br> { <br> alert(result.value); <br> } <br>}</p></td></tr></tbody></table> <p>The above pasted code is pretty straight forward. The “handleError” function like other callback function in this blog takes a result object as argument. The first line of the function checks whether there is any error in the result returned from the server by checking the “error” property of the result object. If there is an error the next three lines of code retrieve the error details by accessing the “errorDetail” property’ “code”, “string” and “raw.xml” properties. The code property returns the code for the error, “string” property returns the error message and “raw.xml” returns the whole SOAP xml. </p> <p>So that’ some of the key features of webservice behavior. In the next blog we will see how to make use of “ScriptManager” to invoke web methods. Till then try to know more.</p> <p>Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com13tag:blogger.com,1999:blog-1454785102765291191.post-53990352907863899482010-03-15T23:14:00.000+05:302012-07-04T14:43:45.104+05:30Calling web service using javascript. Part - 1<p align="justify">Many a times there was this pressing need where I had to call a web service method and get the output and use it in javascript. There were many options available like making use of javascript to call web service method or using some third party javascript library or by making use of webservice behavior (HTML Component (HTC) file) or making use of AJAX and calling an ASPX page which in turn calls a webservice in the code behind and returns the output as XML or if you are using ASP.NET 2.0 then you can make use of “ScriptManager”. We will see all the above ways of invoking a webservice one by one except making use of third party javascript library. As there are many third party javascript libraries available in the internet so we will not concentrate on any as each have different ways of implementation. Lets see each of the methods in action one by one.</p> <p align="justify"><strong><u>Using javascript to invoke web service methods</u></strong></p> <p align="justify">One of the simplest and easiest way is to invoke web service methods is by making use of “XMLHttpRequest” objects in javascript. Before invoking the web service method using javascript lets see the web service methods which we are going to be invoked using javascript. Below are two sample methods which we are going to be invoked using javascript.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="512" bgcolor="#ffffff"> <tbody> <tr> <td width="510"> <p>public class TestService : System.Web.Services.WebService <br>{ <br> [WebMethod] <br> public string HelloWorld() <br> { <br> return "Hello World"; <br> } <br> [WebMethod] <br> public string CombineName(string firstName, string midleName, string lastName) <br> { <br> return string.Concat(string.Concat(firstName, " - ", midleName), " - ", lastName); <br> } <br>}</p></td></tr></tbody></table> <p align="justify">The above two methods are pretty straight forward, one returns a string and the other takes three string arguments and combines them and returns as a string. We will see how to call a web service method without parameters and with parameters. Lets first see how to call the “HelloWorld” web method which doesn’t take any parameter. Below is the javascript code for invoking the “HelloWorld” web method.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="511" bgcolor="#ffffff"> <tbody> <tr> <td width="509"> <p>function webServiceCallWithoutParameters() <br>{ <br> var xmlHttpReq = new XMLHttpRequest(); <br> xmlHttpReq.open("POST", "<a href="http://localhost/TestService.asmx/HelloWorld"">http://localhost/TestService.asmx/HelloWorld"</a>, false); <br> xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); <br> xmlHttpReq.send(); <br> alert(xmlHttpReq.responseXML.childNodes[1].text); <br>}</p></td></tr></tbody></table> <p align="justify">In the above javascript function we are making use of “XMLHttpRequest” object to invoke web service method. We are making use of the “open” method which takes three arguments, first argument says whether the method used is “POST” or “GET”, second argument is the url for the web service and the third argument is to specify whether the “XMLHttpRequest” should be synchronous or asynchronous. The url for a .NET web method always ends with the name of the web method preceded by the url of the web service as shown in the above e.g. Once we have set the url and the method used to call the web service, in the next line we are setting the “Content-Type” for the request using the “setReqeustHeader” method of the “XMLHttpReqeust” object. Its very important to set the “Content-Type” of the request to “application/x-www-form-urlencoded” when you are trying to invoke a web service method, if the “Content-Type” is not set to “application/x-www-form-urlencoded” the following error will be thrown when you try to pass arguments to a web service method.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="511" bgcolor="#ffffff"> <tbody> <tr> <td width="509"> <p>status: 500 <br>statusText: Internal Server Error <br>responseText: System.InvalidOperationException: Request format is invalid: . at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</p></td></tr></tbody></table> <p align="justify">The status property of the “XMLHttpReqeust” object will have a value of 500, the “statusText” will be having “Internal Server Error” as the message and the “responseText” will have the type of error. To solve the problem set the “Content-Type” for the request as shown in the above e.g.</p> <p align="justify">Now let’ see how to pass parameters to a web method. </p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="514" bgcolor="#ffffff"> <tbody> <tr> <td width="512"> <p>var xmlHttpReq = new XMLHttpRequest(); <br>xmlHttpReq.open("POST", "<a href="http://localhost:3150/TestService.asmx/CombineName"">http://localhost:3150/TestService.asmx/CombineName"</a>, false); <br>xmlHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); <br>xmlHttpReq.send("firstName=Sandeep&midleName=mid&lastName=p r"); <br>alert(xmlHttpReq.responseXML); </p></td></tr></tbody></table> <p align="justify">In the above javascript function we are invoking the “CombineName” web method which takes three parameters. Everything else is the same as the previous javascript function except for the “send” method of the “XMLHttpReqeust” object. In the “send” method we are passing the parameters separated by the ampersand (&) symbol. To pass parameter to a web method you can use the “send” method of the “XMLHttpRequest” object. The parameters and their values should be separated by the “equal to” (=) symbol and each set of parameters should be separated by the ampersand symbol. </p> <p align="justify">After this the next obvious question would be how to send complex objects to a web methods. There is no straight forward way of doing this, one can make use of Javascript Object Notations (JSON). You can find lots of e.g. on how to pass JSON over the net. Also you can use “WebService” behavior (HTC file) to send and receive complex objects or one can use “ScriptManager” to send and receive complex objects. We will see “HTC file” and “ScriptManager” usage in subsequent blogs. Receiving a complex object is pretty easy. When you invoke a web method and if that web method returns a complex object then the object will be serialized into a XML and the XML can be accessed through the “responseText” or “responseXML” property of the “XMLHttpRequest” object. Lets see with an e.g. Below is the web method code which returns a “Car” complex object.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="510" bgcolor="#ffffff"> <tbody> <tr> <td width="508"> <p>[WebMethod] <br>public Car GetCarObject() <br>{ <br> return new Car { Model = "Ferrari", Color = "Ferrari Red", CC = 2555 }; <br>}</p> <p>//Car Class is pasted below.</p> <p>public class Car <br>{ <br> public string Model <br> { <br> get; set; <br> } <br> public int CC <br> { <br> get; set; <br> } <br> public string Color <br> { <br> get; set; <br> } <br>}</p></td></tr></tbody></table> <p align="justify">The above web method is pretty straight forward. It creates an instance of a “Car” class and returns the same. The “Car” class is also pasted. The javascript method to invoke the above web method which returns “Car” complex object is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="513" bgcolor="#ffffff"> <tbody> <tr> <td width="511"> <p>function getComplexObject() <br>{ <br> var xmlHttpReq = new XMLHttpRequest(); <br> xmlHttpReq.open("POST", "<a href="http://localhost:3150/TestService.asmx/GetCarObject"">http://localhost:3150/TestService.asmx/GetCarObject"</a>, false); <br> xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); <br> xmlHttpReq.send(); <br> alert(xmlHttpReq.responseText); <br>}</p></td></tr></tbody></table> <p>The output returned in the form of the XML is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="513" bgcolor="#ffffff"> <tbody> <tr> <td width="511"> <p><?xml version="1.0" encoding="utf-8"?> <br><Car xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance"">http://www.w3.org/2001/XMLSchema-instance"</a> xmlns:xsd="<a href="http://www.w3.org/2001/XMLSchema"">http://www.w3.org/2001/XMLSchema"</a> xmlns="<a href="http://tempuri.org/"">http://tempuri.org/"</a>> <br> <Model>Ferrari</Model> <br> <CC>2555</CC> <br> <Color>Ferrari Red</Color> <br></Car></p></td></tr></tbody></table> <p align="justify">As you can see in the above XML the complex object returned by the web method is serialized as XML. That's about invoking web methods using javascript. In my next blog we will see how to invoke web methods using “WebService behviour” or by using “HTC file”. Till then try to know more.</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com8tag:blogger.com,1999:blog-1454785102765291191.post-75844348923103933552010-02-28T21:38:00.001+05:302010-02-28T21:38:25.058+05:30Visual Studio 2010 features preview.<p align="justify">Today I got an opportunity to attend the “Visual Studio 2010 Pit stop” in Chennai. If I am not wrong it is a pre launch event which Microsoft is conducting in different cities to generate interest and gauge developers reaction on the various features which is getting introduced in VS 2010. I thought why not blog on some of the features which were demoed. </p> <p align="justify">With the release of VS 2010 Microsoft is trying to make Visual Studio capable of managing all the phases of Application Lifecycle Management (ALM). They want VS 2010 to target developers, architects and testers. Lets see what VS 2010 brings to the table for different audience it targets.</p> <p align="justify"><strong><u>For developers</u></strong></p> <p align="justify">The first feature which was demoed was simple yet powerful, which was targeted towards developers like me, who hate to drag and drop controls from the toolbox instead prefer writing the controls in HTML view. The feature is a kind of auto complete whereby when in the HTML view of an aspx page you need to type the name of the control and from the intellisense one need to select the control and press tab and VS 2010 will add the full tag with ID, Text and other properties. Though the beta release of VS 2010 which was used for the demo didn’t auto generate ID and other properties, it only auto generated “Text” property, but it was promised that the production version would generate most of the relevant properties like ID etc.</p> <p align="justify">Another feature was a template kind of feature for creating web sites where you get pre-configured pages for login, user registration etc. One gets a full website with some color scheme applied and .mdf file in the “App_data” folder. The .mdf database has all the tables for user management and one can generate schema from this .mdf and recreate the tables in Sql Server 2005/2008. One can use the login, user registration pages without doing any changes or writing any code. Now creating a website is just few clicks away. Microsoft is making the life of a developer easy. Is it? I would say nah, with all these automatic features the developer will forget coding and he will become a lazy bum. Nowadays, when I do interviews many a developers don’t know many of the basics, with all these new changes the next generation developers job will have less of coding and more of configuration. </p> <p align="justify">Next feature was the business layer code generation feature from the Entity framework. You need to follow some of the steps in a wizard and select the needed tables from the database and voila you have your Business Access Layer (BAL) auto generated code. If you tie this auto generated BAL layer to a grid and set some properties you have a grid which is capable of adding, deleting, updating, sorting records without writing a single line of code. One also gets search integration using new search extender control where you need set some properties and you can filter your records based on the search criteria. </p> <p align="justify"><strong><u>IntelliTrace</u></strong></p> <p align="justify">The IntelliTrace feature like Intellisense is going to become a huge hit with developers. With intellitrace you can exactly pinpoint which line of the code threw the exception with values which were passed to the function. Intellitrace feature in combination with Test and Lab management features of VS 2010 is going to rock. </p> <p align="justify"><strong><u>For Architects</u></strong></p> <p align="justify">For the architects visual studio supports UML diagram drawing capabilities. You can draw class diagrams, dependency diagrams, sequence diagrams etc which were earlier done in Visio or some other tool. The architects can have validation checks on dependency during compile time or whatever policies they have set. For e.g. take a simple e.g. where we have a Presentation layer, Business Access Layer and Data Access Layer. The architect doesn’t want the presentation layer to interact with DAL. He can set a constraint like this and during compile time the system will throw an error if the constraints is broken. Also you can restrict classes in a dll from interacting with other dlls. One can generate sequence diagram from methods by right clicking on the method and selecting some option from the context menu.</p> <p><strong><u>Visual Studio Test and Lab management</u></strong></p> <p align="justify">This feature of VS 2010 just blew my head away. This feature is aimed at the testers but I feel this feature will be a boon to the developers. In this feature the testers will have provision to add their manual test steps and record them and then replay them. The feature works like this. The testers will first enter all the manual test steps like the following in an UI.</p> <p align="justify">1. “Open IE and type the following url: <a href="http://someone.com">http://someone.com</a>”.</p> <p align="justify">2. Click register link from the UI.</p> <p align="justify">3. Fill first name with “Sandeep”</p> <p align="justify">4. Fill last name with “P.R”</p> <p align="justify">5. Fill email field with <a href="mailto:“sndppr@gmail.com">“sndppr@gmail.com</a>”</p> <p align="justify">6. Fill the password field with “123456”</p> <p align="justify">7. Fill the confirm password field with “123456”</p> <p align="justify">8. Click the “Register” button.</p> <p align="justify">Once the steps are done the tester can now start recording the steps. The advantage of this feature is that if there is an error in step 8 the tester need not repeat all the steps manually. Once the recording is over he can replay the steps upto step 8 and he need not manually do all the above steps. Think of a situation where there are 50 steps and the error happens in the 45th step then once the bug is fixed the tester has to repeat all the 44 steps manually to reach the 45th step which threw error. Just by recording the steps he can play them back up to the 44th step and then carry on the recording from the 45th step. Can you imagine how much time will be saved on this? It will be huge. Hats off to Microsoft for this.</p> <p align="justify">That’ not all. What happens when a tester posts a bug? Bang comes the reply from the developer, “it works on my system, so sorry boss its not a bug”. Some developer even go to the extend where they ask to reproduce the bug. Poor tester, he has to repeat the whole 44 steps to show the bug. Not any more. Once the tester finds a bug he can use the new features to post the bug while he is recording and can assign the bug to a developer. The developer when he gets the bug has got links to view the video of the recording where he can exactly see what the tester has done to reproduce the error. Now there will be no more tester developer acrimony. Also to top it all he will get the IntelliTrace link along with the link to view the video. When the developer clicks the IntelliTrace link, it goes to repository (Team Foundation Server [TFS]) and opens your code and shows you the exact place where the error occurred. Not only this, it gives you the exact values which were used by the tester and which were passed to the function. Just by clicking a link you can know the exact line number where the error has happened and the data which caused the problem. Isn’t it so cool. IntelliTrace is gonna ROCK. Developers, our life is going to be simple. :) With IntelliTrace, I think, the bug fixing time taken by the developers will be reduced to 1/4th of what a normal developer takes. Wow that’ really superb. After all time is money.</p> <p align="justify">With the above features and many more, Visual Studio 2010 is going to <strong><font color="#ff0000">ROCK</font></strong>. Waiting to get my hands dirty with VS 2010.</p> <p align="justify">Try to know more….</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com1tag:blogger.com,1999:blog-1454785102765291191.post-83424094411982467752010-02-07T22:52:00.001+05:302010-04-26T14:23:22.050+05:30Extending the membership provider.<p align="justify">Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider class but don’t give you what other class they have used in the backend. With this blog I would not only show how to extend MembershipProvider class but will give you the full source code of the web service which is used instead of a database as a backend. </p> <p align="justify">I have made use of the MembershipProvider many a times but I would like to share my experience in one of my project where I had to extend the MembershipProvider class to make use of an already existing web service of the client to validate user, create user, change password etc. In this blog I will show how to extend MembershipProvider class and write your custom MembershipProvider class.</p> <p align="justify">Since I cannot reveal what webserivce was used in the website developed for the client I will create my own webservice to mimic the exact behavior as in the website. So lets start by creating a webservice which will have methods to create a user, validate user credentials and finally change the user’ password. Once the webservice is done we will extend the membership class. Below is the code for the webservice.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="663" bgcolor="#ffffff"><tbody> <tr> <td> <p>[WebService(Namespace = "<a href="http://tempuri.org/")]">http://tempuri.org/")]</a> <br />[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] <br />public class WebServiceAuthentication : System.Web.Services.WebService <br />{ <br />    string xmlFilePath = string.Empty; <br />    public WebServiceAuthentication() <br />    { <br />        xmlFilePath = Server.MapPath("data/users.xml");        <br />    } </p> <p>    [WebMethod] <br />    public bool ChangePassword(string username, string newpassword) <br />    { <br />        XDocument users = XDocument.Load(xmlFilePath); <br />        var user = from u in users.Elements("user") <br />                   where u.Element("username").Value.ToLower() == username.ToLower() <br />                   select u; <br />        if (user != null && user.Count() > 0) <br />        { <br />            user.First().Element("password").Value = newpassword; <br />            return true; <br />        } </p> <p>        return false; <br />    } </p> <p>    [WebMethod] <br />    public bool ValidateUser(string userName, string passWord) <br />    { <br />        XDocument users = XDocument.Load(xmlFilePath); <br />        var user = from u in users.Element("users").Elements("user") <br />                   where u.Element("username").Value.ToLower() == userName.ToLower() && u.Element("password").Value == passWord <br />                   select u; <br />        if (user != null && user.Count() > 0) <br />            return true; <br />        return false; <br />    } </p> <p>    [WebMethod] <br />    public Customer CreateUser(string username, string password, string emailID) <br />    { <br />        XDocument users = XDocument.Load(xmlFilePath); <br />        var user = from u in users.Elements("user") <br />                   where u.Attribute("email").Value.ToLower() == username.ToLower() <br />                   select u.Attribute("email").Value; <br />        if (user.Count() <= 0) <br />            throw new Exception("Email already in user"); <br />        else <br />        { <br />            users.Element("users").Add(new XElement("user", <br />                new XAttribute("email", emailID), <br />                new XElement("userName", username), <br />                new XElement("password", password))); <br />            users.Save(xmlFilePath); <br />        } </p> <p>        return new Customer { UserName = username }; <br />    } </p> <p>    [WebMethod] <br />    public string ResetPassword(string username) <br />    { <br />        string newPass = string.Empty; <br />        XDocument users = XDocument.Load(xmlFilePath); <br />        var user = from u in users.Elements("user") <br />                   where u.Element("username").Value.ToLower() == username.ToLower() <br />                   select u; <br />        if (user != null && user.Count() > 0) <br />        { <br />            newPass = Guid.NewGuid().ToString().Substring(0, 10); <br />            user.First().Element("password").Value = newPass; <br />        } <br />        else <br />            throw new Exception("User not found."); </p> <p>        return newPass; <br />    } </p> <p>    [WebMethod] <br />    public bool UpdateCustomer(Customer customerToBeUdpated) <br />    {        <br />        XDocument users = XDocument.Load(xmlFilePath); <br />        var userToBeUpdated = (from u in users.Elements("user") <br />                              where u.Attribute("email").Value.ToLower() == customerToBeUdpated.UserName.ToLower() <br />                              select u); <br />        if (userToBeUpdated != null && userToBeUpdated.Count() > 0) <br />        { <br />            XElement user = userToBeUpdated.First(); <br />            user.Element("password").Value = customerToBeUdpated.Password; <br />            if (user.Element("firstname") != null) <br />                user.Element("firstname").Value = customerToBeUdpated.FirstName; <br />            else <br />                user.Add(new XElement("firstname", customerToBeUdpated.FirstName)); <br />            if (user.Element("lastname") != null) <br />                user.Element("lastname").Value = customerToBeUdpated.LastName; <br />            else <br />                user.Add(new XElement("lastname", customerToBeUdpated.LastName)); <br />            if (user.Element("address") != null) <br />            { <br />                user.Element("address").Element("street").Value = customerToBeUdpated.Address.Street; <br />                user.Element("address").Element("city").Value = customerToBeUdpated.Address.City; <br />                user.Element("address").Element("state").Value = customerToBeUdpated.Address.State; <br />                user.Element("address").Element("country").Value = customerToBeUdpated.Address.Country; <br />            } <br />            else <br />            { <br />                user.Add(new XElement("address", new XElement("street", customerToBeUdpated.Address.Street), <br />                    new XElement("city", customerToBeUdpated.Address.City), <br />                    new XElement("state", customerToBeUdpated.Address.State), <br />                    new XElement("country", customerToBeUdpated.Address.Country))); <br />            } </p> <p>            return true; <br />        } </p> <p>        return false; <br />    } <br />} </p> </td> </tr> </tbody></table> <p align="justify">In the above web service we have methods to change the password (ChangePassword), to validate user credential based on user name and password (ValidateUser), method to create a user (CreateUser), method to change the password (ResetPassword) and finally method to update user details (UpdateCustomer). All these methods work on a XML file and make use of LINQ to XML to create user, change password etc. As mentioned before all the data is stored and retrieved from a XML file called Users.xml. If a new user has to be added or user details needs to be updated or password needs to be changed everything is done in the xml. The webservice makes use of a XML as a storage medium.The XML is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="663" bgcolor="#ffffff"><tbody> <tr> <td> <p><?xml version="1.0" encoding="utf-8" ?> <br /><users> <br />  <user email="a@a.com"> <br />    <username>sandeep</username> <br />    <password>pass</password> <br />    <firstname>Sandeep</firstname> <br />    <lastname>P.R</lastname> <br />    <address> <br />      <street>Blah blah</street> <br />      <city>City</city> <br />      <state>State</state> <br />      <country>Country</country> <br />    </address> <br />  </user> <br />  <user email="sndppr@gmail.com"> <br />    <username>sndppr@gmail.com</username> <br />    <password>pass</password> <br />    <firstname>Sandeep</firstname> <br />    <lastname>P.R</lastname> <br />    <address> <br />      <street>Blah blah</street> <br />      <city>City</city> <br />      <state>State</state> <br />      <country>Country</country> <br />    </address> <br />  </user> <br /></users></p> </td> </tr> </tbody></table> <p align="justify">The xml is pretty much straight forward. The XML stores the user name, password and other user related details like his address and email id. In the XML the password is saved as plain text which is not a good way of storing password. So while storing password in a physical file do use some sort of encryption.</p> <p align="justify">Some of the methods of the web service return “Customer” as an object. The “Customer” class is also very straight forward. It derives from the “System.Web.Security.MembershipUser” class and adds some of its own properties. The “Customer” class code is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="663" bgcolor="#ffffff"><tbody> <tr> <td> <p>public class Customer : System.Web.Security.MembershipUser <br />{ <br />    public Customer() <br />    { </p> <p>    } </p> <p>    private string userName = string.Empty; </p> <p>    public string FirstName { get; set; } <br />    public string LastName { get; set; } <br />    public string UserName { get; set; } <br />    public string EMail { get; set; } <br />    public string Password { get; set; } <br />    public Address Address { get; set; } <br />} </p> <p>public class Address <br />{ <br />    public string Street { get; set; } <br />    public string City { get; set; } <br />    public string State { get; set; } <br />    public string Country { get; set; } <br />}</p> </td> </tr> </tbody></table> <p align="justify">That’s about web serivce and the XML file which form the backend, now lets try to extend System.Web.Security.MembershipProvider to work in conjunction with the above web service. Before that lets keep some things in mind. If you are not planning to make use of question and answer to reset the password then make sure that you return false from “RequiresQuestionAndAnswer” property. If you leave the default implementation then the system will throw “Sysmtem.NotImplementedException” with the following error message.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="663" bgcolor="#ffffff"><tbody> <tr> <td>The method or operation is not implemented. </td> </tr> </tbody></table> <p align="justify">Now lets see the code where I have extended the System.Web.Security.MembershipProvider class. Some of the methods which have not been implemented have been removed for brevity.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="663" bgcolor="#ffffff"><tbody> <tr> <td> <p>public class CustomMembershipProvider : System.Web.Security.MembershipProvider <br />{ <br />    public CustomMembershipProvider() : base() <br />    { <br />    } </p> <p>    public override string ApplicationName <br />    { <br />        get <br />        { <br />            return "Authentication"; <br />        } <br />        set <br />        { <br />            throw new NotImplementedException(); <br />        } <br />    } <br />    //Non implemented methods have been removed for brevity. <br />    public override bool ChangePassword(string username, string oldPassword, string newPassword) <br />    { <br />        WebServiceAuthentication wsa = new WebServiceAuthentication(); <br />        return wsa.ChangePassword(username, newPassword); <br />    } </p> <p>    public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) <br />    { <br />        MembershipUser cust = this.GetUser(username, false);        </p> <p>        if (cust == null) <br />        { <br />            WebServiceAuthentication wsa = new WebServiceAuthentication(); <br />            cust = wsa.CreateUser(username, password, email); <br />            status = cust != null ? MembershipCreateStatus.Success : MembershipCreateStatus.UserRejected; <br />        } <br />        else <br />            status = MembershipCreateStatus.DuplicateUserName; <br />        return cust; <br />    } </p> <p>    public override MembershipUser GetUser(string username, bool userIsOnline) <br />    { <br />        WebServiceAuthentication wsa = new WebServiceAuthentication(); <br />        MembershipUser mu = wsa.GetUser(username); <br />        return mu; <br />    } </p> <p>    public override int MinRequiredNonAlphanumericCharacters <br />    { <br />        get { return 0; } <br />    } </p> <p>    public override int MinRequiredPasswordLength <br />    { <br />        get { return 2; } <br />    } </p> <p>    public override bool RequiresQuestionAndAnswer <br />    { <br />        get { return false; } <br />    } </p> <p>    public override bool RequiresUniqueEmail <br />    { <br />        get { return false; } <br />    } <br />    //Non implemented methods have been removed for brevity </p> <p>    public override void UpdateUser(MembershipUser user) <br />    { <br />        WebServiceAuthentication wsa = new WebServiceAuthentication(); <br />        wsa.UpdateCustomer(user); <br />    } </p> <p>    public override bool ValidateUser(string username, string password) <br />    { <br />        WebServiceAuthentication wsa = new WebServiceAuthentication(); <br />        if (wsa.ValidateUser(username, password)) <br />        { <br />            FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(30), true, string.Empty); <br />            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(fat)); <br />            HttpContext.Current.Request.Cookies.Add(authCookie); <br />            return true; <br />        } <br />        else <br />        { <br />            return false; <br />        } <br />    } <br />}</p> </td> </tr> </tbody></table> <p align="justify">In above code I have extended the MembershipProvider class and overridden “ChangePassword”, “CreateUser”, “GetUser”, “UpdateUser” and “ValidateUser” methods. All these methods are pretty straight forward, the methods create an instance of our web service class and call the web methods to change password, create user etc. The before mentioned membership methods are called by the various login controls provided in ASP.NET. “ChangePassword” is called by the “ChangePassword” control when you click the “Change Password” button. “CreateUser” method of the MembershipProvider class is executed when you click the “Create User” button of “CreateUserWizard” control. “ValidateUser” method is called whenever the user request needs validation or when you click the “Log in” button of the “Log in” control.</p> <p align="justify">Once you have extended the MembershipProvider class add the following tag in the web.config file of your website.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="663" bgcolor="#ffffff"><tbody> <tr> <td> <p><membership defaultProvider="CustomProvider" > <br />      <providers>        <br />        <add name="CustomProvider" type="CustomMembershipProvider" />        <br />      </providers>  <br /></membership></p> </td> </tr> </tbody></table> <p align="justify">In the above markup the "defaultProvider" is an optional parameter. If not provided it will default to "AspNetSqlProvider", the default provider provided by Microsoft. The "type" attribute has the name of the extended membership provider class. In our case, since the class is placed in the "App_Code" folder, we have only specified the class name. If your membership provider class lies in some different dll and you have added it as a reference to your website then one has to specify the full name preceded by the namespace as well. Also using the “add” tag in “providers” tag you can set the membership properties like "connectionStringName", "enablePasswordRetrieval", "enablePasswordReset" etc in the. Sample tag is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="663" bgcolor="#ffffff"><tbody> <tr> <td> <p><connectionStrings> <br />    <add name="connStr" connectionString="Data Source=testserver;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=sa"/> <br /></connectionStrings> <br /><!--Membership provider configuration with membership properties set in web.config. The connectionStringName should match with the one provided in you web.config.--> <br /><membership defaultProvider="CustomProvider" > <br />      <providers>        <br />        <add name="CustomProvider" type="CustomMembershipProvider" applicationName="TestApp" connectionStringName="connStr" enablePasswordRetrieval="false" enablePasswordReset="true" maxInvalidPasswordAttempts="5"  />        <br />      </providers>  <br /></membership></p> </td> </tr> </tbody></table> <p align="justify">With this done you can drag and drop the various ASP.NET login controls like the CreateUserWizard, ChangePassword, Login etc and you can create users, change password and login into the application without writing any code in the code behind files where these ASP.NET login controls are used. Isn’t it so easy to use the various ASP.NET login controls once you have extended the MembershipProvider class. </p> <p align="justify">Try to know more</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com6tag:blogger.com,1999:blog-1454785102765291191.post-60822938175893613282010-01-19T21:44:00.001+05:302010-02-18T18:07:35.660+05:30Serialization in .NET – 5<p align="justify">In my previous blogs we have seen <a href="http://sandblogaspnet.blogspot.com/2009/05/serialization-in-net-1.html" target="_blank">Binary serialization</a>, <a href="http://sandblogaspnet.blogspot.com/2009/05/serialization-in-net-2.html" target="_blank">XML serialization</a>, <a href="http://sandblogaspnet.blogspot.com/2009/07/serialization-in-net-3.html" target="_blank">SOAP serialization</a> and <a href="http://sandblogaspnet.blogspot.com/2009/12/serialization-in-net-4.html" target="_blank">Custom serialization</a> using <a href="http://sandblogaspnet.blogspot.com/2009/12/serialization-in-net-4.html" target="_blank">ISerilizable</a> interface. This blog will talk about implementing custom XML serialization using the IXmlSerializable interface. We have seen in my previous blogs on serialization how to control XML and SOAP serialization using attributes. Through attributes we can take control to some extent but not to the fullest. If you want to take full control over the way your class is serialized to XML then you need to use IXmlSerializable interface. </p> <p align="justify">Implementing IXmlSerializable interface is pretty straight forward. The interface has three methods namely “WriteXml (XmlWriter writer)”, “ReadXml (XmlReader reader)” and “GetSchema()”. WriteXml method is called when the object is serialized and ReadXML method is executed when the XmlSerializer deserializes the object. GetSchema method returns a XmlSchema object. As such the GetSchema method is not supposed to do anything other than returning null. The help documentation from MSDN says the following about the method.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p align="justify">“<em>When serializing or deserializing an object, the XmlSerializer class does not perform XML validation. For this reason, it is often safe to omit schema information by providing a trivial implementation of this method, for example by returning nullNothingnullptra null reference (Nothing in Visual Basic) (Nothing in Visual Basic).</em></p> <p align="justify"><em>If providing schema information is necessary, you should use the </em><a href="ms-help://ms.vscc.v90/145d2981-3a50-1535-de8e-25e7a8269bb2.htm"><em>XmlSchemaProviderAttribute</em></a><em> attribute. The GetSchema method should still return nullNothingnullptra null reference (Nothing in Visual Basic) (or Nothing).</em></p> <p align="justify"><em>Some .NET Framework types as well as legacy custom types implementing the IXmlSerializable interface may be using GetSchema instead of XmlSchemaProvider. In this case, the method returns an accurate XML schema that describes the XML representation of the object generated by the WriteXml() method</em>.”</p> </td> </tr> </tbody></table> <p align="justify">Lets dive into the code and implement the interface in our good old “Car” class. One thing to keep in mind before implementing IXmlSerializable interface is that the class which implements the interface should have a parameter less constructor. If the class which is implementing IXmlSerializable interface doesn’t have a parameter less constructor then on serialization the following error will be thrown.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td><font color="#ff0000">Vehicles.Car cannot be serialized because it does not have a parameterless constructor.</font></td> </tr> </tbody></table> <p align="justify">Below is the Car class with IXmlSerializable interface implementation.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p>[System.Xml.Serialization.XmlRoot(Namespace="<a href="http://car/car")]">http://car/car")]</a> <br />public class Car : System.Xml.Serialization.IXmlSerializable <br />{ <br />    #region Properties <br />    public string Color <br />    { get; set; } </p> <p>    public string ModelName <br />    { get; set; } </p> <p>    public int Price <br />    { get; set; } </p> <p>    public double CubicCentimeter <br />    { get; set; } <br />    #endregion </p> <p>    #region IXmlSerializable Members </p> <p>    System.Xml.Schema.XmlSchema System.Xml.Serialization.IXmlSerializable.GetSchema() <br />    { <br />        throw new NotImplementedException(); <br />    } </p> <p>    void System.Xml.Serialization.IXmlSerializable.ReadXml (System.Xml.XmlReader reader) <br />    { <br />        string ns = "<a href="http://car/car";">http://car/car";</a> <br />        if (reader.NodeType == System.Xml.XmlNodeType.Element && reader.Name == "Car") <br />        { <br />            reader.MoveToAttribute("Price"); <br />            this.Price = reader.ReadContentAsInt(); <br />            reader.MoveToElement(); <br />        } </p> <p>        reader.Read();</p> <p>        if (reader.NodeType == System.Xml.XmlNodeType.Element && reader.Name == "ModelName") <br />        { <br />            this.ModelName = reader.ReadElementContentAsString(); <br />        } </p> <p>        if (reader.NodeType == System.Xml.XmlNodeType.Element && reader.Name == "CC") <br />        { <br />            this.CubicCentimeter = reader.ReadElementContentAsDouble() ; <br />        } </p> <p>        if (reader.NodeType == System.Xml.XmlNodeType.Element && reader.Name == "Color") <br />        { <br />            this.Color= reader.ReadElementContentAsString(); <br />        }        <br />    } </p> <p>    void System.Xml.Serialization.IXmlSerializable.WriteXml (System.Xml.XmlWriter writer) <br />    {        <br />        string ns = "<a href="http://car/car";">http://car/car";</a> <br />        writer.WriteStartAttribute("Price"); <br />        writer.WriteString(this.Price.ToString()); <br />        writer.WriteEndAttribute(); <br />        writer.WriteStartElement("ModelName", ns); <br />            writer.WriteString(this.ModelName); <br />        writer.WriteEndElement(); <br />        writer.WriteStartElement("CC", ns); <br />            writer.WriteString(this.CubicCentimeter.ToString()); <br />        writer.WriteEndElement(); <br />        writer.WriteStartElement("Color", ns); <br />            writer.WriteString(this.Color); <br />        writer.WriteEndElement();    <br />    } </p> <p>    #endregion <br />}</p> </td> </tr> </tbody></table> <p align="justify">The above code is pretty straight forward, in the WriteXml method we are making use of the XmlWriter class and serializing the Car class in our customized way. We are writing the Price property as an attribute to the root element by making use of the “WriteStartAttribute” method of the XmlWriter class.  Similarly we are making use of “WriteStartElement” method of the XmlWriter class to write the other properties as an element node. The XML generated by WriteXml is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p><?xml version="1.0"?> <br /><Car Price="23423" xmlns="<a href="http://car/car"">http://car/car"</a>> <br />  <ModelName>Beetle</ModelName> <br />  <CC>0</CC> <br />  <Color>Yellow</Color> <br /></Car></p> </td> </tr> </tbody></table> <p align="justify">Seeing the XML output you will be thinking that in “WriteXml” method we have not written code to write the “Car” root node, then how come there is a root node? The reason is that when the XmlWriter object, which is passed as an argument to the WriteXml method, already has the root node. By default the name of the root node will be the class name itself. If you notice we have placed the “XmlRoot” attribute on the “Car” class. So if you want to control the root name then you have to make use of the “XmlRoot” attribute. </p> <p align="justify">In the ReadXml method we are making use of XmlReader class to read the Xml serialized using the WriteXml method and reconstructing our Car class. When the Car class is deserialized the XML serializer executes the ReadXml method by passing the XmlReader class as an argument. When ReadXml is called the reader is positioned at the start of the document. The ReadXml function is  making use of various methods of the XmlReader class to read the content of the XML and reconstructing our serialized Car class. We are checking whether the reader is currently pointing to a attribute or element and then making use of appropriate methods to read the content. </p> <p align="justify">Since there is no validation happening during serializing and deserializing we have left the “GetSchema” method empty. If you really want to return a schema then what should you do? </p> <p align="justify"><strong><u>Returning a schema from IXmlSerializable implemented class.</u></strong></p> <p align="justify">In scenarios where you want to return a schema file one should apply “XmlSchemaProvider” attribute to the IXmlSerializable implemented class. “XmlSchemaProvider” contains the name of the method which returns the schema for the class. The method which is specified in the “XmlSchemaProvider” should be static. Also the method should return an object of type “XmlQualifiedName” and should take “XmlSchemaSet” object as an argument. The method should take the responsibility of filling the “XmlSchemaSet” object passed as an argument. If you are applying “XmlSchemaProvider” to a class then make sure the schema files don’t have any schema errors else error will thrown during the serialization process. </p> <p align="justify">Everything apart lets see how to implement “XmlSchemaProvider” attribute on a IXmlSerialization implemented class. Below is the Car class with the “XmlSchemaProvider” attribute applied. I have pasted only the relevant code.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p>[System.Xml.Serialization.XmlSchemaProvider("ReturnSchema")] <br />public class Car : System.Xml.Serialization.IXmlSerializable <br />{ <br />    /*Code has been trimmed for brevity*/ </p> <p>    public static System.Xml.XmlQualifiedName ReturnSchema (System.Xml.Schema.XmlSchemaSet xs) <br />    { <br />        System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(typeof (System.Xml.Schema.XmlSchema)); <br />        System.Xml.Schema.XmlSchema xmlSchema = (System.Xml.Schema.XmlSchema) xmlSer.Deserialize (new System.Xml.XmlTextReader("CustomSerilize_app1.xsd")); <br />        xs.XmlResolver = new System.Xml.XmlUrlResolver(); <br />        xs.Add(xmlSchema); <br />        return new System.Xml.XmlQualifiedName ("Car", “<a href="http://car/car">http://car/car</a>”); <br />     } <br />}</p> </td> </tr> </tbody></table> <p align="justify">I don’t think the above code needs much of an explanation. In the first few lines of code we are pumping the XmlSchema object with the schema information by reading the schema file from disk. Once that is done we are returning a XmlQualifiedName object. </p> <p align="justify">That’ about customizing XML serialization. Isn’t it so easy to write custom XML serialization. Whenever you find a situation where you want to serialize your class into XML and you don’t want to leave it to the system and want to take full control of the serialization, you can implement IXmlSerializable interface to your class. </p> <p align="justify">Try to know more</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com0tag:blogger.com,1999:blog-1454785102765291191.post-7987084445448490372010-01-02T17:56:00.000+05:302010-02-18T17:57:41.692+05:30Displaying trademark, copyright etc in HTML<p align="justify">This blog talks about a simple trick on how to show the trademark, copyright and registered symbols in HTML. To display trademark, copyright and registered symbols one needs to use “&trade;”, “&copy;” and “&reg;” respectively with any of the html tags. Below are some html and ASP.NET code samples.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p>//Trademark symbol displayed in the title window. <br /><title>My Company &trade;</title> <br />//Copyright symbol in a table header <br /><table width="100px"> <br />        <tr><th> Heading &copy;</th></tr> <br /></table> <br />//Registered symbol in a ASP.NET textbox <br /><asp:TextBox ID="TextBox1" runat="server" Text="&reg;"></asp:TextBox> <br />//Trademark, copyright and registered symbol in a ASP.NET label control <br /><asp:Label ID="Label2" runat="server" Text="&trade; &copy; &reg;"></asp:Label></p> </td> </tr> </tbody></table> <p>Try to know more.</p> <p>Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com10tag:blogger.com,1999:blog-1454785102765291191.post-58259499798773990072009-12-23T19:23:00.000+05:302009-12-23T19:29:11.870+05:30Data type validation using validation control<p align="justify">While developing ASP.NET application you would have come across scenarios where you would like to validate whether the value entered is of a particular data type. The options available with an ASP.NET developer is to write javascript functions to check whether the entered value complies with a data type or make the page postback and check the data type in server side. These two options are time consuming. Is there any simple way of doing this? The answer is to the question is “YES”. One can make use of compare validator to accomplish the task very easily. Lets see how.</p> <p align="justify">To compare whether the entered value is of a particular data type one should make sure that the “Operator” property of compare validator should be “DataTypeCheck” and the “Type” property should be the data type you want to check. These two things are the only requirement to validate the data type. Compare validator supports validation for Currency, Date, Double, Integer and String data type. Below is a sample code which tries to check all these data types.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p>Enter string: <asp:TextBox ID="txtString" runat="server"></asp:TextBox> <br /><font color="#008000"><asp:CompareValidator ID="cmpVldString" runat="server" ErrorMessage="Not a valid string." ControlToValidate="txtString" <br />Type="String" Operator="DataTypeCheck"> </asp:CompareValidator></font><br /> <br />Enter integer: <asp:TextBox ID="txtInt" runat="server"> </asp:TextBox> <br /><font color="#008000"><asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Not a valid Integer." ControlToValidate="txtInt" <br /> Type="Integer" Operator="DataTypeCheck"> </asp:CompareValidator></font><br /> <br />Enter double: <asp:TextBox ID="txtDouble" runat="server"> </asp:TextBox> <br /><font color="#008000"><asp:CompareValidator ID="CompareValidator2" runat="server" ErrorMessage="Not a valid double." ControlToValidate="txtDouble" <br /> Type="Double" Operator="DataTypeCheck"> </asp:CompareValidator></font><br /> <br />Enter date: <asp:TextBox ID="txtDate" runat="server"> </asp:TextBox> <br /><font color="#008000"><asp:CompareValidator ID="cmpVldDate" runat="server" ErrorMessage="Not a valid date." ControlToValidate="txtDate" <br /> Type="Date" Operator="DataTypeCheck" > </asp:CompareValidator></font><br /> <br />Enter currency: <asp:TextBox ID="txtCurrency" runat="server"> </asp:TextBox> <br /><font color="#008000"><asp:CompareValidator ID="cmpVldCurrency" runat="server" ErrorMessage="Not a valid currencys." ControlToValidate="txtCurrency" Type="Currency" Operator="DataTypeCheck" > </asp:CompareValidator></font><br /> <br /><asp:Button ID="Button1" runat="server" Text="Button" /></p> </td> </tr> </tbody></table> <p align="justify">In the above code sample you can see that I am checking the datatype for string, Integer, date, double and finally currency. Isn’t it so easy to check the data type? </p> <p align="justify">Now since we are validating date you would like to check against a particular format say “DD/MM/YYYY”. The default date format against which the compare validator checks the date is “YYYY/MM/DD”. One way specify the date format is to assign the page’ culture to the required culture which supports your date format. Say we want to check “DD/MM/YYYY” then we can set the following in the code behind.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p>protected void Page_Load(object sender, EventArgs e) <br />{ <br />    <font color="#008000">Page.Culture = "hi-IN";</font></p> </td> </tr> </tbody></table> <p align="justify">In the above code we are setting the culture for the page as Hindi-India which will accept the date in “DD/MM'/YYYY” format. Another way specifying the format in compare validator is to assign culture to the control which is specified in “ControlToValidate” property of the compare validator. For e.g. you have date picker assigned to a compare validator then assigning the culture or date format to the date picker will do the trick. As such there is no way to specify date format or culture to a compare validator. </p> <p align="justify"><strong>Note:</strong> When you use compare validator to check currency data type keep in mind it doesn’t check for currency symbol compliance. </p> <p align="justify">Try to know more…..</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com2tag:blogger.com,1999:blog-1454785102765291191.post-77017531872931242892009-12-21T17:29:00.000+05:302009-12-21T17:35:52.913+05:30Retrieving controls from an ASP.NET GridView control using javascript.<p align="justify">In our day to day ASP.NET programming we would have used GridView for one or the other purpose. There would have been requirement to access the controls inside a GridView from javascript. Whenever I had to use the ASP.NET GridView control, nearly 95% of the time I had to access the controls inside the GridView using javascript for one or the other purpose. With this blog I wanted to show how easily you can retrieve controls rendered inside a GridView from javascript. I would like to highlight this by taking an age old design where you will have a checkbox in the header and another set of checkboxes in the column below. Checking the checkbox in the header would select all the checkboxes in the column and un-checking a single checkbox in the column would un-check the header checkbox. This strategy can be used to access any type of controls not only inside the GridView but other data rendering controls as well. Now lets see the code for the same.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p><asp:GridView ID="gvChk" runat="server" AutoGenerateColumns="False" <br />            BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" <br />            CellPadding="4" ForeColor="Black" GridLines="Vertical" <br />            onrowdatabound="gvChk_RowDataBound"> <br />            <RowStyle BackColor="#F7F7DE" /> <br />            <Columns> <br />                <asp:TemplateField HeaderText="Sl. No"> <br />                    <EditItemTemplate> <br />                        <asp:TextBox ID="TextBox1" Text='<%#Eval("No") %>' runat="server"></asp:TextBox> <br />                    </EditItemTemplate> <br />                    <ItemTemplate> <br />                        <asp:Label ID="Label1" runat="server" Text='<%#Eval("No") %>'></asp:Label> <br />                    </ItemTemplate> <br />                </asp:TemplateField> <br />                <asp:TemplateField> <br />                    <EditItemTemplate> <br />                        <asp:CheckBox ID="CheckBox1" runat="server" /> <br />                    </EditItemTemplate> <br />                    <ItemTemplate> <br />                        <asp:CheckBox ID="CheckBox1" runat="server" /> <br />                    </ItemTemplate> <br />                    <HeaderTemplate> <br />                        <asp:CheckBox ID="chkHeader" onclick="javascript:selectAllCheckboxInGrid(<% gvChk.ClientID; %>, this);" <br />                            runat="server" /> <br />                    </HeaderTemplate> <br />                </asp:TemplateField> <br />            </Columns> <br />            <FooterStyle BackColor="#CCCC99" /> <br />            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <br />            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> <br />            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /> <br />            <AlternatingRowStyle BackColor="White" /> <br /></asp:GridView></p> </td> </tr> </tbody></table> <p align="justify">The code is very simple with a GridView control having two columns. First column has a label control and second one has a checkbox control. The second column has a checkbox in the header as well. When checkbox in the header is clicked all the checkboxes in the column are selected using javascript. The javascript code to select all the checkboxes in the column are pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p>function selectAllCheckboxInGrid(gridID, chk) <br />{ <br />    var grid = document.getElementById(gridID); <br />    //Loop starts from 1 because the zeroth row is the header. <br />    for (var i=1; i< grid.rows.length; i++) <br />    { <br />        //Getting the control in the second cell of the grid. <br />        //Second cell contains the checkbox. <br />        var cntls = grid.rows[i].cells[1].getElementsByTagName('input'); <br />        //If you are have only one control in the cell then <br />        //one can do away with the loop. <br />        for (var j=0; j < cntls.length; j++) <br />        { <br />            if (cntls[j].type == "checkbox") <br />                cntls[j].checked = chk.checked; <br />        } <br />    }    <br />}</p> </td> </tr> </tbody></table> <p align="justify">The above pasted javascript is straight forward. The javascript function takes two arguments, one is the GridView’ client id and the second is the checkbox in the GridView control’ header. The function starts by getting the grid control using the “getElementById” javascript method of the document object. After getting the GridView control, which is converted to a HTML table once rendered to the browser, we are looping through the rows collection starting from the first row. The zeroth row is the header so we don’t want the loop to start from the header. Starting from the 1st row we loop through the whole rows and get the controls in the second cell of the GridView using the “getElementsByTagName” method of the document object. Then we loop through the control array and check the type of the control and if it is a checkbox we set the checked property based on the checkbox control of the header cell passed as an argument to the javascript function. If you have only one control in the cell then you can directly use “cells[1].children[0].checked = chk.checked” so that you can avoid the loop. The above modified code is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p>function selectAllCheckboxInGrid(gridID, chk) <br />{ <br />    var grid = document.getElementById(gridID); <br />    //Loop starts from 1 because the zeroth row is the header. <br />    for (var i=1; i< grid.rows.length; i++) <br />    { <br />        //Getting the control in the second cell of the grid. <br />        //Second cell contains the checkbox. <br />        <font color="#0000ff">var cntls = grid.rows[i].cells[1].children[0].checked = chk.checked <br /></font>    }    <br />}</p> </td> </tr> </tbody></table> <p align="justify">Next we have to have a function which will check the header checkbox if all the checkbox in the column are checked and if out of all the checked checkboxes anyone is unchecked then we need to uncheck the header checkbox. The simple function is fired when any of the checkboxes in the column are clicked. The javascript function is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p>function checkUncheckHeaderCheckBox(gridID) <br />{ <br />    var grid = document.getElementById(gridID); <br />    var checked = true; <br />    //Loop starts from 1 because the zeroth row is the header. <br />    for (var i=1; i< grid.rows.length; i++) <br />    { <br />        //Getting the control in the second cell of the grid. <br />        //Second cell contains the checkbox. <br />        var cntls = grid.rows[i].cells[1].getElementsByTagName('input'); <br />        //If you are have only one control in the cell then <br />        //one can do away with the loop. <br />        for (var j=0; j < cntls.length; j++) <br />        { <br />            if (cntls[j].type == "checkbox" && !cntls[j].checked) <br />            { <br />                checked = cntls[j].checked; <br />                break; <br />            } <br />        } <br />        if (!checked) <br />            break; <br />    }    <br />    //Get the header checkbox and assign its checked property. <br />    grid.rows[0].cells[1].children[0].checked = checked;    <br />}</p> </td> </tr> </tbody></table> <p align="justify">The above function is pretty straight forward. The “GridView” control id is passed as argument. The function gets the “GridView” control using the “getElementById” function of the document object and loops through the rows starting from the first row leaving the zeroth row. Inside the loop the function retrieves the controls inside the second cell of each row and checks whether any one of the checkbox is unchecked. If so it assigns the “checked” variable as false and breaks the loop. Finally it sets the checked property of the checkbox in the header (zeroth row) to the value of “checked” variable. This function will take care of checking or unchecking the checkbox if all the checkbox in the column are checked or if any one checkbox in the checkbox column is unchecked respectively. </p> <p align="justify">To fire the javascript function on the click of the checkboxes we need to add the javascript function to the “onclick” javascript event. To do this add the following in the “RowDataBound” event of the GridView control. </p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="410" bgcolor="#ffffff"><tbody> <tr> <td> <p>protected void gvChk_RowDataBound(object sender, GridViewRowEventArgs e) <br />{ <br />    //Check if the row is of header type. <br />    if (e.Row.RowType == DataControlRowType.Header) <br />    { <br />        //Add the javascript function which gets called <br />        //when the checkbox in the header is clicked. <br />        (e.Row.FindControl("chkHeader") as CheckBox).Attributes.Add("onclick", "javascript:selectAllCheckboxInGrid('" + gvChk.ClientID + "', this);"); <br />    } <br />    else if (e.Row.RowType != DataControlRowType.Footer) <br />    { <br />        //Add the javascript function call which gets called <br />        //when the checkboxes in the column are clicked. <br />        (e.Row.FindControl("CheckBox1") as CheckBox).Attributes.Add("onclick", "javascript:checkUncheckHeaderCheckBox('" + gvChk.ClientID + "');"); <br />    } <br />}</p> </td> </tr> </tbody></table> <p align="justify">With the above code we are ready to go. </p> <p align="justify">The above technique using javascript can be used to retrieve any type of controls (textbox, dropdown, radio button, button, links, images, labels etc) from within the GridView control or any other ASP.NET data rendering controls. You need to make some small javascript changes according to your data bound controls layout. So tweak the code wherever necessary and start retrieving controls. </p> <p align="justify">Try to know more…</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com1tag:blogger.com,1999:blog-1454785102765291191.post-5349521934936187132009-12-15T19:38:00.000+05:302009-12-15T19:42:29.319+05:30Serialization in .NET - 4<p align="justify">In my previous blogs on serialization we had looked at the different ways of serializing an objects in .NET. The links to my previous blogs are</p> <p align="justify"><a href="http://sandblogaspnet.blogspot.com/2009/07/serialization-in-net-3.html" target="_blank">Soap Serialization</a></p> <p align="justify"><a href="http://sandblogaspnet.blogspot.com/2009/05/serialization-in-net-2.html" target="_blank">XML serialization</a></p> <p align="justify"><a href="http://sandblogaspnet.blogspot.com/2009/05/serialization-in-net-1.html" target="_blank">Binary serialization</a> </p> <p align="justify">In this blog we will have a look at how to implement custom serialization using ISerializable interface. In my previous blogs on serialization we looked at ways of controlling serialization by way of applying various attributes to the class and its member variables. Applying attributes gives us some control over serialization but doesn’t provide full fledge control. Most of your day to day serialization requirement can be met with the attributes discussed in my previous articles. But if you are the one who wants to take full control over serialization, then ISerializable interface is there for you. Lets first see what is needed to implement ISerializable interface.</p> <p align="justify">The ISerializable interface has got only one method, GetObjectData. In addition to implementing the GetObjectData the implementer should also take care to implement a special constructor to classes implementing ISerializable interface. The constructor is called by the system during the de-serialization process to reconstruct the serialized object. If by chance you forgot to implement the constructor, runtime error will be thrown when one tries to deserialize a class implementing ISerializable interface without the special constructor. The “System.Runtime.Serialization.SerializationException” exception message which is thrown at runtime is pasted below.</p> <table bordercolor="#000000" bordercolordark="#ffffff" width="400" bgcolor="#ffffff" bordercolorlight="#ffffff" border="1"><tbody> <tr> <td> <p align="justify"><font color="#ff0000">The constructor to deserialize an object of type 'ISerializableImplementation.[CLASSNAME]' was not found.</font></p> </td> </tr> </tbody></table> <p align="justify"><strong>Note: </strong>“GetObjectData” will be executed only in the case of binary serialization. For custom serialization in XML and SOAP serialization you need to implement IXmlSerializable interface.</p> <p align="justify">Now lets see and try to understand the GetObjectData and the special constructor.</p> <p align="justify"><strong>GetObjectData: </strong>The ISerializable method has only one method to be implemented and the signature looks like this “<font color="#004000">GetObjectData((SerializationInfo info, StreamingContext context)</font>”. The method takes SerializationInfo object as the first argument. SerializationInfo class can be used to store the required data to serialize and deserialize an object. Its the responsibility of the implementer to fill the SerializationInfo class with the necessary data. The implementer can decide on which member variables to store and which ones he doesn’t want to save. While doing this care should be taken to see that sufficient information is serialized for the objects to be deserialized. You can use the “AddValue” overloaded methods to add values to the SerializationInfo class. StreamingContext, the second argument in the method can be used to check the source from which the serialization request has come. Use the StreamingContext.State to check the source. Usage of StreamingContext is given at the end of the blog.</p> <p align="justify"><strong>Special constructor: </strong>The signature of the special constructor is as follows “(SerializationInfo info, StreamingContext context)”. The paremeters for the constructor are also the same. So I will not spend time explaining these. The special constructor is executed when an object (whose class has implemented ISerializable interface) is deserialized. If the special constructor is not implemented the system will not throw any compile time error but it will throw a runtime exception. So make sure a class which implements ISerializable interface has an explicit implementation of the special constructor which takes SerializationInfo and StreaminContext as its constructor argument. The special constructor should be private or protected if you intent to inherit the class.</p> <p align="justify"><strong>Things to note before you implement ISerializable interface</strong></p> <p align="justify">Keep the following things in mind before you implement the ISerializable Interface.</p> <ul> <li> <div align="justify">The class should have the Serializable attribute applied to it. If the class is not marked with the Serializable attribute an exception of type “System.Runtime.Serialization.SerializationException” will be thrown with the following error message.</div> </li> </ul> <table bordercolor="#000000" bordercolordark="#ffffff" width="400" bgcolor="#ffffff" bordercolorlight="#ffffff" border="1"><tbody> <tr> <td> <p align="justify"><font color="#ff0000">Type 'ISerializableImplementation.[CLASSNAME]' in Assembly 'ISerializableImplementation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.</font></p> </td> </tr> </tbody></table> <ul> <li> <div align="justify">NonSerializable attribute should not be used as it will not have any effect.</div> </li> <li> <div align="justify">Special constructor with the same argument as that of GetObjectData method must be implemented and should be private or protected.</div> </li> <li> <div align="justify">If the ISerializable implemented class is derived from a base class which also implements ISerializable interface then the parent class’ GetObjectData and special constructor should be called before the child class’ function and special constructor.</div> </li> </ul> <p align="justify">That’ enough about the ISerializable interface implementation, now you will be eager to see the real implementation. The implementation is also pretty easy and straight forward. As usual lets take the Car class and implement ISerializable interface to it. The code sample is pasted below.</p> <table bordercolor="#000000" bordercolordark="#ffffff" width="400" bgcolor="#ffffff" bordercolorlight="#ffffff" border="1"><tbody> <tr> <td> <p>using System; <br />using System.Collections.Generic; <br />using System.Linq; <br />using System.Text; <br />using System.Runtime.Serialization; </p> <p>namespace ISerializableImplementation <br />{ <br />    <font color="#008000">[Serializable] <br /></font>    public class Car : ISerializable <br />    { <br />        public Car() <br />        {} </p> <p>        <font color="#008000">public Car(SerializationInfo info, StreamingContext context) <br />        { <br />            this.Color = info.GetString("CarColor"); <br />            this.CubicCentimeter = info.GetDouble("CC"); <br />            this.ModelName = info.GetValue("Model", typeof(string)).ToString(); <br />        } </font></p> <p>        public string Color <br />        { get; set; } <br />        public string ModelName <br />        { get; set; } <br />        public int Price <br />        { get; set; } <br />        public double CubicCentimeter <br />        { get; set; } </p> <p>        #region ISerializable Members </p> <p>        <font color="#008000">void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) <br />        { <br />            info.AddValue("CarColor", this.Color); <br />            info.AddValue("Model", this.ModelName); <br />            info.AddValue("CC", this.CubicCentimeter);            <br />        } </font></p> <p>        #endregion <br />    } <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above code we have a special constructor and the GetObjectData method needed to implement custom serialization. GetObjectData method is called when a Car object is serialized and the special constructor is executed when the de-serialization of the Car object happens. Also if you notice, inside, GetObjectData method we are changing the property names, “Color” is changed to “CarColor”, “ModelName” is changed to “Model” and “CubicCentimeter” to CC. These are simple e.g. where we are taking control of serialization. Similar to this you can take control based on different scenarios. If you notice we have not included the “Price” in the serialization and deserialization process i.e. in GetObjectData and special constructor respectively. </p> <p align="justify">Isn’t it so simple to implement custom serialization. Now lets see how to use the StreamingContext object in serialization and deserialization. “StreamingContext” has only two properties which can be of interest, they are “Context” and “State”. Context property can hold any type of object as the underlining type is an “System.Object” class. Context property can be used when you expect some sort of object to come from the caller when serialization is happening. State property tells us from which source the serialization request has been raised. Lets understand with an e.g.</p> <table bordercolor="#000000" bordercolordark="#ffffff" width="400" bgcolor="#ffffff" bordercolorlight="#ffffff" border="1"><tbody> <tr> <td> <p>void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) <br />{ <br />      info.AddValue("CarColor", this.Color); <br />      info.AddValue("Model", this.ModelName); <br />      info.AddValue("CC", this.CubicCentimeter); <br />      //If the request comes from other sources then retrieve the price from the HashTable in the "Context"  <br />      // property of StreamingContext class. <br />      <font color="#ff8000">if (context.State == StreamingContextStates.Other) <br />      { <br />          info.AddValue("Price", ((System.Collections.Hashtable)context.Context)["Ferari Mondeno"].ToString()); <br />      } </font>           <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above code I have pasted the modified “GetObjectData” method as the other structure of the Car class is same. What we have done in the method is we have added a checking to check whether the serialization request is coming from other sources, if it is then get the price value from the “Context” property of the StreamingContext object. If you see the code I am casting the object to Hashtable and retrieving the price by passing “Ferari Mondeno” string as key. Lets see how the serialization code for the above implementation should be called.</p> <table bordercolor="#000000" bordercolordark="#ffffff" width="400" bgcolor="#ffffff" bordercolorlight="#ffffff" border="1"><tbody> <tr> <td> <p>//Create a Hashtable object and add the necessary data. <br /><font color="#ff8000">System.Collections.Hashtable ht = new System.Collections.Hashtable(); <br />ht.Add("Ferari Mondeno", 324324); <br />ht.Add("Lamborgini", 56677); <br /></font>//Create StreamingContext instance by passing the Hashtable <br />//as one of the arguments. Also we are setting the <br />//StreaminContextStates as Other. <br /><font color="#ff8000">StreamingContext sc = new StreamingContext(StreamingContextStates.Other, ht); <br /></font>//Pass the StreamingContext instance as one of the parameters <br />//of the binary formatter class. <br /><font color="#ff8000">BinaryFormatter bf = new BinaryFormatter(null, sc);</font> <br />using (System.IO.FileStream fs = new System.IO.FileStream("Serialized.txt", System.IO.FileMode.Create)) <br />{ <br />    Car car = new Car { ModelName = "Ferari Mondeno", Color = "Ferari Red", CubicCentimeter = 23584.33, Price = 234656 }; <br />    //bf.Serialize(Console.OpenStandardOutput(), car); <br />    bf.Serialize(fs, car); <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above code you can see that we are first creating a Hashtable with the necessary data. Once that is done we are creating a StreamingContext instance by passing the Hashtable instance and setting the “StreamingConstextstate as “Other”. After this we are passing the StreamingContext instance as one of the arguments to the “BinaryFormatter” class’ constructor. As you would have noticed we are passing Hashtable instance into the “Context” property of the StreamingContext object. Using the Hashtable we are retrieving the price in “GetObjectData” method. </p> <p align="justify">Now lets see how to deserialize object by making use of the StreamingContext instance. Based on the above changes we need to first change the constructor. Below is the constructor code.</p> <table bordercolor="#000000" bordercolordark="#ffffff" width="400" bgcolor="#ffffff" bordercolorlight="#ffffff" border="1"><tbody> <tr> <td> <p>public Car(SerializationInfo info, StreamingContext context) <br />{ <br />    this.Color = info.GetString("CarColor"); <br />    this.CubicCentimeter = info.GetDouble("CC"); <br />    this.ModelName = info.GetValue("Model", typeof(string)).ToString(); <br />    //Checking whether the serialization request is <br />    //coming from file or from other sources. <br />    if (context.State == StreamingContextStates.File || context.State == StreamingContextStates.Other) <br />    { <br />        this.Price = int.Parse(((System.Collections.Hashtable)context.Context)["Ferari Mondeno"].ToString()); <br />    } <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above code we have just added a if checking to check whether the request is coming from a file or from other sources, If so read the price value from the StreamingContext instance’ Context property. The “Context” property has a Hashatable having prices.</p> <p align="justify">Now lets see the deserialization code for the above.</p> <table bordercolor="#000000" bordercolordark="#ffffff" width="400" bgcolor="#ffffff" bordercolorlight="#ffffff" border="1"><tbody> <tr> <td> <p>using (System.IO.FileStream fs = new System.IO.FileStream("Serialized.txt", System.IO.FileMode.Open)) <br />{ <br />    //Create a Hashtable object and add the necessary data. <br />    <font color="#ff8000">System.Collections.Hashtable ht = new System.Collections.Hashtable(); <br />    ht.Add("Ferari Mondeno", 324324); <br />    ht.Add("Lamborgini", 56677); <br /></font>    //Create StreamingContext instance by passing the Hashtable <br />    //as one of the arguments. Also we are setting the <br />    //StreaminContextStates as Other. <br />    <font color="#ff8000">StreamingContext sc = new StreamingContext(StreamingContextStates.File, ht); <br /></font>    //Pass the StreamingContext instance as one of the parameters <br />    //of the binary formatter class. <br />    <font color="#ff8000">BinaryFormatter bf = new BinaryFormatter(null, sc); <br /></font>    Car deserializedCar = (Car)bf.Deserialize(fs); <br />    string nl = Environment.NewLine; <br />    Console.WriteLine(nl + "Model name: {0}, " + nl + "envi Color: {1}, " + nl + "Cubic centimeter: {2}, " + nl + "Price: {3}", <br />                        deserializedCar.ModelName, deserializedCar.Color, deserializedCar.CubicCentimeter, deserializedCar.Price); <br />}</p> </td> </tr> </tbody></table> <p align="justify">There is nothing much to explain about the above code. Its pretty much straight forward and is similar to  the code where we have serialized the Car class. That’ it about custom serialization using ISerializable interface. One very important point which I would like to reiterate again is that the “GetObjectData” and the special constructor will be executed only for binary serialization. For XML and SOAP serialization “GetObjectData” and the special constructor will not be executed. To implement custom serialization in XML and SOAP serialization you have to implement IXmlSerializable interface. We will have a look at IXmlSerializable interface implementation in my next blog. Till then try to know more.</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com4tag:blogger.com,1999:blog-1454785102765291191.post-57941508668772770812009-12-11T22:18:00.003+05:302009-12-14T11:04:24.933+05:30Showing image when validation fails using validation control<p align="justify">As they say .NET is a big ocean and each day you come across something new. Even after working for six years on .NET every other day I learn something new. One such experience I would like to share with this blog. In this blog we will see how to show an image when there is a validation error.</p> <p align="justify">Anyone who is a ASP.NET developer would have used validation control at some point or the other. So with this blog I would like to show a small technique whereby you can show an image next to a control whenever a validation fails using a validation control. The great thing about this approach is that, it is in-built into all the validation controls and to do this one need not write any server side code or client side code. Just placing an image tag in the “ErrorMessage” property of the validation control will do. Lets see the code.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>Required Numeric: <br /><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"            <font color="#ff8000">ErrorMessage='<img src=images/error.gif />'</font> Display="Dynamic"></asp:RequiredFieldValidator> <br /><asp:Button ID="btnSubmit" runat="server" Text="Submit" CausesValidation="true" CommandName="Edit" /> <br /><asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="" CausesValidation="False" <br />            OnClick="btnCancel_Click" /></p> </td> </tr> </tbody></table> <p align="justify">If you see the above code I have placed a html image tag in the “ErrorMessage” property of the required field validator control. So when you click the submit button without entering any value in “TextBox1” an error image will pop next to the textbox. The screenshot is shown below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicYRt8Xqe_68J9pa9w3F0a5nFUOLquisnKvHoJU1PFJwF3vrRKFP-DUClzK_y7E7MqYaFnRBe2N9qFDE-loBvm2AXV6AEday7TGxA1QAk9qGq1M6fKsTv6xZCgFeA1lClgJBEl80vK7VQc/s1600-h/image15.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_QY7fSC4VqiA/SyXOTqRprzI/AAAAAAAAECQ/ha_gH19Pv8M/image_thumb11.png?imgmax=800" width="384" height="74" /></a> </td> </tr> </tbody></table> <p align="justify">In the above image you can see an image, adjacent to the textbox, which was assigned to the “ErrorMessage” property of the validation control. In the above screenshot one thing which is missing is the description about the error. Wouldn’t it be nice to have a description about the error alongside the image? To achieve just that just place the error message before the html image tag as shown below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"           <font color="#ff8000">ErrorMessage="Required.<img src=images/imagesCAJD7BX6.jpg />" </font>Display="Dynamic"></asp:RequiredFieldValidator></p> </td> </tr> </tbody></table> <p align="justify">From the above you can notice that we have inserted “Required.” text before the image tag. The output of this is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyOg0Rv9P7RLdVD9TicZvc4u15dpqeubwGc2rMRbGi8hmPexZbQ-Cj5YGvWVnp6V9gDfQrk3EkqxNc_IOSYJb82V3HwpoELtYSYl48rexZfDTwppJSO76MrmjM_kt2sYTsvwPC-7l4pz4b/s1600-h/image19.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS2INfCCN5MLVyk7CVzLFjCTl71UoHvp66FGihHu2GVTrqtbUy0oa2Xi0mxqsPLTxo1MtobljCHeA0KLLC4qMJJy1Q3Nd6KHCrCFTYl2zPxQ_tUKa3wJU5HsjeRmsPkG_kNhWt5qcjnheK/?imgmax=800" width="384" height="75" /></a> </td> </tr> </tbody></table> <p align="justify">Now we have a message alongside the image which gives as the detail of what went wrong. Now all this is fine, but some others would like to make use of the validation summary and show the error messages in the validation summary and error images along side the controls. Hmm, is that tricky? Not at all, its very easy. Lets see how?</p> <p align="justify"><strong><u>Error image along with validation summary control</u></strong></p> <p align="justify">To show error image alongside the control and validation message in validation summary you have to make some small adjustments in the above code. First thing, obviously, is to insert a validation summary control. Next, Place the image tag in between the starting and ending tags of the validation control. I know you will be little confused, lets clear your confusion with some code. Here is what you need to do. </p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"            <font color="#ff8000">ErrorMessage="Required."</font> Display="Dynamic"><font color="#ff8000"><img src=images/imagesCAJD7BX6.jpg /></font></asp:RequiredFieldValidator></p> </td> </tr> </tbody></table> <p align="justify">In the above code I have purposefully not included the validation summary control. You can find the whole code at the end of the blog. If you notice, we have placed the image tag in between the starting and ending tag of the required field validator. Also we have the error message in the “ErrorMessage” property. The output of the above code is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9h1l4ltoNCbH5q5L0rcegV5tDg9uUjEzyWyZq6zznagU61Wf8U8hARphKlBGj2YRoMqJIApJGjgcM7mTzcxuMVzgWwykJYiCwFDrA8ySD6hUfpfH1h6vWpLDE4xxmwr4SUk9syNRIoLns/s1600-h/image23.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4zt8aWhUxsNRhOFW5fSALXmhm_hX2kY3WxivMGJLInwy-wYpQev9elEwykA9l5i_MGlqgYXyz4M8F3uRfl-g0wlJboICLO-IwCckymQArwa9bxBg-2u9sUcSsTfEIcM1log1V_qC8u2sY/?imgmax=800" width="384" height="105" /></a> </td> </tr> </tbody></table> <p align="justify"><font color="#ff0000"><strong>One thing to note here is that you have to set the “Display” property of the validation control to “Dynamic”.</strong></font>  If you set the “Display” property to “None”, which we usually use with validation summary control, then the image will not be displayed. So its very important to set the “Display” property to “Dynamic'” for this to work. The whole code along with the validation summary is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p><asp:ValidationSummary ID="ValidationSummary1" runat="server" /> <br />Required Numeric: <br /><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"            <font color="#ff8000">ErrorMessage="Required."</font> Display="Dynamic"><font color="#ff8000"><img src=images/imagesCAJD7BX6.jpg /></font></asp:RequiredFieldValidator> <br /><asp:Button ID="btnSubmit" runat="server" Text="Submit" CausesValidation="true" CommandName="Edit" /> <br /><asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="" CausesValidation="False"            OnClick="btnCancel_Click" /></p> </td> </tr> </tbody></table> <p>Try to learn more</p> <p>Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com17tag:blogger.com,1999:blog-1454785102765291191.post-10064379438714741752009-12-11T22:18:00.001+05:302009-12-13T20:10:22.430+05:30Weird, CausesValidation not working.<p align="justify">Recently I faced a weird situation where I had some validation controls, a cancel and submit buttons in a page . Submit button would validate the page controls for errors and cancel button would just postback and execute some code on the server without validating the page. The weird thing was once submit button is clicked and if there are any validation errors in the page and then one clicks the cancel button it won’t clear postback. If the user clicks the cancel button for the second time it would trigger postback. This happened even after setting the “CausesValidation” property of the cancel button to “false'”. The cancel button code is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p><asp:Button ID="btnRemove" CssClass="buttonEnabled" CommandName="Delete" runat="server"                       meta:resourcekey="btnRemove" CausesValidation="false" /></p> </td> </tr> </tbody></table> <p align="justify">One thing to note here is that the cancel button was inside a ListView control’ ItemTemplate section. So on click of the button  postback should happen and in the server some logic would be carried. The cancel would not work only when the user clicks the submit button and if there are any error and the user wishes to cancel the action then the cancel button would not post back. Only when the user clicks the cancel button for the second time, it would post back. If the user clicks the cancel button immediately after clicking the submit button and there are any validation errors displayed through the validation controls then the cancel button would not postback. This was weird. The solution was also simple. I need to set “Page_ValidationActive” javascript variable to false on the “OnClientClick” property of the cancel button. The modified cancel button HTML is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p><asp:Button ID="btnRemove" CssClass="buttonEnabled" CommandName="Delete" runat="server"                       meta:resourcekey="btnRemove" CausesValidation="false" <font color="#ff8000">OnClientClick="javascript:Page_ValidationActive = false;"</font> /></p> </td> </tr> </tbody></table> <p align="justify">Setting the “Page_ValidationActive” to false disables all the validations in the page. So please do keep this in mind. Anyway this is what I wanted and my problem was solved.</p> <p align="justify">Try to know more.</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com18tag:blogger.com,1999:blog-1454785102765291191.post-6199196070315213572009-11-30T21:12:00.001+05:302009-11-30T21:12:39.116+05:30Updating a resource file.<p align="justify">Recently one of our client had this requirement where they wanted to customize the texts appearing in the website as and when needed i.e. suppose they have a heading text in the login page which says “Login” and at some point they would like to change the text to something like “Login using email and password” without tinkering with the code. This is just an e.g., the client wanted each and every text appearing in the UI to be customizable. </p> <p align="justify">The above requirement can be easily achieved using resource files. The text which are displayed can be placed in the resource files and whenever there is a change in the text just editing the resource file will take care of displaying the new text. Now you might be thinking what is the big deal in this, yes there is no rocket science involved in editing a resource file, just open any text editor and make the necessary modification. Asking the client to do that will be too much in the asking. As resource files are stored as XML, any syntax problem can bring down the whole application. So the next obvious solution is to provide a web page to edit the existing resource files. </p> <p align="justify">By itself .NET doesn’t provide any class to edit and update resource files. There are classes to read and create resource files but nothing as such to update a resource files. If you want to simply read the content of a resource file you can make use of “System.Resources.ResourceReader” class and if you want to dynamically create a resource file then make use of “System.Resource.Resources.ResourceWriter” class. One of the disadvantages of using these classes is that they don’t have facility to fetch the comment part of a resource item.</p> <p align="justify">My problem was not reading or creation of resource file but updating the content. Also I had to update the comments as well. So some googling helped me and gave me hints. People suggested that, treat a resource file as an XML and use the XML classes to read/update the resource file. With this hint and little bit of LINQ to XML I found the solution. Lets dive into the solution.</p> <p align="justify"><strong><u>Reading resource file using LINQ</u></strong></p> <p align="justify">Following is the HTML content for displaying the resource file content.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p><asp:GridView ID="gvResourceEditor" runat="server" AutoGenerateColumns="False" OnRowCancelingEdit="gvResourceEditor_RowCancelingEdit" <br />            OnRowEditing="gvResourceEditor_RowEditing" OnRowUpdating="gvResourceEditor_RowUpdating"            CellPadding="0" BorderWidth="0px" Width="100%" meta:resourcekey="gvResourceEditorResource1"> <br />            <Columns> <br />                <asp:TemplateField HeaderText="Key" meta:resourcekey="TemplateFieldResource1"> <br />                    <EditItemTemplate> <br />                        <asp:Label ID="lblKey" runat="server" Text='<%# Eval("Key") %>' meta:resourcekey="lblKeyResource1"></asp:Label> <br />                    </EditItemTemplate> <br />                    <ItemTemplate> <br />                        <asp:Label ID="lblKey" runat="server" Text='<%# Eval("Key") %>' meta:resourcekey="lblKeyResource2"></asp:Label> <br />                    </ItemTemplate> <br />                    <ItemStyle CssClass="gridText tenXPadding bottomBorder rightBorder" Wrap="True" VerticalAlign="Top" <br />                        Width="10%" /> <br />                </asp:TemplateField> <br />                <asp:TemplateField HeaderText="TEXT" meta:resourcekey="TemplateFieldResource2"> <br />                    <HeaderStyle BorderWidth="0" BorderColor="White" BorderStyle="None" /> <br />                    <EditItemTemplate> <br />                        <asp:TextBox ID="txtValue" TextMode="MultiLine" CssClass="textBoxEnabled" runat="server" <br />                            Text='<%# Bind("Value") %>' Width="100%" Height="150px" meta:resourcekey="txtValueResource1"></asp:TextBox> <br />                    </EditItemTemplate> <br />                    <ItemTemplate> <br />                        <asp:Label ID="lblValue" runat="server" Text='<%# Bind("Value") %>' meta:resourcekey="lblValueResource1"></asp:Label> <br />                    </ItemTemplate> <br />                    <ItemStyle CssClass="gridText tenXPadding rightBorder bottomBorder" Wrap="True" Width="35%" <br />                        VerticalAlign="Top" /> <br />                </asp:TemplateField> <br />                <asp:TemplateField HeaderText="COMMENTS" meta:resourcekey="TemplateFieldResource3"> <br />                    <HeaderStyle BorderWidth="0" BorderColor="White" BorderStyle="None" /> <br />                    <EditItemTemplate> <br />                        <asp:TextBox ID="txtComment" TextMode="MultiLine" CssClass="textBoxEnabled" runat="server" <br />                            Text='<%# Bind("Comment") %>' Width="100%" Height="150px" meta:resourcekey="txtDescriptionResource1"></asp:TextBox> <br />                    </EditItemTemplate> <br />                    <ItemTemplate> <br />                        <asp:Label ID="lblDescription" runat="server" Text='<%# Bind("Comment") %>' meta:resourcekey="lblDescriptionResource1"></asp:Label> <br />                    </ItemTemplate> <br />                    <ItemStyle CssClass="gridText tenXPadding rightBorder bottomBorder" Wrap="True" Width="35%" <br />                        VerticalAlign="Top" /> <br />                </asp:TemplateField> <br />                <asp:CommandField ButtonType="Button" ItemStyle-CssClass="tenXPadding bottomBorder" <br />                    ShowEditButton="True" ControlStyle-CssClass="buttonEnabled" ItemStyle-VerticalAlign="Top" <br />                    HeaderStyle-BorderColor="White" HeaderStyle-BorderWidth="0" HeaderStyle-BorderStyle="None" <br />                    ItemStyle-Width="20%" meta:resourcekey="CommandFieldResource1"> <br />                    <ControlStyle CssClass="buttonEnabled"></ControlStyle> <br />                    <HeaderStyle BorderColor="White" BorderWidth="0px" BorderStyle="None"></HeaderStyle> <br />                    <ItemStyle VerticalAlign="Top" CssClass="tenXPadding bottomBorder" Width="20%"></ItemStyle> <br />                </asp:CommandField> <br />            </Columns> <br />        </asp:GridView></p> </td> </tr> </tbody></table> <p align="justify">In the above code you can see there is a GridView control which has its columns bound to various properties like “Key”, “Value” and “Comment”. This is a simple grid with “Edit”, “Update” and “Cancel” facility. In the above HTML make sure you have the “Key” field. “Key” field is used to search the resource file for the record to be updated. Make sure the “Key” field is not editable.</p> <p align="justify"> In the Page_Load event in the code behind the following code is used to read the content of a resource file and data bind the same to a GridView control.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>protected void Page_Load(object sender, EventArgs e) <br />{ <br />   if (!IsPostBack) <br />     LoadData(); <br />} </p> <p>private void LoadData() <br />{ <br />   string path = Server.MapPath("App_LocalResources/Default.aspx.resx"); <br />   //Loading the XML file using the Load method of XElement. <br />   XElement resourceElements = XElement.Load(path); <br />   //LINQ to load the resource items <br />   gvResourceEditor.DataSource = (from resElem in resourceElements.Elements("data") <br />       select new <br />       { <br />           Key = resElem.Attribute("name").Value, <br />           Value = HttpUtility.HtmlEncode(resElem.Element("value").Value), <br />           Comment = resElem.Element("comment") != null ? <br />                HttpUtility.HtmlEncode(resElem.Element("comment").Value) : string.Empty <br />       }); <br />    gvResourceEditor.DataBind(); <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above code you can see we are making use of XML to LINQ to read the contents from a resource file (Default.aspx.resx). Once we have loaded the resource file using the Load method of XElement class, in the next line we are making use of LINQ and creating <a href="http://sandblogaspnet.blogspot.com/2009/06/anonymous-types-features-of-c-30-part-5.html" target="_blank">anonymous types</a> and assigning the same as DataSource to the GridView control. </p> <p align="justify">With that simple code we have read the contents from a resource file and displayed the same in a GridView with facility to “Edit”, “Update” and “Cancel”. Now lets see how to update a particular value in a resource file.</p> <p align="justify"><strong><u>Updating a resource file</u></strong></p> <p align="justify">In the “RowUpdating” event of the GridView control we are doing the following to update the resource file.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>protected void gvResourceEditor_RowUpdating(object sender, GridViewUpdateEventArgs e) <br />{ <br />    string theFileName = Server.MapPath("App_LocalResources/Default.aspx.resx"); <br />    Label lblKey = gvResourceEditor.Rows[e.RowIndex].FindControl("lblKey") as Label; <br />    TextBox txtValue = gvResourceEditor.Rows[e.RowIndex].FindControl("txtValue") as TextBox; <br />    TextBox txtComment = gvResourceEditor.Rows[e.RowIndex].FindControl("txtComment") as TextBox; <br />    //Loading the Resource file as an XML. <br />    XDocument xDoc = XDocument.Load(theFileName); <br />    //Filtering out key which matches currently updated record. <br />    var elementToBeEdited = from xle in xDoc.Element("root").Elements("data") where xle.Attribute("name").Value == lblKey.Text select xle; </p> <p>    if (elementToBeEdited != null && elementToBeEdited.Count() > 0) <br />    { <br />        //Updating the new value <br />        elementToBeEdited.First().SetElementValue("value", HttpUtility.HtmlDecode(txtValue.Text)); </p> <p>        //Checking if there is a comment node, if no then adding a new comment node. <br />        if (elementToBeEdited.First().Element("comment") == null && !string.IsNullOrEmpty(txtComment.Text)) <br />        { <br />            elementToBeEdited.First().Add(new XElement("comment", HttpUtility.HtmlDecode(txtComment.Text))); <br />        } <br />        else if (elementToBeEdited.First().Element("comment") != null && !string.IsNullOrEmpty(txtComment.Text)) <br />        { <br />            //If comment node is present then updating the comment node. <br />            elementToBeEdited.First().SetElementValue("comment", HttpUtility.HtmlDecode(txtComment.Text)); <br />        } <br />        //Finally saving the Resource file. <br />        xDoc.Save(theFileName);                <br />    } </p> <p>    gvResourceEditor.EditIndex = -1; <br />    LoadData(); <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above code, first we are finding controls holding the values and then we are loading the resource file into the XDoc object. Once the resource file is loaded, in the next line we are making use of LINQ statement to select the element whose name attribute matches the “Key” field of the GridView. Once the element to be edited is filtered next we are updating the “value” node with the newly updated value. The value node in the resource file holds the text. </p> <p align="justify">Then in the next line we are checking whether there is a comment node available, if not we are creating a new comment node by calling the “Add” method and passing a new “XElement” object as the parameter. If there is a comment node then we are updating the comment by calling the “SetElementValue” method and passing the necessary text as argument. Finally the updated resource file is saved by calling the “Save” method of the XDoc class.</p> <p align="justify">Isn’t it so simple to update the resource file. With XML to LINQ the code has become terse and very easy. So with this you have seen how to read and update a resource file using LINQ. </p> <p align="justify"><strong>Note: </strong>If you are updating a resource file in a live system then keep in mind that all the logged in users session will expire and they will be logged out. </p> <p align="justify">Try to konw more…</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com21tag:blogger.com,1999:blog-1454785102765291191.post-81428980114877244952009-09-27T14:14:00.002+05:302012-01-13T11:57:35.789+05:30Calling multiple validation group<p align="justify">Recently I had this requirement where in a single button click I need to call multiple Validation groups. The scenario is something like this. I had a ASP.NET page where there were 5 user controls and each had their own validation controls embedded in them. Each user control had its own validation controls and they had their own Validation group defined. All these user controls were placed in a single page which only had two button “Submit” and “Canel”. On click of the “Submit” button all the validation controls in the form should execute. The problem here is that there are five different validation groups in the same page. To top it all you can only assign one validation group to a button’ ValidationGroup property. If you don’t assign any validation group then on click of the submit button the validation controls which don’t have any validation group defined for them will only be fired. Validation controls which have validation group property defined will not get fired. This is the default behavior of validation controls. So how to call the validation controls of different groups? The answer lies in calling the “Page_ClientValidate” javascript method with the validation group name. </p> <p align="justify">Lets try to understand how this all words with some code.The HTML code of the page looks something like this.</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff"><</span><span style="color: #800000">table</span> <span style="color: #ff0000">width</span><span style="color: #0000ff">="100%"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TextBox</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TextBox1"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:TextBox</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:RequiredFieldValidator</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="RequiredFieldValidator1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> <span style="color: #ff0000">ErrorMessage</span><span style="color: #0000ff">="RequiredFieldValidator"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> <span style="color: #ff0000">ValidationGroup</span><span style="color: #0000ff">="Group1"</span> <span style="color: #ff0000">ControlToValidate</span><span style="color: #0000ff">="TextBox1"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> <span style="color: #0000ff"></</span><span style="color: #800000">asp:RequiredFieldValidator</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14"> 14:</span> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15"> 15:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TextBox</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TextBox2"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16"> 16:</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:TextBox</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17"> 17:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:RequiredFieldValidator</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18"> 18:</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="RequiredFieldValidator2"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19"> 19:</span> <span style="color: #ff0000">ErrorMessage</span><span style="color: #0000ff">="RequiredFieldValidator"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20"> 20:</span> <span style="color: #ff0000">ValidationGroup</span><span style="color: #0000ff">="Group2"</span> <span style="color: #ff0000">ControlToValidate</span><span style="color: #0000ff">="TextBox2"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21"> 21:</span> <span style="color: #0000ff"></</span><span style="color: #800000">asp:RequiredFieldValidator</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22"> 22:</span> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23"> 23:</span> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum24"> 24:</span> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum25"> 25:</span> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum26"> 26:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TextBox</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TextBox3"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:TextBox</span><span style="color: #0000ff">></span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:RequiredFieldValidator</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="RequiredFieldValidator3"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ErrorMessage</span><span style="color: #0000ff">="RequiredFieldValidator"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum27"> 27:</span> <span style="color: #ff0000">ValidationGroup</span><span style="color: #0000ff">="Group3"</span> <span style="color: #ff0000">ControlToValidate</span><span style="color: #0000ff">="TextBox3"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum28"> 28:</span> <span style="color: #0000ff"></</span><span style="color: #800000">asp:RequiredFieldValidator</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum29"> 29:</span> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum30"> 30:</span> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum31"> 31:</span> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum32"> 32:</span> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum33"> 33:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TextBox</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TextBox4"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum34"> 34:</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:TextBox</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum35"> 35:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:RequiredFieldValidator</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum36"> 36:</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="RequiredFieldValidator4"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ErrorMessage</span><span style="color: #0000ff">="RequiredFieldValidator"</span> <span style="color: #ff0000">ControlToValidate</span><span style="color: #0000ff">="TextBox4"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum37"> 37:</span> <span style="color: #0000ff"></</span><span style="color: #800000">asp:RequiredFieldValidator</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum38"> 38:</span> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum39"> 39:</span> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum40"> 40:</span> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum41"> 41:</span> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum42"> 42:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Button</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="btnSubmit"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Submit"</span> <span style="color: #ff0000">OnClientClick</span><span style="color: #0000ff">="javascript:return </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum43"> 43:</span> validatePage();" <span style="color: #0000ff">/></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum44"> 44:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Button</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="btnCancel"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Cancel"</span> <span style="color: #0000ff">/></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum45"> 45:</span> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum46"> 46:</span> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum47"> 47:</span> <span style="color: #0000ff"></</span><span style="color: #800000">table</span><span style="color: #0000ff">></span></pre><!--CRLF--></div></div><p align="justify">From the above markup you can make out that there are four required field validators and out of the four validators three have validation group property defined. In such a scenario when you click the submit button only the validator which doesn’t have validation group will be executed i.e. RequiredFiedlValidator4 will only be executed. Since there are more than one validation group assigning button’ ValidationGroup wont work as it will execute only validator controls which belong to the assigned validaiton group. Other validator controls belonging to other validation group won’t execute. Also there is no way to specify multiple validaiton group using the ValidationGroup property of the button control. </p><p align="justify">The way to solve this problem is to call Page_ClientValidate javascript function. Page_ClientValidate is a javascript function generated by ASP.NET. The function takes validation group name as an argument. The javascript function which gets called when the submit button is clicked is pasted below.</p><div style="border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 4px; background-color: rgb(244, 244, 244); margin-top: 20px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 200px; overflow-x: auto; overflow-y: auto; border-top-color: silver; border-top-width: 1px; border-top-style: solid; cursor: text; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 4px; " id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow-x: visible; overflow-y: visible; padding-top: 0px; " id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <script language=<span style="color: #006080">"javascript"</span> type=<span style="color: #006080">"text/javascript"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff">function</span> validatePage() </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #008000">//Executes all the validation controls associated with group1 validaiton Group1. </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff">var</span> flag = Page_ClientValidate(<span style="color: #006080">'Group1'</span>); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> <span style="color: #0000ff">if</span> (flag) </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> <span style="color: #008000">//Executes all the validation controls associated with group1 validaiton Group2. </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> flag = Page_ClientValidate(<span style="color: #006080">'Group2'</span>); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> <span style="color: #0000ff">if</span> (flag) </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> <span style="color: #008000">//Executes all the validation controls associated with group1 validaiton Group3. </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span> flag = Page_ClientValidate(<span style="color: #006080">'Group3'</span>); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span> <span style="color: #0000ff">if</span> (flag) </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span> <span style="color: #008000">//Executes all the validation controls which are not associated with any validation group. </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14"> 14:</span> flag = Page_ClientValidate(); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15"> 15:</span> <span style="color: #0000ff">return</span> flag; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16"> 16:</span> } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17"> 17:</span> </script></pre><!--CRLF--></div></div><p align="justify">In the above code you can see the Page_ClientValidate function is called four times, first by passing the first validation group name, second time passing on the second validation group name and so on. If you see the last call to Page_ClientValidate, it is called with an empty argument. When call Page_ClientValidate with no argume/validation group name it executes all the validation controls in the page which don’t have a validation group assigned to them. So if one wants to execute validation controls which are not having any validation group associated with them you can call the Page_ClientValidate without any parameter.</p><p align="justify">So using Page_ClientValidate javascript function one can execute all the validation controls in the page by passing the validation group name or without any validation group name.</p><p align="justify"><br /></p><p align="justify">Try to know more.</p><br /><p align="justify">Sandeep</p>Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com19tag:blogger.com,1999:blog-1454785102765291191.post-73659777295999172202009-09-19T22:37:00.001+05:302009-09-20T16:48:38.905+05:30Some important .NET functions. Part – 1<p align="justify">.NET is a big ocean. Each day when I work I find one or the other function which are very useful in day to day programming. So I thought I will start a series of blog on some .NET function which I feel  are very useful. Here is the first list of function.</p> <p align="justify">Recently while working in a ASP.NET project I wanted to make use of colors given by the designers in C# code behind file and wanted to change the color of ASP.NET controls. You will be thinking what is so hard in this. There is nothing much other than the color was given in hexadecimal value, like #657468, #AA3212 etc, and .NET controls only understand System.Drawing.Color structure values. So there is my problem. I need to convert the hexadecimal values to System.Drawing.Color values. Luckily I didn’t had to break my head for solving this problem, .NET provides a class just to solve my problem. The class is called ColorTranslator. The method which helped me is FromHtml. Code is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>DropDownList1.BackColor = System.Drawing.ColorTranslator.FromHtml("#345678"); <br />DropDownList1.BorderColor = System.Drawing.ColorTranslator.FromHtml("Yellow");</p> </td> </tr> </tbody></table> <p align="justify">The FromHtml method can take the name of the color as well as the hexadecimal value/HTML value. Some other methods of the class are listed below.</p> <p align="justify"><strong>ColorTranslator.ToHtml(Color theColor): </strong>This is just the opposite of FromHtml i.e. it converts the color to HTML values. So when one wants to convert color to HTML color values/Hexadecimal color value one can make use of the ToHtml method. Sample code is pasted below. </p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>DropDownList1.BackColor = <br />System.Drawing.ColorTranslator.FromHtml("#ff5678"); <br />DropDownList1.BorderColor = <br />System.Drawing.ColorTranslator.FromHtml("Yellow"); <br />Console.WriteLIne(System.Drawing.ColorTranslator.ToHtml <br />(DropDownList1.BackColor));//Output - #ff5678 <br />Console.WriteLine(System.Drawing.ColorTranslator.ToHtml <br />(DropDownList1.BorderColor));//Output - Yellow</p> </td> </tr> </tbody></table> <p align="justify"><strong>ColorTranslator.ToWin32(Color c) and ColorTranslator.FromWin32(int w32): </strong>ToWin32 converts the Color object to the equivalent windows color value whereas FromWin32 does just the opposite i.e. converts a Win32 color value to a System.Drawing.Color object. Sample codes are pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>Console.WriteLine(System.Drawing.ColorTranslator.ToWin32 <br />(System.Drawing.Color.Red));//Output – 255. <br />System.Drawing.Color color = <br />System.Drawing.ColorTranslator.FromWin32(255);</p> </td> </tr> </tbody></table> <p align="justify">ColorTranslator.ToOLE(Color col) and ColorTranslator.FromOLE(int oleValue): ToOLE method converts Color object to OLE equivalent color value and FromOLE converts OLE color value to System.Drawing.Color object.</p> <p align="justify"><strong>My ever useful System.IO.Path class</strong></p> <p align="justify">Over my career the class which is mostly used by me is the System.IO.Path class. Though the class has got only 15 or so static methods I use this class a lot while working with file paths. Let me first start with my favorite Combine method of the Path class which I use the most.</p> <p align="justify"><strong>Path.Combine(string path1, string path2): </strong>The combine method combines two paths and returns you the combined path. The method takes care to add the necessary directory separator before combining the two paths. Also the combine method can be used to combine paths with wild characters like *.pdf or sa*.txt etc. If wild characters are used the combine method takes them as search criteria and doesn’t throw any error. E.g pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>System.IO.Path.Combine(Server.MapPath("."), "images") <br />//Output: "C:\\aaa\\bb\\WebSite1\\images" <br />System.IO.Path.Combine(System.IO.Path.Combine(Server.MapPath <br />("."), "images"), "*.gif") <br />//Output: "C:\\aaa\\bb\\WebSite1\\images\\*.gif"</p> </td> </tr> </tbody></table> <p align="justify"><strong>Path.GetExtension(string thePath): </strong>The GetExtension method returns the extension along with “.” from the path argument passed. So if you want to retrieve only extension from a file path just pass the file path to the GetExtension method and there you go you will have your extension. GetExtension method returns an empty string if the path doesn’t have any extension, also it returns null if the path argument is null. E.g. pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>string filePath = System.IO.Path.Combine(System.IO.Path.Combine(Server.MapPath <br />("."),  "images"), "*.gif"); <br />Console.WriteLine(System.IO.Path.GetExtension(filePath)); <br />//Output: .gif</p> </td> </tr> </tbody></table> <p align="justify"><strong>Path.GetFileName(string thePath): </strong>This method returns the filename with extension from the specified path argument. Returns an empty string if there are no file name. Sample code is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td>string filePath = System.IO.Path.Combine(System.IO.Path.Combine(Server.MapPath <br />("."), "images"), "tick.gif"); <br />Console.WriteLine(System.IO.Path.GetFileName <br />(filePath));//Output: tick.gif</td> </tr> </tbody></table> <p align="justify"><strong>Path.ChangeExtension(string filePath, string newExt): </strong>This method changes the extension of the file. The method takes two arguments, filename with extension along with/without path  and second one is the new extension with “.” which needs to be applied. If period is not there in the new extension argument then the method adds one. If you just wants to remove the extension then just pass a null value as the new extension parameter. Sample code is given below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td>string filePath = System.IO.Path.Combine(System.IO.Path.Combine(Server.MapPath <br />("."), "images"), "tick.gif"); <br />Console.WriteLine(System.IO.Path.ChangeExtension <br />(filePath, "jpg"));//Output: C:\\aaa\\bb\\WebSite1 <br />\\images\\tick.jpg</td> </tr> </tbody></table> <p align="justify"><strong>Path.GetFileNameWithoutExtension(string filePath): </strong>Function returns the file name without extension. E.g. is shown below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td>string filePath = System.IO.Path.Combine(System.IO.Path.Combine(Server.MapPath <br />("."), "images"), "tick.gif"); <br />Console.WriteLine(System.IO.Path.ChangeExtension <br />(filePath, "jpg"));//Output: tick</td> </tr> </tbody></table> <p align="justify"><strong>Path.GetRandomFileName(): </strong>Returns a random string. The string is generated using cryptographic principles. The string can be used as folder or file name. Sample code is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>Console.WriteLine(System.IO.Path.GetRandomFileName())//Output: x4zxg224.hva</p> </td> </tr> </tbody></table> <p align="justify"><strong>Path.GetTempFileName(): </strong>Function returns a string with a file name along with temporary folder path. The filename returned has a .tmp extension. The method creates a file with .tmp in the temporary folder and then returns the filename along with the temprorary folder path where the file is created. Sample code with output is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>Console.WriteLine(System.IO.Path.GetTempFileName())//Output: C:\\Documents and Settings\\sandeep\\Local Settings\\Temp\\tmp20C.tmp</p> </td> </tr> </tbody></table> <p align="justify"><strong>Path.GetTempPath(): </strong>GetTempPath function returns the system’ temporary folder path. Sample code is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td>Console.WriteLine(System.IO.Path.GetTempPath());//Output: C:\\Documents and Settings\\sandeep\\Local Settings\\Temp\\</td> </tr> </tbody></table> <p align="justify"><strong>Path.HasExtension(string filePath): </strong>This function checks whether the file path passed has a file extension. If extension is found the function returns true else false.</p> <p align="justify">So these are some of my favorite and useful functions. Will publish some more over the course of time till then try to know more.</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com0tag:blogger.com,1999:blog-1454785102765291191.post-76725413498188653252009-08-31T14:37:00.001+05:302009-08-31T14:38:53.363+05:30Saving files from one website to another website.<p align="justify">This blog is based on my recent requirement where I had to save some image files from one website to another website. Lets see the requirement and the solution for the requirement.</p> <p align="justify"><strong><u>Requirement</u></strong></p> <p align="justify">The requirement is as follows. The user will select a file which needs to be uploaded using a website (UploadFilesWebsite) and these selected files will be saved in another website (SaveFilesWebsite). Cross website posting of data. We all know it’ very easy to save files within the same site by making use of a file upload control and calling its SaveAs method. E.g. is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td>fileUploadCntl.SaveAs(System.IO.Path.Combine(Server.MapPath("."), fileUploadCntl.FileName))</td> </tr> </tbody></table> <p align="justify">But in my case it was different, the file needs to be saved in a different website from the one from where file upload is done.</p> <p align="justify"><strong><u>Solution</u></strong></p> <p align="justify">The problem was solved by making use of HttpWebRequest and HttpWebResponse object. Below is steps which are needed to solve this problem.</p> <ul> <li> <div align="justify">First create an ASPX file which will be capable of receiving any type of file stream and saving this stream to the required folder. This file should be created/placed in the website where you want to save the files, in my case it is “SaveFiles” website.</div> </li> <li> <div align="justify">Create a HttpWebRequest object and pump the file content to the RequestStream of the HttpWebRequest object.</div> </li> <li> <div align="justify">Get the response using the GetResponse method of the HttpWebRequest object. GetResponse will return a HttpWebResponse object.</div> </li> <li> <div align="justify">Get the response stream from the HttpWebResponse object by executing the GetResponseStream method.</div> </li> </ul> <p align="justify">These are the steps which you need to follow to post file contents from one website to another. Lets see each one of these one by one.</p> <p align="justify"><strong><u>Create an aspx file capable of saving request stream.</u></strong></p> <p align="justify">The first step is to create an aspx file which will be capable of saving a request stream. This file should be created and saved in the web site where you plan to save your file. This file will receive requests from other website for saving files in the website. So we will create this file in “SaveFiles” website and we will name it as SaveFile.asxp. After creating and saving the file go to the HTML source view of the file. It will look something like this.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p><%@ Page Language="C#" AutoEventWireup="true"  CodeFile="SaveFile.aspx.cs" Inherits="SaveFile" %> </p> <p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</a>> </p> <p><html xmlns="<a href="http://www.w3.org/1999/xhtml"">http://www.w3.org/1999/xhtml"</a>> <br /><head runat="server"> <br />    <title>Untitled Page</title> <br /></head> <br /><body> <br />    <form id="form1" runat="server"> <br />    <div> <br />    </div> <br />    </form> <br /></body> <br /></html></p> </td> </tr> </tbody></table> <p align="justify">Remove the HTML source from the file leaving only the Page attribute. The page should look something like this.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><%@ Page Language="C#" AutoEventWireup="true"  CodeFile="SaveFile.aspx.cs" Inherits="SaveFile" %></td> </tr> </tbody></table> <p align="justify">Now lets go to the codebehind and do some coding to save the request stream. The codebehind (SaveFile.aspx.cs) file of SaveFile looks something like this.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>using System; <br />using System.Configuration; <br />using System.Data; <br />using System.Linq; <br />using System.Web; <br />using System.Web.Security; <br />using System.Web.UI; <br />using System.Web.UI.HtmlControls; <br />using System.Web.UI.WebControls; <br />using System.Web.UI.WebControls.WebParts; <br />using System.Xml.Linq; </p> <p>public partial class SaveFile : System.Web.UI.Page <br />{ <br />    protected void Page_Load(object sender, EventArgs e) <br />    { <br />        <font color="#008000">try <br />        { <br />            /*Retrieving the file name from the headers in the request. */ <br />            string fileName = System.IO.Path.Combine(Server.MapPath("."), Request.Headers["FileName"].ToString()); <br />            using (System.IO.FileStream fileStream = System.IO.File.Create(fileName)) <br />            { <br />                /*Getting stream from the Request object.*/ <br />                using (System.IO.Stream stream = Request.InputStream) <br />                { <br />                    int byteStreamLength = (int)stream.Length; <br />                    byte[] byteStream = new byte[byteStreamLength]; <br />                    /*Reading the stream to a byte array.*/ <br />                    stream.Read(byteStream, 0, byteStreamLength); <br />                    /*Writing the byte array to the harddisk.*/ <br />                    fileStream.Write(byteStream, 0, byteStreamLength); <br />                } <br />            } <br />            Response.Clear(); <br />            /*Writing the status to the response.*/ <br />            Response.Write("File successfully saved"); <br />        } <br />        catch (Exception ex) <br />        { <br />            /*Writing the error message to the response stream.*/ <br />            Response.Clear(); <br />            Response.Write("Error: " + ex.Message); <br />        } <br /></font>    } <br />}</p> </td> </tr> </tbody></table> <p align="justify">From the above code one can see we are first retrieving the filename from Request object’ Headers property. We will shortly see how to send info in headers of a request. After getting the filename we are opening a file stream to flush the content to the hard disk. Once the file stream is successfully created, next, we are creating a stream by getting the InputStream of the Request object. The InputStream property of the Request object will hold the content which needs to be saved. In the next line we are reading the stream content to a byte array and finally passing the byte array to the FileStream object and writing/saving to a file. Once the file is successfully saved we are writing the status to the Response after clearing the Response. Also if there is any exception thrown while the file is saved the same is written to the Response.</p> <p align="justify">So that’ about the page which will save the content in the desired filename. So now we will move to our next steps like creating the HttpWebRequest object and passing the file content to the SaveFile.aspx file to save it in the website.</p> <p align="justify"><strong><u>Create an aspx page to upload the images.</u></strong></p> <p align="justify">The file which we will be creating will have the capability to upload files from the user’ hard disk and will send these file contents to the SaveFile.aspx page. The UploadFile.aspx will be created in a separate website/virtual directory called “UploadFiles” website. This aspx page will have a FileUpload control and a save button. So here is the HTML source of UploadFile.aspx.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p><%@ Page Language="C#" AutoEventWireup="true"  CodeFile="FileUpload.aspx.cs" Inherits="FileUpload" %> </p> <p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</a>> </p> <p><html xmlns="<a href="http://www.w3.org/1999/xhtml"">http://www.w3.org/1999/xhtml"</a>> <br /><head runat="server"> <br />    <title>Untitled Page</title> <br /></head> <br /><body> <br />    <form id="form1" runat="server"> <br />    <div> <br />    </div> <br />       <font color="#008000"><asp:Label ID="lblMessage" runat="server"></asp:Label><br /> <br />        <asp:FileUpload ID="fileUpload" runat="server" /><br /> <br />        <asp:Button ID="btnSave" runat="server" Text="Save Files" <br />        onclick="btnSave_Click" /> <br /></font>    </form> <br /></body> <br /></html></p> </td> </tr> </tbody></table> <p align="justify">From the HTML you can see that we have an FileUpload control and a save button with an OnClick event handler. So that’ our simple UploadFile page. Now lets see the real action i.e. the place where the code to upload files and sending the content of these files to the SaveFile.aspx in “SaveFiles” website happen. So here is the click event of the save button where all the action takes place.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>protected void btnSave_Click(object sender, EventArgs e) <br />{ <br />        /*Creating the WebRequest object using the URL of SaveFile.aspx.*/ <br />        System.Net.HttpWebRequest webRequest = <br />(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create <br />("<a href="Http://Localhost/SaveFiles/SaveFile.aspx");">Http://Localhost/SaveFiles/SaveFile.aspx");</a> <br />        webRequest.Method = "POST"; <br />        webRequest.KeepAlive = false; <br />        /*Assigning the content type from the FileUpload control.*/ <br />        webRequest.ContentType = fileUpload.PostedFile.ContentType; <br />        /*Creating the Header object.*/ <br />        System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection(); <br />        headers.Add("FileName", fileUpload.FileName); <br />        /*Adding the header to the WebRequest object.*/ <br />        webRequest.Headers = headers; <br />        /*Getting the request stream by making use of the GetRequestStream method of WebRequest object.*/ <br />        using (System.IO.Stream stream = webRequest.GetRequestStream())//Filling request stream with image stream. <br />        { <br />            /*Writing the FileUpload content to the request stream.*/ <br />            stream.Write(fileUpload.FileBytes, 0, fileUpload.FileBytes.Length); <br />        } <br />        /*Creating a WebResponse object by calling the GetResponse method of WebRequest object.*/ <br />        using (System.Net.HttpWebResponse webResponse = (System.Net.HttpWebResponse)webRequest.GetResponse()) <br />        { <br />            /*Retrieving the response stream from the WebResponse object by calling the GetResponseStream method.*/ <br />            using (System.IO.StreamReader sr = new System.IO.StreamReader(webResponse.GetResponseStream())) <br />            { <br />                lblMessage.Text = sr.ReadToEnd(); <br />            } <br />        } <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above code first I am creating a WebRequest object by passing the URL of the page which will handle the saving mechanism. Once the WebRequest object is created next I am assigning the Method as POST. This is a very important step. If you don’t assign the method property it will default to “GET”. If you use “GET” as the method to send data then you will receive System.Net.ProtocolViolationException with the following message.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><font color="#008000">"Cannot send a content-body with this verb-type."</font></td> </tr> </tbody></table> <p align="justify">Once the method is set to “POST” we are setting the KeepAlive property to false. KeepAlive property will be responsible for maintaining a live connection. The next line we are setting the ContentType of the request. The content type can be easily retrieved by calling the ContentType property from PostedFile property of the FileUpload Control. Next line we are creating a WebHeaderCollection object to pass additional information in the headers of the request. You can see we are passing the file name as one of the header value. These header details are read in SaveFile.aspx. So if you want send some extra information you can do that using WebHeaderCollection. In the next few lines we are retrieving the request stream using the GetRequestStream method and then writing the contents of the selected file to request stream using the Write method of the Stream object. To pump the content of the chosen file we are making use of the FileBytes property of the FileUpload control. One can note that we are making use of the “<a href="http://sandblogaspnet.blogspot.com/2009/04/using-statement-in-net.html" target="_blank">using</a>” statement quite a lot. To know more about the usefulness of the “<a href="http://sandblogaspnet.blogspot.com/2009/04/using-statement-in-net.html" target="_blank">using</a>” statement you can refer my blog on using statement <a href="http://sandblogaspnet.blogspot.com/2009/04/using-statement-in-net.html" target="_blank">here</a>. </p> <p align="justify">Once the FileUpload contents are pumped to the request stream of the HttpRequest object in the next line I am creating the HttpWebResponse using the GetResponse method of the HttpWebRequest object. So what GetResponse does is that it sends a request to the Url (savefile.aspx) specified while creating the HttpWebRequest object. When the HttpWebRequest object sends request to the url its similar to the way we access url through the browser. So the whole life cycle of the page executes and response is saved in the form of HttpWebResponse object. After getting the HttpWebResponse object we are reading what output was returned by the page using the StreamReader object’ ReadToEnd method. You can retrieve the StreamReader object by calling the GetResponseStream method of the WebRequest object. The response which I am getting is directly assigned to the Text property of a label control. What we get in the ResponseStream object is what we have written to the response using the Write method of the Response property in the SaveImage.aspx page. So if the image is successfully saved we get “File Successfully saved” as the response else we get error as the response.</p> <p align="justify">That’ it, we are done. With this technique we can save files or contents from one website to another site i.e. cross website posting of data. This technique is very simple but can be very dangerous. You should make sure that you implement some sort of authentication so that hackers can be evaded from saving some malicious files. </p> <p align="justify">Try to know more.</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com16tag:blogger.com,1999:blog-1454785102765291191.post-24753396348920080102009-08-10T19:48:00.001+05:302009-08-23T21:06:59.123+05:30Creating RESTful web services in .NET<p align="justify">This blog is about creating RESTful web services using Windows Communicaiton Foundation (WCF) in .NET. The intention of this blog is not to teach what is Representation State Transfer (REST) but how to create web services which support REST by making use of WCF. So lets start by having a look at what was the requirement which prompted me to create a RESTful web service and how we did it.</p> <p align="justify">As with any change in software, this change, to have RESTful web service was also raised by the client. The client in our case had some Business Access Layer (BAL) and he wanted to expose some of the methods to the outside world through RESTful web service. So what we did was we created a Facade layer to expose the required methods of the BAL and called exposed this Facade layer with the help of WCF web service. Thats the simple solution to our requirement. Now lets see the code wise implementation of the solution.</p> <p align="justify">As per company rules and other client agreement I may not be able to publish the same implementation but will try to take another e.g. and try to replicate the same scenario and create RESTful web services. We will see two ways of creating WCF, one is implementing the interface in class file and then exposing the class methods using a .SVC file and second approach is the default way i.e. implementing an interface to a .SVC file. Lets see the first way (this was the solution implemented to solve our problem).</p> <p align="justify">For creating a WCF service first thing you need is a contract. A contract is nothing but an Interface with the methods you want to expose. So lets create our contract (interface) which will be implemented by the WCF service. Any WCF webservice (RESTful or non RESTful) needs a contract, if no contract is defined then the class should be have the ServiceContract attribute to it and this is mandatory. Below is the interface definition.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>using System; <br />using System.Collections.Generic; <br />using System.Linq; <br />using System.Text; </p> <p>namespace CarService <br />{ <br />    <font color="#008000">[System.ServiceModel.ServiceContract] <br /></font>    public interface ICarService <br />    { <br />       <font color="#008000">[System.ServiceModel.OperationContract]  <br />       [System.ServiceModel.Web.WebGet(UriTemplate="cars",  <br />         ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Xml)] <br /></font>        List<Car> GetCars(); </p> <p>       <font color="#008000">[System.ServiceModel.OperationContract]  <br />       [System.ServiceModel.Web.WebGet(UriTemplate="cars/search?carName={theCarName}")] <br /></font>        Car GetCar(string theCarName); <br />    } <br />}</p> </td> </tr> </tbody></table> <p align="justify">From the above interface definition one can see that we are using some attributes. Lets see each of these attributes one by one. First up is the ServiceContract attribute.</p> <p align="justify"><strong>ServiceContract: </strong>This attribute tells the system that the interface defines a service contract for a WCF application. If an interface which is being inherited by a WCF web service doesn’t have a ServiceContract attribute then the following error will thrown by the system.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><i><font color="#ff0000">Service 'CarService' implements multiple ServiceContract types, and no endpoints are defined in the configuration file. WebServiceHost can set up default endpoints, but only if the service implements only a single ServiceContract. Either change the service to only implement a single ServiceContract, or else define endpoints for the service explicitly in the configuration file.</font></i></td> </tr> </tbody></table> <p align="justify">Just applying the ServiceContract attribute above the interface will solve the above error. Now lets see the various properties associated with the ServiceContract attribute </p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td width="115"><strong>Property</strong></td> <td width="272"><strong>Description</strong></td> </tr> <tr> <td valign="top" width="115">ConfigurationName</td> <td width="272"> <p align="justify">The element name in the configuration file which defines the service.</p> </td> </tr> <tr> <td valign="top" width="115">Name</td> <td width="272"> <p align="justify">Using the property you can provide a different name to the interface. </p> </td> </tr> <tr> <td valign="top" width="115">Namespace</td> <td width="272">Can be used to provide namespace.</td> </tr> <tr> <td valign="top" width="115">ProtectionLevel</td> <td width="272"> <p align="justify">enum value specifies what type of protection should be applied to the service. The enum values are ProtectionLevel.None, ProtectionLevel.Sign and ProtectionLevel.EncryptAndSign</p> </td> </tr> <tr> <td valign="top" width="115">SessionMode</td> <td width="272"> <p align="justify">enum specifies whether sessions are allowed or not. The enum values are SessionMode.Allowed, SessionMode.Required and SessionMode.NotAllowed.</p> </td> </tr> </tbody></table> <p align="justify">That’ about ServiceContract attribute. The next attribute which we have used in all the methods is the OperationContract attribute. Lets see what does OperationContract do.</p> <p align="justify"><strong>OperationContract: </strong>OperationContract attribute tells the system that the method needs to be exposed as part of a service contract. A method which is not having OperationContract will not be exposed. So its imperative to have OperationContract attribute to expose a method. The properties which can be used along with OperationContract are.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><strong>Property</strong></td> <td><strong>Description</strong></td> </tr> <tr> <td valign="top">Action</td> <td> <p align="justify">Using the action property you can specify a url to which the incoming messages needs to be posted. Action uniquely identifies a method with a Url.</p> </td> </tr> <tr> <td valign="top">AsyncPattern</td> <td> <p align="justify">Specifies whether the method can be called asynchronously or not.</p> </td> </tr> <tr> <td valign="top">IsOneWay</td> <td> <p align="justify">Specifies whether the operation returns a value or not.</p> </td> </tr> <tr> <td valign="top">IsInitiating</td> <td> <p align="justify">Specifies whether the method needs to be called when session is started.</p> </td> </tr> <tr> <td valign="top">IsTerminating</td> <td> <p align="justify">Tells the system to execute the method when session is completed.</p> </td> </tr> <tr> <td valign="top">Name</td> <td> <p align="justify">If you want to give some other name to the method then you can make use of the name property.</p> </td> </tr> <tr> <td valign="top">ProtectionLevel</td> <td> <p align="justify">enum value specifies what type of protection should be applied to the service. The enum values are ProtectionLevel.None, ProtectionLevel.Sign and ProtectionLevel.EncryptAndSign</p> </td> </tr> </tbody></table> <p align="justify">Next attribute which you will notice is the WebGet. Here is the explanation of WebGet attribute.</p> <p align="justify"><strong>WebGet:</strong> If you would have worked on ASP.NET application then you know that the forms in ASP.NET post data in two ways, one is the GET method and the other one is the POST method. WebGet attribute tells the system that the method is a pure data retrieval method to which HTTP GET method is associated. The properties associated with WebGet are listed below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><strong>Property</strong></td> <td><strong>Description</strong></td> </tr> <tr> <td valign="top">BodyStyle</td> <td> <p align="justify">enum specifies how messages should be sent. Enum values are WebMessageBodyStyle.Bare, WebMessageBodyStyle.Wrapped, WebMessageBodyStyle.WrappedRequest and WebMessageBodyStyle.WrappedResponse.</p> </td> </tr> <tr> <td valign="top">RequestFormat</td> <td> <p align="justify">enum specifies what is the request format. Enum values are WebMessageFormat.Xml and WebMessageFormat.Json.</p> </td> </tr> <tr> <td valign="top">ResponseFormat</td> <td> <p align="justify">Same as RequestFormat. Specifies the type of the response.</p> </td> </tr> <tr> <td valign="top">UriTemplate</td> <td> <p align="justify">The Uri to access the method/operation.</p> </td> </tr> </tbody></table> <p align="justify">UriTemplate here is the endpoint. Here endpoint means a unique Url to access the method in a restful webservice. This is one of the requirement of a RESTful method which says there should be unique endpoint to access the methods.</p> <p align="justify">One thing to note in UriTemplate property is that whatever you specify inside a curly brace, {}, and if the same name is used in the parameter of the method then the value which comes in the querystring is passed on as the parameter for the method. In our second method in the interface we have given the UriTemplate as something like this “<font color="#008000">cars/search?carName={theCarName}</font> ” which means the querystring value in carName will be passed as the parameter to the method, as the parameter name and value inside the curly brace are the same. If you want more parameters you can very well do this by declaring more parameters in the querystring. A hypothetical method is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>[System.ServiceModel.OperationContract] <br />[System.ServiceModel.Web.WebGet(UriTemplate = "cars/Carsearch?carName={theCarName}&color={theColor}&price={thePrice}")] <br />Car SearchCar(string theCarName, string theColor, string thePrice);</p> </td> </tr> </tbody></table> <p align="justify">In the above e.g. theCarName, theColor and thePrice will be passed as parameter to the method SearchCar. The url may look something like this “http://localhost:2333/cars/carsearch?carName=ferrari&color=red&price=432544”. The values ferrari, red and 432544 will be passed as parameters to the SearchCar method. So if you want to pass parameters to a RESTful web method then you need to just follow the above approach. </p> <p align="justify">Now that was about making use of HTTP GET method. The next obvious question would be how to make use of HTTP POST method. To make use of HTTP POST method one need to apply another attribute called “WebInvoke” All the properties are same as in WebGet except for an extra property called Method. Using the method property you can specify the HTTP method like POST, PUT, DELETE and HEAD. When to use each of these HTTP method is given below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td width="84"><strong>HTTP Method</strong></td> <td width="303"><strong>Description</strong></td> </tr> <tr> <td valign="top" width="84">GET</td> <td width="303">Whenever you want to retrieve some information you will make use of get.</td> </tr> <tr> <td valign="top" width="84">POST</td> <td width="303">When you want to submit data which will be processed by the service.</td> </tr> <tr> <td valign="top" width="84">PUT</td> <td width="303">When you want create or update a resource you will make use of PUT.</td> </tr> <tr> <td valign="top" width="84">DELETE</td> <td width="303">As the name suggest whenever you want to delete a resource you will make use of DELETE.</td> </tr> </tbody></table> <p align="justify">Now we have our contract defined. So the first step is over. Now we need to implement the interface and that is what we are going to do next. We will be implementing the interface in a class called CarService. The code is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>namespace CarService <br />{ <br />    public class CarService : ICarService <br />    { <br />        List<Car> carList; <br />        public CarService() <br />        { <br />            carList = new List<Car> {new Car{ModelName="Ferrari", Color="Ferrari Red", CubicCentimeter= "2345", <br />             Price=34324324}, new Car{ModelName="BMW 3 Series", Color="Blue", CubicCentimeter= "2200", <br />             Price = 32423}, new Car{ModelName="Benz SLR", Color="Milky White", CubicCentimeter = "3200", <br />             Price = 32424}};//Storing the car objects in a collection <br />        } <br />        List<Car> ICarService.GetCars() <br />        { <br />            return carList; <br />        } </p> <p>        Car ICarService.GetCar(string theCarName) <br />        {           <br />            var car = from c in carList where c.ModelName == theCarName select c; <br />            Car cs = null; <br />            foreach (var c in car) <br />            { <br />                cs = c as Car; <br />            } <br />            return cs; <br />        } <br />    } <br />}</p> </td> </tr> </tbody></table> <p align="justify">You can see from the above code we have implemented ICarService interface into a class called CarService. The first method returns the Car collection and the second method searches the carList collection object based on the name of the car and returns the matching Car object. No rocket science here. The Car class is discussed in detail at the end of the blog. So we will move on to the next step.</p> <p align="justify">We have defined the base requirement and now we have to expose the methods to the outside world using WCF service. For that you can either add a new WCF Service Applicaiton project from the file menu or you can right click on your ASP.NET or web service project and from the popup menu select Add—>New Item option. From the Add New Item dialog box select WCF Service and give a name to your service. I have named it CarService. The screenshot of Add New Item dialog is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEJQLpxRGL9Ds6nt1_fPl3Dcgc_wf3bEStUEaO4H3pM8OuiPbPhC-jxK3jqY5xlpSUj3WHyZxYFe0_uLA7ooazJxUIQsg6Rf_szmsHHXvlpTVpWaIY_REcMv-dux1T4zP-79kInHgc6rJ_/s1600-h/image9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9asBMjX2q85hZYWSIFQTxlDa9huXsJTF3t8CMlRcFKDuIUnC3lxEbW9mlXW0l8fRCqrdv30bRsXIeG8gwfdX9uWzAovBtJ9YlQ8wcD9nURlvaygeY8GPVklZrCjxRdbMpTzqssV4cy7mt/?imgmax=800" width="395" height="244" /></a> </td> </tr> </tbody></table> <p align="justify">You can do the same from file menu as well. </p> <p align="justify">When you add WCF Web service application or a SVC file the system will automatically add an interface by the name ICarService or I followed by whatever name given to the project or SVC file. Delete the interface, as we have already defined the contract. Also delete the SVC.cs file. Now open the SVC file, in my case CarService.svc. You can see a markup something like this.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><%@ ServiceHost Language="C#" Debug="true" Service="CarService.CarService" <font color="#008000">CodeBehind="Service1.svc.cs"</font> %></td> </tr> </tbody></table> <p>Delete the CodeBehind attribute and add Factory attribute as shown below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p><%@ ServiceHost Language="C#" Debug="true" <br />Service="CarService.CarService" <font color="#008000">Factory="System.ServiceModel.Activation.WebServiceHostFactory"</font> %></p> </td> </tr> </tbody></table> <p>You may get an error something like the one pasted below. </p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><i><font color="#ff0000">Service 'CarService.CarService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.</font></i></td> </tr> </tbody></table> <p>If you come across an error like this then the possible reason could be you will be missing the Factory attribute in the ServiceHost tag. Just by adding the Factory attribute will solve the prob.</p> <p>Visual studio also embeds the following tag in Web.config file. </p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p><system.serviceModel> <br />        <behaviors> <br />   <serviceBehaviors> <br />    <behavior name="RestFulWebservice.CarServiceBehavior"> <br />     <serviceMetadata httpGetEnabled="true" /> <br />     <serviceDebug includeExceptionDetailInFaults="false" /> <br />    </behavior>    <br />   </serviceBehaviors> <br />  </behaviors> <br />        <services> <br />   <service behaviorConfiguration="RestFulWebservice.CarServiceBehavior" <br />    name="RestFulWebservice.CarService"> <br />    <endpoint address="" binding="wsHttpBinding" contract="CarService.ICarService"> <br />     <identity> <br />      <dns value="localhost" /> <br />     </identity> <br />    </endpoint> <br />    <endpoint address="" binding="mexHttpBinding" contract="IMetadataExchange" />    <br />   </service> <br />  </services> <br /></system.serviceModel></p> </td> </tr> </tbody></table> <p align="justify">Now you are ready to go. Just hit F5 and see the output. If you see a message saying there is no endpoint defined you need not panic. Just type one of the endpoints defined in the contract (interface) you can see the output. In my case the two url which I used are as follows.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><a title="http://localhost:3891/CarService.svc/cars" href="http://localhost:3891/CarService.svc/cars"><font color="#008000">http://localhost:3891/CarService.svc/cars</font></a> <br />Ouput of the above url <br /> <p><GetCarsResponse xmlns="<a href="http://tempuri.org/"">http://tempuri.org/"</a>> <br />     <GetCarsResult xmlns:a="<a href="http://schemas.datacontract.org/2004/07/CarService"">http://schemas.datacontract.org/2004/07/CarService"</a> xmlns:i="<a href="http://www.w3.org/2001/XMLSchema-instance"">http://www.w3.org/2001/XMLSchema-instance"</a>> <br />         <a:Car> <br />          <a:Color>Ferrari Red</a:Color> <br />          <a:CubicCentimeter>2345</a:CubicCentimeter> <br />          <a:ModelName>Ferrari</a:ModelName> <br />          <a:Price>34324324</a:Price> <br />          </a:Car> <br />         <a:Car> <br />          <a:Color>Blue</a:Color> <br />          <a:CubicCentimeter>2200</a:CubicCentimeter> <br />          <a:ModelName>BMW 3 Series</a:ModelName> <br />          <a:Price>32423</a:Price> <br />          </a:Car> <br />         <a:Car> <br />          <a:Color>Milky White</a:Color> <br />          <a:CubicCentimeter>3200</a:CubicCentimeter> <br />          <a:ModelName>Benz SLR</a:ModelName> <br />          <a:Price>32424</a:Price> <br />          </a:Car> <br />      </GetCarsResult> <br /></GetCarsResponse></p> <p><a title="http://localhost:3891/CarService.svc/cars/search?carName=ferrari" href="http://localhost:3891/CarService.svc/cars/search?carName=Ferrari"><font color="#008000">http://localhost:3891/CarService.svc/cars/search?carName=Ferrari</font></a></p> <p>Output of the above url.</p> <p><Car xmlns="<a href="http://schemas.datacontract.org/2004/07/CarService"">http://schemas.datacontract.org/2004/07/CarService"</a> xmlns:i="<a href="http://www.w3.org/2001/XMLSchema-instance"">http://www.w3.org/2001/XMLSchema-instance"</a>> <br />  <Color>Ferrari Red</Color> <br />  <CubicCentimeter>2345</CubicCentimeter> <br />  <ModelName>Ferrari</ModelName> <br />  <Price>34324324</Price> <br /></Car></p> </td> </tr> </tbody></table> <p>The car class which is getting serialized is shown below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>[System.Runtime.Serialization.DataContract] <br />public class Car <br />{        <br />        [System.Runtime.Serialization.DataMember] <br />        public string Color <br />        { get; set; } <br />        [System.Runtime.Serialization.DataMember] <br />        public string ModelName <br />        { get; set; } <br />        [System.Runtime.Serialization.DataMember]        <br />        public int Price <br />        { get; set; } <br />        [System.Runtime.Serialization.DataMember] <br />        public string CubicCentimeter <br />        { get; set; } <br />}</p> </td> </tr> </tbody></table> <p align="justify">The objects used in WCF should be qualified by DataContract attribute. Some of the properties of DataContract are listed below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><strong>Property</strong></td> <td><strong>Description</strong></td> </tr> <tr> <td valign="top">Name</td> <td>If you want to give a different name to the class when it is serialized then you can make use of the name property.</td> </tr> <tr> <td valign="top">Namespace</td> <td>To provide a namespace to the xml attribute you can make use of the “Namespace” property. When you provide namespace it has abide by w3 guidelines. As a general practice we provide urls as namespace.</td> </tr> </tbody></table> <p align="justify">The other attribute is the DataMember. DataMember attribute tells the serializer that the property/field is part of a DataContract and it can be serilizable. Some of the properties are explained below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td><strong>Property</strong></td> <td><strong>Description</strong></td> </tr> <tr> <td valign="top">EmitDefaultValue</td> <td>Property which tells the serializer whether to emit default value if the property is not having any value.</td> </tr> <tr> <td valign="top">IsRequired</td> <td>This property can be set when you want the property/field to be present while serializing and deserializing the object.</td> </tr> <tr> <td valign="top">Name</td> <td>If you want to give some other name other than name of the property/field then you can make use the Name property.</td> </tr> <tr> <td valign="top">Order</td> <td>When the object is serialized in what order the property/field needs to be serialized.</td> </tr> </tbody></table> <p align="justify">Now lets see the second way of implementing the WCF webservice. This is the most common way which everyone will be aware off. Open VS 2008 and add a new project of type WCF Service Application from File—>New—>Project menu. This will automatically add a contract (interface) and the necessary .SVC files (a .svc and a .svc.cs file inheriting from the interface). Rest we need to follow the same steps for defining various methods in the Interface as explained above.</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com8tag:blogger.com,1999:blog-1454785102765291191.post-42628063252293714312009-08-08T17:50:00.001+05:302009-08-08T18:33:49.307+05:30Formatting numeric data types in .NET<p align="justify">Recently I was discussing with one of my friend and he informed me that he was breaking his head on creating a utility to format decimals, float and other datatypes. Out of curiosity I asked him how are you doing these, for e.g. displaying a decimal datatype with only two decimal place value. Bang came the reply that he is doing some string manipulation. I was surprised and informed him that he need not take so much of a pain instead he can use ToString methods of most of the datatype to format the data types. In this blog I will highlight some of the commonly needed number formatting techniques.</p> <p align="justify"><strong><u>First up formatting for decimal places.</u></strong></p> <p align="justify">This is one of the common requirement where we always come across situation to format float, decimal and double datatypes to some number of decimal places. One of the easiest way to format is given below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double doub = 8457.3299; <br />float fl = 28398.39843289f; <br />decimal dec = 982389.348093m; <br />Console.WriteLine(doub.ToString(".00"));//Output: 8467.33 <br />Console.WriteLine(fl.ToString(".000"));//Output: 28398.400 <br />Console.WriteLine(dec.ToString(".0000"));//Output: 982389.3481</p> </td> </tr> </tbody></table> <p align="justify">In the above e.g. I have used zero in combination with decimal symbol to format the numbers according to the required precision required. If the need is to format to the max of two decimal places I have used “.” (dot) followed by 2 zeroes. Similarly how many precision points you want you can use that number of zeroes along with dot. Isn’t it so simple? One thing to note here is that the system will automatically round off the numbers if there are more decimal places than what is specified in the format string as you can see in the above e.g.</p> <p align="justify"><strong><u>Formatting numbers</u></strong></p> <p align="justify">Some number formatting e.g. are given below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double doub = 8457.3299; <br />float fl = 28398.39843289f; <br />decimal dec = 982389.348093m; <br />Console.WriteLine(doub.ToString("000"));//Ouput 8457 <br />Console.WriteLine(fl.ToString("00000000"));//Ouput 00028398 <br />Console.WriteLine(dec.ToString("00000.000"));//Ouput 982389.348 <br />Console.WriteLine(dec.ToString("<font color="#800000">00 - 00 - 0.000</font>"));//Ouput 982 - 38 - 9.348 <br />Console.WriteLine(dec.ToString("<font color="#800000">(00000) (00) (0)</font>"));//Ouput (00982) (38) (9)</p> </td> </tr> </tbody></table> <p align="justify">In the above e.gs we have used zeroes to format numbers. First formatting using 3 zeroes doesn’t do much. It just displays the numbers as it is. The second one with 8 zeroes formats numbers and adds extra zeroes if the number doesn’t have the required digits i.e. in the above e.g. there are only 5 digits and because of formatting applied it adds extra zeroes preceeding the number. Use of zero to format numbers tells the system that even if zero is not a significant number it should display zero. One can use other characters along with zero to format the numbers. Few e.g. have been highlighted above.</p> <p align="justify"><strong><u>Formatting numbers using # symbol</u></strong></p> <p align="justify">One of the problem while using 0 to format numbers is that it will show the insignificant numbers or club zeroes to fill the gap. To avoid just this you can make use of # symbol in place of 0. To show the difference between # and 0 I have pasted below same e.g. with both the format string.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double twoDeci = 1234.34; <br />int flo = 2343243; <br />decimal deci = 23434355.6749m; <br />Console.WriteLine(twoDeci.ToString("######.####"));\\Output 1234.34 <br />Console.WriteLine(twoDeci.ToString("000000.0000"));\\Ouput 001234.3400 <br />Console.WriteLine(flo.ToString("(####) - (###) - (##)"));\\Output (23) - (432) - (43) <br />Console.WriteLine(flo.ToString("(0000) - (000) - (00)"));\\Output (0023) - (432) - (43) <br />Console.WriteLine(deci.ToString(".##"));\\Output 23434355.67 <br />Console.WriteLine(deci.ToString(".00"));\\Output 23434355.67</p> </td> </tr> </tbody></table> <p>From the above e.gs one can make out that if you are using 0 as the format string then it adds insignificant zeroes preceding or leading the numbers, whereas # will ignore insignificant zeroes. Also one thing to note is that if you use # with numbers with insignificant zeroes then it will ignore those zeroes whereas 0 will consider the zeroes as significant. The difference is shown below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>float preecedingZeroes = 00034556; <br />double leadingZeroes = 34345.983000; <br />Console.WriteLine(preecedingZeroes.ToString("########"));\\Ouput 34556 <br />Console.WriteLine(preecedingZeroes.ToString("00000000"));\\Ouput 00034556 <br />Console.WriteLine(leadingZeroes.ToString("#####.######"));\\Ouput 34345.983 <br />Console.WriteLine(leadingZeroes.ToString("00000.000000"));\\Ouput 34345.983000</p> </td> </tr> </tbody></table> <p>From the above e.g. differences are clear that # never takes into consideration the insignificant zeroes even if there is one in the datatype. So if you want the insignificant zeroes to be considered then you need to use 0 instead of #.</p> <p><strong><u>Formatting for thousand separator.</u></strong></p> <p align="justify">Many a times we get numbers from the database without any formatting applied and we may require the numbers to be formatting with thousand separators. Its very easy to apply thousand separators to a number. E.g. are pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double preecedingZeroes = 345563434; <br />Console.WriteLine(preecedingZeroes.ToString("#,#"));\\Output 345,563,434 <br />Console.WriteLine(preecedingZeroes.ToString("0,0"));\\Output 345,563,434</p> </td> </tr> </tbody></table> <p align="justify">The above e.g. makes use of both # and 0 along with “,” sign for thousand formatting. Comma (,) can be used along with other format strings to apply thousand formatting. One thing to note here is that when you apply thousand separator formatting then the system makes use of the system’ culture and thousand separator associated with the culture. If you want to use a specific culture’ thousand separator then you need to provide the culture you want to use along with the “ToString” method. Here are e.g. in Danish and Indian format.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>//Applies Hindi-India culture and formats the number based on Indian notations. <br /><font color="#008000">Console.WriteLine(preecedingZeroes.ToString("#,#", System.Globalization.CultureInfo.CreateSpecificCulture("hi-IN")));</font>//Ouput 34,55,63,434 <br />//Applies Danish culture and formats the number based on Danish culture. <br /><font color="#008000">Console.WriteLine(preecedingZeroes.ToString("0,0", System.Globalization.CultureInfo.CreateSpecificCulture("da-DK")));</font>//Ouput 345.563.434</p> </td> </tr> </tbody></table> <p>So you can see from the above e.g. that in the Indian culture the thousand separator used is comma (,) whereas in Danish culture the thousand separator is represented by a dot (.)</p> <p align="justify">One thing to note here is that if you use “,” one after the other without any number formatting characters in between them, then the meaning of comma completely changes. The system consider each comma as 1000 and divides the number to which formatting is applied by 1000. Confused, let me explain with e.g.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double dou = 23432432423; <br /><font color="#008000">Console.WriteLine(dou.ToString("#,,"));</font>//Output 23432 <br /><font color="#008000">Console.WriteLine(dou.ToString("0,,,"));</font>//Output 23</p> </td> </tr> </tbody></table> <p align="justify">In the above e.g. if you see in the first formatting we have used two commas which means the number “23432432423” will be divided by thousand two times as the number of commas occur two times in the formatting string. Similarly in the second sample code the commas occur thrice so the number will be divided by 1000 three times.</p> <p align="justify"><strong><u>Formatting for positive and negative numbers.</u></strong></p> <p align="justify">There may situation where you don’t know what type of number you are getting from the database, whether the number is a positive or a negative one. Even the number can be a zero. You would like to apply different formatting for positive number and different formatting for negative number. Also you would like to show zero in a different way. I have faced a similar prob in one of my projects where the client wanted to display a positive symbol enclosed in brackets (+) in front of a positive number, a negative symbol enclosed in brackets (-) in case of negative numbers and a zero enclosed in brackets (0) in the case of zero. If you also face a similar kind of situation you can make use “;” (semi colon) to separate the formatting. Sample formatting code is given below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double positiveNo = 3746; <br />double negativeNo = -3435; <br />double zero = 0; <br />string formatString = "(+)#;(-)#;(0)"; <br />Console.WriteLine(positiveNo.ToString(formatString));//Output (+)3746 <br />Console.WriteLine(negativeNo.ToString(formatString));//Output (-)3435 <br />Console.WriteLine(zero.ToString(formatString));//Output (0)</p> </td> </tr> </tbody></table> <p align="justify">In the above e.g. if you notice I have defined the formatting string for positive, negative and zero in the variable “formatString”. Semi colon (;) is used as the separator for the different number format. This is how this works, starting from left in the formatString variable the format string to the left of the first semi colon is considered as the formatting string for positive numbers, and the format string in between the first semi colon and the second semi colon is considered the format string for negative values and the format string to the right of second semi colon is taken as the format string for zeroes. </p> <p align="justify">If you don’t want to give separate formatting for zero then you can just leave the format string after the second semi colon empty i.e. you need to only specify format strings for positive and negative values. In such situation the format string for positive value will be applied to format zeroes. The sample is given below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double positiveNo = 3746; <br />double negativeNo = -3435; <br />double zero = 0; <br />string formatString = "(+)#;(-)#"; <br />Console.WriteLine(positiveNo.ToString(formatString));//Output (+)3746 <br />Console.WriteLine(negativeNo.ToString(formatString));//Output (-)3435 <br />Console.WriteLine(zero.ToString(formatString));//Output (+)</p> </td> </tr> </tbody></table> <p><strong><u>Multiplying a number by 100.</u></strong></p> <p align="justify">If you want to multiply a number by 100 one can make use of the % symbol in the format string along with other format strings. Sample code is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double dd = .459; <br />double ddd = 849; <br />Console.WriteLine(dd.ToString("#%"));//Output 46% <br />Console.WriteLine(dd.ToString(".#%"));//Output 45.9% <br />Console.WriteLine(ddd.ToString("#%"));//Output 84900% <br />Console.WriteLine(dd.ToString("#.#%"));//Output 45.9% <br />Console.WriteLine(ddd.ToString("0%"));//Output 84900%</p> </td> </tr> </tbody></table> <p align="justify">You can see from the above e.g. that by using the % sign along with other format strings the number gets multiplied by 100 and % symbol is appended at the end of the number. </p> <p align="justify"><strong><u>Appending currency symbol to a number.</u></strong></p> <p align="justify">Another common requirement is to append the currency symbol along with numbers. To do just that one can make use of “C” or “c” character in the format string. The e.g. is given below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double curFor = 329.5943; <br />Console.WriteLine(<font color="#800000">curFor.ToString("C")</font>);//Output $329.59 <br />Console.WriteLine(<font color="#800000">curFor.ToString("C3")</font>);//Output $329.594</p> </td> </tr> </tbody></table> <p align="justify">The currency symbol and precision points will be taken from the current culture set for the system. If you want to specify precision points for decimal value then you can specify the number of precision points after the “C” symbol as shown in the above e.g. If you want to change the current culture and apply some other culture then you can do that as shown in the below e.g.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td>Console.WriteLine(curFor.ToString("C3", <font color="#800000">System.Globalization.CultureInfo.CreateSpecificCulture("en-GB")</font>));//Output £329.594</td> </tr> </tbody></table> <p align="justify">In the above e.g. we are using currency format specifier with 3 decimal point precision and also we are applying Great Britain’ i.e. UK’ culture. This formats the number and adds the pound symbol.</p> <p align="justify"><strong><u>Displaying numbers in exponential form</u></strong></p> <p align="justify">If you want to display numbers in exponential format you can make use of “E” or “e”. Sample code is pasted below. </p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double exp = 43895.04390; <br />Console.WriteLine(exp.ToString("e"));//Output 4.389504e+004</p> </td> </tr> </tbody></table> <p align="justify">If you want you can specify the number of precision decimal points to be displayed. If the precision points are not specified then the system by default will add 6 precision points after the decimal point. Sample code with precision point is pasted below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>double exp = 43895.04390; <br />Console.WriteLine(exp.ToString("E9"));//Output 4.389504390E+004</p> </td> </tr> </tbody></table> <p align="justify">So with that I have covered some of the common number formatting requirements. </p> <p align="justify">Try to know more.</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com3tag:blogger.com,1999:blog-1454785102765291191.post-50655787393738843912009-07-09T18:05:00.001+05:302009-08-28T11:31:23.108+05:30Lambda Expressions – Features of C# 3.0 (Part – 6)<p align="justify">In my earlier article we have seen the following new features of C# 3.0.</p> <ul> <li><a href="http://sandblogaspnet.blogspot.com/2009/02/extension-methods-features-of-c-30-part.html">Extension Methods</a> </li> <li><a href="http://sandblogaspnet.blogspot.com/2009/03/automatic-properties-features-of-c-30.html">Automatic Properties</a> </li> <li><a href="http://sandblogaspnet.blogspot.com/2009/04/implicitly-typed-variable.html">Implicitly Typed variables</a> </li> <li><a href="http://sandblogaspnet.blogspot.com/2009/04/object-initializers-and-collection.html">Object Initializers and Collection Initializers</a> </li> <li><a href="http://sandblogaspnet.blogspot.com/2009/06/anonymous-types-features-of-c-30-part-5.html" target="_blank">Anonymous Types</a> </li> </ul> <p align="justify">In this blog we will try to understand the concept of Lambda expressions. </p> <p align="justify"><strong><u>What is Lambda Expression?</u></strong></p> <p align="justify">Lambda expressions are nothing but anonymous functions. Lambda expressions can be used to write expressions or statements. To write Lambda expression one has to make use of the Lambda operator which is read as “goes to”. Lambda operator is represented as “=>” i.e. an equal to sign followed by a greater than symbol. Lambda expressions normally have input parameters on the left side of the Lambda operator and expressions/statements on the right side. The lambda operator is used to separate the input arguments on the left side from the expression/statements on the right side. Lambda expressions are extensively used in LINQ. An e.g. of Lambda expression is given below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>public class LambdaExpressionDemo <br />{ <br />    delegate int Add(int a, int b); <br />    public void PrintAddResult(int num1, int num2) <br />    { <br />        Add addResult = <font color="#008000">(a, b) => a + b</font>; <br />        Console.WriteLine(addResult(num1, num2).ToString()); <br />    } </p> <p>    public double CountEmp() <br />    { <br />         System.Collections.Generic.List<Person> perColl = new List<Person>{ <br />             new Person {FName="first", LName="lastFirs", Age=30}, <br />             new Person{FName="second", LName="lastSecond", Age=24}, <br />             new Person{FName="third", LName="Third", Age=44}}; <br />            double avgAge = perColl.Count(<font color="#008000">p => p.LName.StartsWith("la")</font>);  <br />         return avgAge; <br />     }    <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above code one can see we have declared a delegate which returns an integer value and takes two integers as input parameters. Also you can see I have declared a delegate variable (addResult) and assigned an anonymous function using our Lambda expression. One thing to note here is that there is no need to declare the type of the input arguments for the anonymous functions. The compiler will infer the type. What the above lambda expressions means is that we have an anonymous function with two input parameters (left side of the Lambda operators are input parameters) which needs to be added and the result returned. Don’t you thing this is a very simple way of declaring a function. In the second e.g. I have made use of Lambda expression along with Count method. The lambda expression evaluates and checks whether the person’ LName starts with “la” and returns true or false. If it returns true then that record is counted. So the count will be 2. </p> <p align="justify">To better understand the advantages/usefullness of Lambda expression we need to know how we use to implement these things in the earlier versions of C#. Lets see how we would do this in C# 2.0 using anonymous methods.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>delegate int Add(int a, int b); <br />public void PrintAddResult(int num1, int num2) <br />{ <br />    //Using anonymous methods of C#2.0. <br />    Add addResult = <font color="#008000">delegate(int aa, int bb) { return aa + bb; }; <br /></font>    Console.WriteLine(addResult(num1, num2)); <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above e.g. we are making use of Anonymous method feature of C# 2.0 where we are making use of delegates to declare an Anonymous methods (highlighted in green). Wherever you thing creating a method is redundant or will create overhead you can go ahead and make use of Anonymous methods. Also one can use anonymous methods in cases where a method or property or constructor expects a delegate. In the above code we have declared a delegate with the signature of the method and then again using delegate variable, addResult, we are declaring an Anonymous method. One can write any number of statements inside Anonymous methods. The scope of the variables declared in Anonymous methods are within the limits of Anonymous methods. </p> <p align="justify">Now lets see how we would have done this in the good olden days of C#1.0.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>delegate int Add(int a, int b); <br />public void PrintAddResult(int num1, int num2) <br />{ <br />    //The good olden days of C#1.0 <br />    Add additionDel = Addition; <br />} </p> <p>public int Addition(int a, int b) <br />{ <br />    return a + b; <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above code you can see the good olden days of delegate declaration where one has to create a method (Addition) and then create a delegate (Add) representing the method. Once you have declared the delegate one can assign the method. So after seeing the olden ways of declaring the same functionality which can be achieved using Lambda expression one can see the advantages.</p> <p align="justify">One can define two types of lambda, an Expression Lambda and a Statement Lambda. Lets see what each one of it means.</p> <p align="justify"><strong>Expression Lambda: </strong>Expression lambda is nothing but an expression on the right side of the Lambda Operator. E.g are given below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td>(a, b) =>  (a + b); <br />(int a, int b) => a > b;</td> </tr> </tbody></table> <p align="justify">An expressions is any piece of code which can be evaluated to a single value, object etc. So the above code are just e.g. of expressions, even an assignment of a value to a variable is also an expression.</p> <p align="justify"><strong>Statement Lambdas: </strong>As the name suggests statement lambdas are ones which can have more than one line of code/statement. In expression lambda you normally have only one line of statement which executes and produces the output in the form of a single value or object etc whereas in statement lambda we have more than one line of statements enclosed in a curly brace ({}).</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>delegate int Add(int a, int b); <br />public void StatementLambda(int operand1, int operan2) <br />{ <br />    <font color="#008000">Add result = (a, b) => <br />    { <br />        int c = a + b; <br />        Console.WriteLine(c.ToString()); <br />        return c; <br />    }; <br /></font>    result(operand1, operan2); <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above code you can see we have written some three lines of code and this is an e.g. of statement Lambda. There are no restriction to the number of lines of code that can be written in a Lambda expression. As a good practice it will be nice if you can restrict the number of lines between 2 and 3 lines.</p> <p align="justify"><strong><u>Some points about Lambda expressions</u></strong></p> <ul> <li> <div align="justify">Lambda expressions are anonymous functions.</div> </li> <li> <div align="justify">No need to declare the types of the variables used in the input parameter of the Lambda expression. The types will be inferred by the compiler. </div> </li> <li> <div align="justify">If there are situation when the compiler cannot infer the type of the variable used, in those kind of scenarios we can explicitly declare the types for the input parameters as shown below.</div> </li> </ul> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>delegate int Add(int a, int b); <br />public void PrintAddResult(int num1, int num2) <br />{ <br />    Add result = (int a, int b) => a + b; <br />    Console.WriteLine(result(num1, num2).ToString()); <br />}</p> </td> </tr> </tbody></table> <ul> <li> <div align="justify">Variables declared in a Lambda expressions are scoped inside the Lambda blocks.</div> </li> <li> <div align="justify">Lambda declaration should match the signature of the delegate i.e. the number of parameters and return type.</div> </li> <li> <div align="justify">Parameter less Lambdas can also be declared just by having a empty parentheses as shown below.</div> </li> </ul> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>delegate void Print(); <br />public void ParameterLessLambda() <br />{ <br />    Print print = <font color="#008000">() => Console.WriteLine("Parameter less lambda executed."); <br /></font>    print(); <br />}</p> </td> </tr> </tbody></table> <ul> <li>You can pass Lambda expression where a delegate is expected. E.g. is shown below. </li> </ul> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>/*Lambda expression passed as an argument where delegate was expected.*/ <br />System.Threading.Thread thh = new System.Threading.Thread( <br />   <font color="#008000">() => Console.WriteLine("hi")</font>);</p> </td> </tr> </tbody></table> <ul> <li> <div align="justify">When you are making use of Lambda expressions behind the scene the compiler does the extra work of creating an anonymous function for the Lambda expression. Lets see with an e.g.: the code and generated IL are pasted below.</div> </li> </ul> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody> <tr> <td> <p>/*Class having a delegate and a Lambda expression.*/ <br />class LambdaExpression <br />{ <br />    delegate int Add(int operand1, int operand2); <br />    public void LambdaExp(int operan1, int operan2) <br />    { <br />        //Lambda expression. <br />        Add result = <font color="#008000">(a, b) => a + b; <br /></font>        Console.WriteLine(result(operan1, operan2)); <br />    } <br />}</p> <p>/*Below is the MSIL generated for the above method. */ <br />.method public hidebysig instance void LambdaExp(int32 operan1, <br />int32 operan2) cil managed <br />{ <br />    .maxstack 3 <br />    .locals init ( <br />        [0] class <br />LambdaExpressions.LambdaExpression/Add result) <br />    L_0000: nop <br />    L_0001: ldsfld class <br />LambdaExpressions.LambdaExpression/Add <br />LambdaExpressions.LambdaExpression::CS$<>9__Cach <br />edAnonymousMethodDelegate1 <br />    L_0006: brtrue.s L_001b <br />    L_0008: ldnull <br />    L_0009: ldftn int32 <br />LambdaExpressions.LambdaExpression::<LambdaExp>b <br />__0(int32, int32) <br />    L_000f: newobj instance void <br />LambdaExpressions.LambdaExpression/Add::.ctor <br />(object, native int) <br />    L_0014: stsfld class LambdaExpressions.LambdaExpression/Add <br />LambdaExpressions.LambdaExpression::CS$<>9__Cach <br />edAnonymousMethodDelegate1 <br />    L_0019: br.s L_001b <br />    L_001b: ldsfld class <br />LambdaExpressions.LambdaExpression/Add <br />LambdaExpressions.LambdaExpression::CS$<>9__Cach <br />edAnonymousMethodDelegate1 <br />    L_0020: stloc.0 <br />    L_0021: ldloc.0 <br />    L_0022: ldarg.1 <br />    L_0023: ldarg.2 <br />    L_0024: callvirt instance int32 <br />LambdaExpressions.LambdaExpression/Add::Invoke(i <br />nt32, int32) <br />    L_0029: call void [mscorlib]System.Console::WriteLine(int32) <br />    L_002e: nop <br />    L_002f: ret <br />}</p> <p>/*C# code decompiled from MSIL using .NET Reflector*/ <br />internal class LambdaExpression <br />{ <br />    // Methods <br />    public void LambdaExp(int operan1, int operan2) <br />    { <br />        Add result = <font color="#008000">delegate (int a, int b) { <br />            return a + b; <br />        }; <br /></font>        Console.WriteLine(result(operan1, operan2)); <br />    } </p> <p>    // Nested Types <br />    private delegate int Add(int operand1, int operand2); <br />}</p> </td> </tr> </tbody></table> <p align="justify">In the above pasted code you can see the MSIL generated is making use of AnonymousMethodDelegate i.e. the compiler is converting Lambda expressions into Anonymous functions. This is proven from the decompiled C# code from the MSIL pasted above. </p> <p align="justify">As with other features of C# 3.0 Lambda expression is also a way of writing terse code where the compiler does the extra work of generating the extra codes. In my next  we will have a look at Language Integrated Query (LINQ) for which all these features were incorporated in C#. Till then write terse code and try to learn more.</p> <p align="justify">Sandeep</p> Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com2tag:blogger.com,1999:blog-1454785102765291191.post-18545001973176526482009-07-03T14:26:00.003+05:302010-12-03T12:31:24.369+05:30Working with Modal Popup extender control.<p align="justify">This blog discusses about the ASP.NET AJAX ModalPopupExtender control. In this blog we will see how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, showing/displaying/calling the modal popup from a hyper link control within the gridview control and finally some important javascript methods of the ASP.NET AJAX ModalPopupExtender control. So first lets see how to use the ModalPopupExtender control. </p> <p align="justify"><strong><u>How to use the ASP.NET AJAX ModalPopupExtender control?</u></strong></p> <p align="justify">Drag and drop a ASP.NET button/LinkButton/ImageButton or any control to an aspx page. To add a ModalPopupExtender control, drag and drop the control from the toolbox or Select the any of the ASP.NET controls like (button/LinkButton/ImageButton or any other control) and click the button with a greater than symbol as shown below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"> <tbody> <tr> <td><a href="http://lh5.ggpht.com/_QY7fSC4VqiA/Sk3HrYCaMMI/AAAAAAAAC40/baIjKjgb8UI/s1600-h/image17.png"><img style="display: inline" title="image" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtQgAcZALdipOR-mGlC2ZoGf4T0KsSj8NiXSYie_hwpGOHCm1jUJgDglvchTzL6FnL64XgWlXe9Cax7WMDacxLhur348b5gUEDLO-MhIBgFHX_0hK_NRKH9yjGir5AdawQmvATy1laadnt/?imgmax=800" width="388" height="79" /></a> </td></tr></tbody></table> <p>When you click the arrow you will get a menu with an “Add Extender” option as shown below.</p> <table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"> <tbody> <tr> <td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8bhyZr_stOGQWSws3FXrQwxEd-iB_4mHytZG01PtDSauGTErzfY7NAvJDlS33UE5ouZtF6TcYFit4tLU0KsxeDWPKHXRf90kw-C9pFGMx7_VUUV-V28liuT4lJ8fTrpUa7tINyho1fFrO/s1600-h/image16.png"><img style="display: inline" title="image" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjU2euHtuvd9w0HnkzH_RWD9ZYDbqgeC9eX5wMmGa8i0R_W3yhiZv5jSKbkVBVrjaMyvxsTLmfLZ6e7k5ktsu-ePRG38jwfjsYz9xSStwmMbYiZaFYtrX0HmX_rq3uZgZ9Heiwl9MxIHV5Z/?imgmax=800" width="233" height="176" /></a> </td></tr></tbody></table> <p align="justify">Click the “Add Extender” menu option and select “ModalPopupExtender” from “Extender Wizard” popup. Once you have added the ModalPopupExtender control you need an ASP.NET panel control. This is because the ModalPopupExtender control will show the content of the Panel control as a popup. Add ASP.NET Panel control and the content which you want to display as popup into the ASP.NET Panel control. Sample code with all the above requirement is pasted below. Don’t forget to drag and drop the ScriptManager control to the page.</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; color: #f4f4f4; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><span style="color: #ffff00"><%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModalPopup.aspx.cs" Inherits="ModalPopup" %></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><span style="color: #ffff00"><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><span style="color: #0000ff"><!</span><span style="color: #800000">DOCTYPE</span> <span style="color: #ff0000">html</span> <span style="color: #ff0000">PUBLIC</span> <span style="color: #0000ff">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span> <span style="color: #0000ff">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><span style="color: #0000ff"><</span><span style="color: #800000">html</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://www.w3.org/1999/xhtml"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><span style="color: #0000ff"><</span><span style="color: #800000">head</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">title</span><span style="color: #0000ff">></span>Modal Popup Demo<span style="color: #0000ff"></</span><span style="color: #800000">title</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">style</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> .backgroundColor </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> background-color:Gray; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> filter:alpha(opacity=25); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"></</span><span style="color: #800000">style</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><span style="color: #0000ff"></</span><span style="color: #800000">head</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><span style="color: #0000ff"><</span><span style="color: #800000">body</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">form</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">="form1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">div</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">asp:ScriptManager</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="ScriptManager1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"></</span><span style="color: #800000">asp:ScriptManager</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Button</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="popupBtn"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Click to see the modal popup."</span> <span style="color: #0000ff">/></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Panel</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="Panel1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">="display: none; padding:10px; border:1px; border-style:solid;"</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#FF9933"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="400px"</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">h3</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="text-align: center;"</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">="header"</span><span style="color: #0000ff">></span>Modal Popup<span style="color: #0000ff"></</span><span style="color: #800000">h3</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">p</span><span style="color: #0000ff">></span>This is a Modal Popup extender control. You are seeing this because you have clicked the hyperlink button.<span style="color: #0000ff"></</span><span style="color: #800000">p</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">p</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="text-align: center;"</span><span style="color: #0000ff">><</span><span style="color: #800000">asp:Button</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="closeBtn"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Close"</span> <span style="color: #0000ff">/></</span><span style="color: #800000">p</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"></</span><span style="color: #800000">asp:Panel</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"><</span><span style="color: #800000">cc1:ModalPopupExtender</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="ModalPopupExtender"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #ff0000">TargetControlID</span><span style="color: #0000ff">="popupBtn"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #ff0000">PopupControlID</span><span style="color: #0000ff">="Panel1"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #ff0000">OkControlID</span><span style="color: #0000ff">="closeBtn"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #ff0000">BackgroundCssClass</span><span style="color: #0000ff">="backgroundColor"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #ff0000">DropShadow</span><span style="color: #0000ff">="true"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #ff0000">PopupDragHandleControlID</span><span style="color: #0000ff">="header"</span><span style="color: #0000ff">/></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"></</span><span style="color: #800000">div</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff"></</span><span style="color: #800000">form</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><span style="color: #0000ff"></</span><span style="color: #800000">body</span><span style="color: #0000ff">></span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><span style="color: #0000ff"></</span><span style="color: #800000">html</span><span style="color: #0000ff">></span></pre><!--CRLF--></div></div><p align="justify">From the above code one can see I have a ScriptManager, an asp:Button control, an asp:Panel control, some contents inside the panel control and then we have the ModalPopupExtender control. Normally when you attach an ASP.NET panel control to a ModalPopupExtender control it will become invisible in the HTML rendered to the browser and if due to some reason if the panel control is being displayed in the page then just set the "Style" property' “display” attribute to “none” as in the above e.g. Now when you click the button you will see a popup as shown below.</p><table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="400" bgcolor="#ffffff"><tbody></tbody><tbody><tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnLwXRt73oNZjnh0Il3R3E3Vk0byD7S0oBkwjCJ9Otkhd2E1-WpwkSe0HVm-KjscrzpUUOHRGwMdfvREyVXAp53FD-9aAgzvg-4Gc6phFxnpQSjc6LMRGuFO-1QnK_r_qSHTKm7waR9gFl/s1600-h/image4.png"><img style="display: inline" title="image" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPTHU1XFB1GsmogYDQvwwh0r2dYU7f0Xoz9j5cAD2pD8XdG5iqk5rFWLEoRvM09Ew0QNlvjzdoTMhAtuOvzbTNDuErnMsnYm40s9njDo6a2twIhPhmOZlp31-B_On7RAUskRCYsybxvvRa/?imgmax=800" width="388" height="244" /></a> </td></tr></tbody></table><p align="justify">Now lets see how to configure the ModalPopupExtender control. The configuration is pretty simple, you need to set some properties and and you will have your Modal popup. The properties are as follows</p><p align="justify"><strong>TargetControlID:</strong> This property is the one which tells, on click of which control the popup should be displayed. In our e.g. we have given the TargetControlID as our button control. You can assign the ID of any ASP.NET controls like LinkButton, ImageButton, HyperLink, DropDownList, CheckBox, RadioButton etc. Even you can give a label’ id as the TargetControlID.</p><p align="justify"><strong>PopupControlID: </strong>The ID of the control to be displayed as a modal popup. In our e.g. we have given ASP.NET panel control’ ID. You can give any ASP.NET control’ ID. If for e.g if you give the ID of a textbox then the textbox alone will be popped up. Its not compulsory that you should provide a ASP.NET panel control.</p><p align="justify"><strong>OkControlID: </strong>The ID of the control which should act as an Ok button. Clicking of this control will dismiss the popup.</p><p align="justify"><strong>BackgroundCssClass: </strong>The name of the CSS class which needs to be applied to the background of the popup. One thing to note here is that if you don’t provide a CSS class then the modal popup will not function like a modal dialog i.e. One will be able to interact with the controls in the back of the popup control, so its imperative to provide a valid CSS class name value to the BackgroundCssClass property. In the above e.g. we have defined a CSS class called “backgroundColor” in the header section of the aspx page. Please note in the CSS class definition we have applied “filter” property to make the background transparent.</p><p align="justify"><strong>DropShadow: </strong>Accepts a boolean value which specifies whether the popup should have shadow. True will give a shadow and false will disable the shadow.</p><p align="justify"><strong>PopupDragHandleControlID: </strong>The ID of the control clicking on which the ModalPopupExtender can be dragged. The control should be enclosed in the control specified using PopupControlID i.e. in our case inside the ASP.NET panel control. If a particular control ID is set as the PopupDragHandlerControlID then one can click on that control and drag the ModalPopupExtender control. In the above e.g. we have set the ID of the “h3” control as PopupDragHandleControlID, clicking which the popup can be dragged.</p><p align="justify"><strong>CancelControlID: </strong>If you want a button to behave as a Cancel button provide the ID of the button. This button will cancel the popup.</p><p align="justify"><strong>Drag: </strong>This property takes a boolean value which when set decides whether the popup control can have the drag feature. A value of true means the popup extender control can be dragged around the screen whereas false will disable the drag.</p><p align="justify"><strong>RepositionMode: </strong>This property accepts four values. They are “None”, “RepositionOnWindowResize”, “RepositionOnWindowResizeAndScroll” and “RepositionOnWindowScroll”. The default value is “RepositionOnWindowResizeAndScroll”. Explanation of each values is given below.</p><p align="justify">RepositionOnWindowResize: Will reposition the popup when the window is resized.</p><p align="justify">RepositionOnWindowScroll: Will reposition the popup when the scroll bar is moved.</p><p align="justify">RepositionOnWindowResizeAndScroll: Will reposition the popup when you resize or when you move the scroll bar. Its a combination of both “RepositionOnWindowResize” and “RepositionOnWindowScroll”.</p><p align="justify">None: The popup will not be tinkered with. It will be shown in its original position irrespective of window resizing or scroll bar being moved.</p><p align="justify"><strong>DynamicServicePath: </strong>Link to a webservice/aspx page from where data or content needs to be retrieved and displayed in the popup extender control.</p><p align="justify"><strong>DynamicServiceMethod: </strong>The method name from which content needs to be retrieved. The method can be a webservice method or a method in your code behind file of your aspx file. If you leave the “DynamicServicePath” empty and provide DynamicServiceMethod name then the system will try to ping the same page’ and try to find a method. We will see an e.g. with web service shortly.</p><p align="justify"><strong>DynamicContextKey: </strong>The string value which will be passed as the parameter to the method specified in DynamicServiceMethod. One thing to note here is that the parameter should be named contextKey in the webservice/code behind.</p><p align="justify"><strong>X: </strong>The X coordinates for the popup control.</p><p align="justify"><strong>Y: </strong>The Y coordinates for the popup control.</p><p align="justify"><strong><u>Showing the content of a webservice (asmx) method in a ModalPopupExtender control.</u></strong></p><p align="justify">Showing the output of a web method of a web service in a ModalPopupExtender control is also pretty simple. First you need to have a web service, if you don’t have one its very easy to create one in Visual Studio. Create a web service and add a method the output of which you want to display in a ModalPopupExtender conrol. Below I have pasted the code of my webservice.</p><div style="border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 4px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; overflow-x: auto; overflow-y: auto; border-top-color: silver; border-top-width: 1px; border-top-style: solid; cursor: text; border-right-color: silver; border-right-width: 1px; border-right-style: solid; " id="codeSnippetWrapper"><div style="color: rgb(244, 244, 244); font-size: 8pt; line-height: 12pt; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: monospace; white-space: pre; "><span style="color: #0000ff">using</span> System; </span></div><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; " id="codeSnippet"><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "><span style="color: #0000ff">using</span> System.Collections; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "><span style="color: #0000ff">using</span> System.Linq; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "><span style="color: #0000ff">using</span> System.Web; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "><span style="color: #0000ff">using</span> System.Web.Services; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "><span style="color: #0000ff">using</span> System.Web.Services.Protocols; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "><span style="color: #0000ff">using</span> System.Xml.Linq; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; ">[WebService(Namespace = <span style="color: #006080">"http://tempuri.org/"</span>)] </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "><span style="color: #008000">/*The below attribute is needed so that the webservice can process calls from ASP.NET AJAX controls. Without the below attribute one may get the following error. "Web Service call failed: 500"*/</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; ">[System.Web.Script.Services.ScriptService] </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Service : System.Web.Services.WebService </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; ">{ </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #0000ff">public</span> Service () </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #008000">/*Method which will be called by the ModalPopupExtender control.*/</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> [WebMethod] </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> HelloWorld() </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #0000ff">return</span> <span style="color: #006080">"<b>Hello World</b><br/>"</span>; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; ">}</pre><!--CRLF--></div></div><br />The above webservice is pretty simple. It has only one web method and the most famous of them all, the “HelloWorld” method. The method returns a HTML formatted “Hello World” string.<br />One thing to note while writing a web service whose methods can be called by the ASP.NET Ajax controls is that you need to add the “[System.Web.Script.Services.ScriptService]” attribute. If the before mentioned attribute is not added then you may get the below web service error.<br /><blockquote><p>Web Service call failed: 500</p></blockquote><p align="justify">The mark up for the ModalPopupExtender control to display the webservice’ web method output is pasted below.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; color: #f4f4f4; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid" id="codeSnippetWrapper"><div><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: monospace; white-space: pre; "><!--Web service content display demo--> </span></div><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible" id="codeSnippet"><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><asp:Panel ID=<span style="color: #006080">"webServicePanel"</span> runat=<span style="color: #006080">"server"</span> Width=<span style="color: #006080">"300px"</span> Height=<span style="color: #006080">"300"</span> BackColor=<span style="color: #006080">"Azure"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <asp:Label ID=<span style="color: #006080">"webServiceContentLbl"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Label"</span>></asp:Label> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <asp:Button ID=<span style="color: #006080">"clsBtn"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Button"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"></asp:Panel> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><asp:Button ID=<span style="color: #006080">"webServiceCall"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Click to see the output of a webservice in a popup."</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><cc1:ModalPopupExtender ID=<span style="color: #006080">"ModalPopupExtender1"</span> runat=<span style="color: #006080">"server"</span> TargetControlID=<span style="color: #006080">"webServiceCall"</span> OkControlID=<span style="color: #006080">"clsBtn"</span> DynamicServicePath=<span style="color: #006080">"Service.asmx"</span> DynamicServiceMethod=<span style="color: #006080">"HelloWorld"</span> DynamicControlID=<span style="color: #006080">"webServiceContentLbl"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> BackgroundCssClass=<span style="color: #006080">"backgroundColor"</span> PopupControlID=<span style="color: #006080">"webServicePanel"</span> DropShadow=<span style="color: #006080">"true"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"></cc1:ModalPopupExtender></pre><!--CRLF--></div></div><br />The difference from our previous ModalPopupExtender control is that we have configured some extra properties related to webservice request. They are DynamicServicePath where we have given the url of the web service, DynamicServiceMethod takes the web method name and finally DynamicControlID takes the ID of the control in which the output of the web method should be displayed. We have given the ID of the label control inside the panel control as the DynamicControlID. The label control will display “Hello World” string in bold.<br />The ModalPopupExtender is capable of displaying the output from normal aspx pages as well. To display some content its not compulsory that you need to create a webservice. One can directly show the output of a method in a code behind file in a ModalPopupExtender. Lets see how to do that.<br /><strong><u>Displaying the content of a webpage (aspx) method in a ModalPopupExtender control.</u></strong><br />Below is the code behind file content of the ASPX page. The code is pretty straight forward. It has a static method called HelloWorld which returns the same text as that of the webservice.<br /><br /><div style="border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 4px; line-height: 12pt; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; font-size: 8pt; overflow-x: auto; overflow-y: auto; border-top-color: silver; border-top-width: 1px; border-top-style: solid; cursor: text; border-right-color: silver; border-right-width: 1px; border-right-style: solid; " id="codeSnippetWrapper"><br /><div style="color: rgb(244, 244, 244); "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: monospace; white-space: pre; "><span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> ModalPopup : System.Web.UI.Page </span></div><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; " id="codeSnippet"><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; ">{ </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Page_Load(<span style="color: #0000ff">object</span> sender, EventArgs e) </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #008000">/// <summary> </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #008000">/// Page method which will be called by the modal popup extender control. </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #008000">/// </summary> </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #008000">/// <returns></returns> </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> [System.Web.Services.WebMethod(), System.Web.Script.Services.ScriptMethodAttribute()] </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> HelloWorld() </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> <span style="color: #0000ff">return</span> <span style="color: #006080">"<b>Hello World</b><br/>"</span>; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; "> } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; ">}</pre><!--CRLF--></div></div><br />One thing to keep in mind when you declare a method in an aspx which needs to be accessed by the ModalPopupExtender control or any ASP.NET AJAX control is to apply the following attribute.<br /><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; color: #f4f4f4; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid" id="codeSnippetWrapper"><div><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: monospace; white-space: pre; ">[System.Web.Services.WebMethod(), System.Web.Script.Services.ScriptMethodAttribute()]</span></div></div><p align="justify">In addition to the above method attributes one need to declare the method as a static method. If the method is not declared static then you may not be able to ping from the client side. In the case of web service the method need not be static. Some of the errors which you may face because of not declaring the method static or because of not applying the above attributes are listed below.</p><blockquote><p>1. Web Service call failed: 12030<br />2. Web Service call failed: 500 </p></blockquote><p align="justify">If the above two errors popup you know what to do? First check whether the method attributes are applied and secondly see to it that the method is declared as static in the code behind.</p><p align="justify">Below is the mark up needed to display the content from a method in an aspx page.</p><div style="border-bottom-color: silver; border-bottom-width: 1px; border-bottom-style: solid; text-align: left; border-left-color: silver; border-left-width: 1px; border-left-style: solid; padding-bottom: 4px; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; overflow-x: auto; overflow-y: auto; border-top-color: silver; border-top-width: 1px; border-top-style: solid; cursor: text; border-right-color: silver; border-right-width: 1px; border-right-style: solid; padding-top: 4px; " id="codeSnippetWrapper" color="#f4f4f4" size="8pt" face="'Courier New', courier, monospace"><div style="line-height: 12pt; "><span class="Apple-style-span" style="font-family: monospace; font-size: 11px; white-space: pre; "><!--Web service content display demo--> </span></div><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; " id="codeSnippet" ><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><asp:Panel ID=<span style="color: #006080">"webServicePanel"</span> runat=<span style="color: #006080">"server"</span> Width=<span style="color: #006080">"300px"</span> Height=<span style="color: #006080">"300"</span> BackColor=<span style="color: #006080">"Azure"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <asp:Label ID=<span style="color: #006080">"outputContentLbl"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Label"</span>></asp:Label> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <asp:Button ID=<span style="color: #006080">"clsBtn"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Button"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"></asp:Panel> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><asp:Button ID=<span style="color: #006080">"webServiceCall"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Click to see the output of a webservice in a popup."</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><cc1:ModalPopupExtender ID=<span style="color: #006080">"ModalPopupExtender1"</span> runat=<span style="color: #006080">"server"</span> DynamicServicePath=<span style="color: #006080">"ModalPopup.aspx"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> TargetControlID=<span style="color: #006080">"webServiceCall"</span> OkControlID=<span style="color: #006080">"clsBtn"</span> DynamicServiceMethod=<span style="color: #006080">"HelloWorld"</span> DynamicControlID=<span style="color: #006080">"outputContentLbl"</span> BackgroundCssClass=<span style="color: #006080">"backgroundColor"</span> PopupControlID=<span style="color: #006080">"webServicePanel"</span> DropShadow=<span style="color: #006080">"true"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"></cc1:ModalPopupExtender></pre><!--CRLF--></div></div><br />You can see in the above mark up everything is same except for the webservice related properties, highlighted in Maroon. DynamicServicePath is used to specify the url of the page. If left blank it will refer the same page. DynamicServiceMethod is the method name in the aspx/codebehind which will be pinged by the ModalPopupExtender to retrieve data. DynamicControlID is the ID of the control in which you would like to display the output of the method. DynamicControlID should have the ID of a control inside the ASP.NET Panel control in our case or any control inside whatever container control the user is making use for popup. Also if you have any argument then you can use DynamicContextKey to pass the string argument.<br /><strong><u>Hiding and Showing the ModalPopupExtender control using javascript</u></strong><br />The above e.g. are quite straight forward and easy to implement. Unfortunately a developer’ life is not a bed of roses. There may arise a requirement where one has to call/show/hide the popup control using javascript. So lets see how to do exactly this. Below is the HTML markup.<br /><br /><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper" ><div><span class="Apple-style-span" style="font-family: monospace; font-size: 11px; white-space: pre; "><asp:Button ID=<span style="color: #006080">"popupScriptBtn"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Click to view the modal popup using javascript"</span> OnClientClick=”javascript:showModalPopup();<span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;” /> </span></div><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet" ><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><asp:Button ID=<span style="color: #006080">"popupBtn"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Click to see the modal popup."</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><div ID=<span style="color: #006080">"div1"</span> runat=<span style="color: #006080">"server"</span> > </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <asp:Panel ID=<span style="color: #006080">"Panel1"</span> runat=<span style="color: #006080">"server"</span> Style=<span style="color: #006080">"display: none; padding:10px; border:1px; border-style:solid;"</span> BackColor=<span style="color: #006080">"#FF9933"</span> Width=<span style="color: #006080">"400px"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <table id=<span style="color: #006080">"Table1"</span> style=<span style="color: #006080">"background-color: #C0C0C0; width: 400px; height: 5px;"</span>><tr><td><h3 style=<span style="color: #006080">"text-align: center;"</span> id=<span style="color: #006080">"header"</span>>Modal Popup</h3></td></tr></table> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <p>This <span style="color: #0000ff">is</span> a Modal Popup extender control. You are seeing <span style="color: #0000ff">this</span> because you have clicked the hyperlink button.</p> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <p style=<span style="color: #006080">"text-align: center;"</span>><asp:Button ID=<span style="color: #006080">"closeBtn"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Close"</span> /></p> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> </asp:Panel> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"></div> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><cc1:ModalPopupExtender ID=<span style="color: #006080">"ModalPopupExtender"</span> runat=<span style="color: #006080">"server"</span> TargetControlID=<span style="color: #006080">"popupBtn"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> PopupControlID=<span style="color: #006080">"Panel1"</span> OkControlID=<span style="color: #006080">"closeBtn"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> BackgroundCssClass=<span style="color: #006080">"backgroundColor"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> DropShadow=<span style="color: #006080">"true"</span> PopupDragHandleControlID=<span style="color: #006080">"header"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> CancelControlID=<span style="color: #006080">""</span> Drag=<span style="color: #006080">"true"</span> RepositionMode=<span style="color: #006080">"None"</span> /></pre><!--CRLF--></div></div><p align="justify">Above markup is pretty much same as the one we used at the beginning of the blog. The only difference being we have an extra ASP.NET button, clicking which we will show the ModalPopupExtender control with the help of javascript. In the above markup we have used the “OnClientClick” property to assign the javascript, showModalPopup, which needs to be called when the button is clicked. The javascript to show and hide the popup is pasted below.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; padding-left: 4px; width: 97.5%; padding-right: 4px; direction: ltr; max-height: 500px; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper" ><div><span class="Apple-style-span" style="font-family: monospace; font-size: 11px; white-space: pre; "><script type=<span style="color: #006080">"text/javascript"</span> language=<span style="color: #006080">"javascript"</span>> </span></div><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet" ><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"><span style="color: #008000">//Javascript function to hide the popup control. </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible">function closeModalPopup() </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible">{ </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #008000">//Using the $find javascript method to retrieve the modal popup control. </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> var modalPopup = $find(<span style="color: #006080">'<%=ModalPopupExtender.ClientID %>'</span>); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> <span style="color: #0000ff">if</span> (modalPopup != <span style="color: #0000ff">null</span>) </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> modalPopup.hide(); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible"> } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible">} </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" ><span style="color: #008000">//Javascript function to show the ModalPopupExtender control. </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible">function showModalPopup() </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" >{ </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <span style="color: #008000">//Using the $find javascript method to retrieve the modal popup control. </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > var modalPopup = $find(<span style="color: #006080">'<%=ModalPopupExtender.ClientID %>'</span>); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <span style="color: #0000ff">if</span> (modalPopup != <span style="color: #0000ff">null</span>) </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > modalPopup.show(); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" >} </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" ></script></pre><!--CRLF--></div></div><br />In the above javascript we have two functions. One to show the ModalPopupExtender control and another to hide the control. In both the function we are using $find shortcut method to retrieve the popup control. To know more about $find method please see this <a href="http://sandblogaspnet.blogspot.com/2009/06/difference-between-get-and-find.html" target="_blank">link</a>. Once we have retrieved the modal popup control we are calling the show and hide methods of the control to show and hide the control respectively.<br /><strong><u>Using the modal popup control within a GridView control</u></strong><br /><br /><p align="justify">There is nothing different here. In a grid if you want to link the ModalPopupExtender to a control inside the GridView you need to just convert the column into a template column and add the ModalPopupExtender control to the column and configure the necessary properties as discussed. Below is a sample code where I have added the ModalPopupExtender control in the header section as well in a column of GridView control.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><br /><div> </div><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" ><asp:GridView ID=<span style="color: #006080">"backIssueGrid"</span> runat=<span style="color: #006080">"server"</span> AutoGenerateColumns=<span style="color: #006080">"False"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > DataMember=<span style="color: #006080">"issue"</span> DataSourceID=<span style="color: #006080">"backIssuesXML"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <RowStyle BorderColor=<span style="color: #006080">"Tan"</span> BorderStyle=<span style="color: #006080">"Solid"</span> BorderWidth=<span style="color: #006080">"1px"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <Columns> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <asp:TemplateField HeaderText=<span style="color: #006080">"Back Issues"</span> HeaderStyle-CssClass=<span style="color: #006080">"headerText"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <ItemTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <asp:HyperLink ID=<span style="color: #006080">"title"</span> runat=<span style="color: #006080">"server"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > Text=<span style="color: #006080">'<%# XPath("@title") %>'</span> CssClass=<span style="color: #006080">"gridText"</span> NavigateUrl=<span style="color: #006080">'<%# XPath("url") %>'</span>></asp:HyperLink> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <asp:Panel ID=<span style="color: #006080">"webServicePanel"</span> runat=<span style="color: #006080">"server"</span> Width=<span style="color: #006080">"300px"</span> Height=<span style="color: #006080">"300"</span> BackColor=<span style="color: #006080">"Azure"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <asp:Label ID=<span style="color: #006080">"outputContentLbl"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Label"</span>></asp:Label> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <asp:Button ID=<span style="color: #006080">"clsBtn"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Button"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > </asp:Panel> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <cc1:ModalPopupExtender ID=<span style="color: #006080">"ModalPopupExtender1"</span> runat=<span style="color: #006080">"server"</span> DynamicServicePath=<span style="color: #006080">"ModalPopup.aspx"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > TargetControlID=<span style="color: #006080">"title"</span> OkControlID=<span style="color: #006080">"clsBtn"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > DynamicServiceMethod=<span style="color: #006080">"HelloWorld"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > DynamicControlID=<span style="color: #006080">"outputContentLbl"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > BackgroundCssClass=<span style="color: #006080">"backgroundColor"</span> PopupControlID=<span style="color: #006080">"webServicePanel"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > DropShadow=<span style="color: #006080">"true"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > </cc1:ModalPopupExtender> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > </ItemTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <HeaderStyle CssClass=<span style="color: #006080">"headerText"</span>></HeaderStyle> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <ItemStyle BorderColor=<span style="color: #006080">"Tan"</span> BorderStyle=<span style="color: #006080">"Solid"</span> BorderWidth=<span style="color: #006080">"1px"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > </asp:TemplateField> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> <asp:TemplateField HeaderStyle-CssClass=<span style="color: #006080">"headerText"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <ItemTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> <asp:TextBox ID=<span style="color: #006080">"quantityTxt"</span> Width=<span style="color: #006080">"30"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">'<%#XPath("@noOfCopies") %>'</span> CssClass=<span style="color: #006080">"gridText"</span>></asp:TextBox> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > </ItemTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> <ItemStyle BorderColor=<span style="color: #006080">"Tan"</span> HorizontalAlign=<span style="color: #006080">"Center"</span> BorderStyle=<span style="color: #006080">"Solid"</span> BorderWidth=<span style="color: #006080">"1px"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <HeaderStyle CssClass=<span style="color: #006080">"headerText"</span>></HeaderStyle> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> <HeaderTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" > <asp:ImageButton ID=<span style="color: #006080">"ImageButton1"</span> runat=<span style="color: #006080">"server"</span> ImageUrl=<span style="color: #006080">"some.gif"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> <asp:Panel ID=<span style="color: #006080">"webServicePanel2"</span> runat=<span style="color: #006080">"server"</span> Width=<span style="color: #006080">"300px"</span> Height=<span style="color: #006080">"300"</span> BackColor=<span style="color: #006080">"Azure"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> <asp:Label ID=<span style="color: #006080">"outputContentLbl1"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Label"</span>></asp:Label> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> <asp:Button ID=<span style="color: #006080">"clsBtn"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Button"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> </asp:Panel> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> <cc1:ModalPopupExtender ID=<span style="color: #006080">"ModalPopupExtender2"</span> runat=<span style="color: #006080">"server"</span> DynamicServicePath=<span style="color: #006080">"ModalPopup.aspx"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> TargetControlID=<span style="color: #006080">"ImageButton1"</span> OkControlID=<span style="color: #006080">"clsBtn"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> DynamicServiceMethod=<span style="color: #006080">"HelloWorld"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> DynamicControlID=<span style="color: #006080">"outputContentLbl1"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> BackgroundCssClass=<span style="color: #006080">"backgroundColor"</span> PopupControlID=<span style="color: #006080">"webServicePanel2"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> DropShadow=<span style="color: #006080">"true"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> </cc1:ModalPopupExtender> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> </HeaderTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </asp:TemplateField> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> <asp:TemplateField> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <ItemTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> <asp:Label ID=<span style="color: #006080">"Label4"</span> CssClass=<span style="color: #006080">"gridText"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">'<%# Add(XPath("@noOfCopies"), XPath("@price"))%>'</span>></asp:Label> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </ItemTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> </asp:TemplateField> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:CommandField ShowSelectButton=<span style="color: #006080">"True"</span> ButtonType=<span style="color: #006080">"Button"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; direction: ltr; border-top-style: none; border-left-style: none; overflow: visible; padding-top: 0px" color="black" size="8pt" face="'Courier New', courier, monospace"> SelectText=<span style="color: #006080">"Remove"</span> ControlStyle-CssClass=<span style="color: #006080">"buttonText"</span> > </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <ControlStyle CssClass=<span style="color: #006080">"buttonText"</span>></ControlStyle> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <ItemStyle BorderColor=<span style="color: #006080">"Tan"</span> BorderStyle=<span style="color: #006080">"Solid"</span> BorderWidth=<span style="color: #006080">"1px"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </asp:CommandField> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </Columns> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <EditRowStyle BorderStyle=<span style="color: #006080">"Solid"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </asp:GridView></pre><!--CRLF--></div></div><p align="justify">In the above e.g. you can see the markups highlighted in green. In the first portion I have place a popup control in the “ItemTemplate” and hooked the ModalPopupExtender control to a hyperlink control. Pretty simple, isn’t it? In the second section I have put the popup control in the HeaderTemplate of the column and hooked it to a ImageButton. So when one clicks on the image button in the header he will see a popup. If you want you can add javascript “onmouseover” and “onmouseout” behavior to the image in the code behind by adding attributes to the ImageButton control.</p><p align="justify">In my case I had to show help text whenever the user clicks the header text so instead of adding ModalPopupExtender control to each and every HeaderTemplate what I did is added the ModalPopupExtender control somewhere in the aspx page and hooked it to a hidden control and on click of the header, used javascript to display the popup control. The reason why I took this approach is that if I put the ModalPoupExtender in each column’ header template, it will generate as many popup extenders as the number of columns. My popup control needs to display help text and these help text were retrieved from a method in the code behind/webservice. So I used a javascript function and passed parameters necessary to retrieve the help text. Also people who have similar kind of requirement where for e.g. you have a column and you need to show some help text or some detailed information based on some parameters you can also follow the same approach. The approach will reduce the amount of html being generated. With this approach I wanted to highlight the subtle feature of ModalPopupExtender control where one can hook up the control to a hidden control and use javascript to show the control. This method can be very useful for controls to which ModalPopupExtender cannot be attached. I think thats enough, lets see the code in action.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><div><span class="Apple-style-span" style="white-space: pre; "><asp:GridView ID=<span style="color: #006080">"backIssueGrid"</span> runat=<span style="color: #006080">"server"</span> </span></div><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">AutoGenerateColumns=<span style="color: #006080">"False"</span> DataMember=<span style="color: #006080">"issue"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">DataSourceID=<span style="color: #006080">"backIssuesXML"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <RowStyle BorderColor=<span style="color: #006080">"Tan"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">BorderStyle=<span style="color: #006080">"Solid"</span> BorderWidth=<span style="color: #006080">"1px"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <Columns> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:TemplateField </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">HeaderStyle-CssClass=<span style="color: #006080">"headerText"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <HeaderTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:HyperLink ID=<span style="color: #006080">"title"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Name"</span> CssClass=<span style="color: #006080">"gridText"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">NavigateUrl=<span style="color: #006080">'javascript:showModalPopup("helpOne" </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">);'></asp:HyperLink> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </HeaderTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <ItemTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:HyperLink ID=<span style="color: #006080">"title"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">'<%# XPath("@title") %>'</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">CssClass=<span style="color: #006080">"gridText"</span> NavigateUrl=<span style="color: #006080">'<%# </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">XPath("url") %>'></asp:HyperLink> </ItemTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <HeaderStyle </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">CssClass=<span style="color: #006080">"headerText"</span>></HeaderStyle> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <ItemStyle BorderColor=<span style="color: #006080">"Tan"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">BorderStyle=<span style="color: #006080">"Solid"</span> BorderWidth=<span style="color: #006080">"1px"</span> /> </asp:TemplateField> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:TemplateField </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">HeaderStyle-CssClass=<span style="color: #006080">"headerText"</span>> <ItemTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:TextBox </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">ID=<span style="color: #006080">"quantityTxt"</span> Width=<span style="color: #006080">"30"</span> runat=<span style="color: #006080">"server"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Text=<span style="color: #006080">'<%#XPath("@noOfCopies") %>'</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">CssClass=<span style="color: #006080">"gridText"</span>></asp:TextBox> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </ItemTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <ItemStyle BorderColor=<span style="color: #006080">"Tan"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">HorizontalAlign=<span style="color: #006080">"Center"</span> BorderStyle=<span style="color: #006080">"Solid"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">BorderWidth=<span style="color: #006080">"1px"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <HeaderStyle </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">CssClass=<span style="color: #006080">"headerText"</span>></HeaderStyle> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <HeaderTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:HyperLink ID=<span style="color: #006080">"title"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Address"</span> CssClass=<span style="color: #006080">"gridText"</span> NavigateUrl=<span style="color: #006080">'javascript:showModalPopup("helpTwo" </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">);'></asp:HyperLink> </HeaderTemplate> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </asp:TemplateField> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:CommandField </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">ShowSelectButton=<span style="color: #006080">"True"</span> ButtonType=<span style="color: #006080">"Button"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">SelectText=<span style="color: #006080">"Remove"</span> ControlStyle-CssClass=<span style="color: #006080">"buttonText"</span> > </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <ControlStyle </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">CssClass=<span style="color: #006080">"buttonText"</span>></ControlStyle> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <ItemStyle BorderColor=<span style="color: #006080">"Tan"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">BorderStyle=<span style="color: #006080">"Solid"</span> BorderWidth=<span style="color: #006080">"1px"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </asp:CommandField> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </Columns> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"></asp:GridView> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><asp:XmlDataSource ID=<span style="color: #006080">"backIssuesXML"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">runat=<span style="color: #006080">"server"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">DataFile=<span style="color: #006080">"~/Data/BackIssue.xml"</span>></asp:XmlDataSou </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">rce> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><asp:HyperLink ID=<span style="color: #006080">"title"</span> runat=<span style="color: #006080">"server"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Style=<span style="color: #006080">"display:none;"</span>> </asp:HyperLink> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:Panel ID=<span style="color: #006080">"webServicePanel"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">runat=<span style="color: #006080">"server"</span> Width=<span style="color: #006080">"300px"</span> Height=<span style="color: #006080">"300"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">BackColor=<span style="color: #006080">"Azure"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:Label ID=<span style="color: #006080">"outputContentLbl"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Label"</span>></asp:Label> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <asp:Button ID=<span style="color: #006080">"clsBtn"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">"Button"</span> /> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </asp:Panel> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><cc1:ModalPopupExtender ID=<span style="color: #006080">"ModalPopupExtender1"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">runat=<span style="color: #006080">"server"</span> DynamicServicePath=<span style="color: #006080">"ModalPopup.aspx"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">TargetControlID=<span style="color: #006080">"title"</span> OkControlID=<span style="color: #006080">"clsBtn"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">DynamicServiceMethod=<span style="color: #006080">"HelloWorld"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">DynamicControlID=<span style="color: #006080">"outputContentLbl"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">BackgroundCssClass=<span style="color: #006080">"backgroundColor"</span> PopupControlID=<span style="color: #006080">"webServicePanel"</span> DropShadow=<span style="color: #006080">"true"</span>> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"></cc1:ModalPopupExtender></pre><!--CRLF--></div></div><p align="justify">The above code has ASP.NET hyper link controls in the header template which calls a javascript function using its NavigateUrl property and passes a string value to the javascript function based on which the help text is retrieved. Also as you can see we have a ModalPopupExtender control outside of GridView. A javascript function is used to show the popup control when you click the hyper link controls inside the header template of the gridview. Also note the hyper link control outside the GridView which has its style set to “None” so that the control becomes invisible. The javascript which is executed on clicking the hyper link controls inside the GridView is pasted below.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><div><span class="Apple-style-span" style="color: rgb(0, 128, 0); white-space: pre; ">//Javascript function to show the ModalPopupExtender control. </span></div><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; " id="codeSnippet"><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; ">function showModalPopup(helpId) </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; ">{ </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; "> var modalPopup = $find(<span style="color: #006080">'<%=ModalPopupExtender1.ClientID %>'</span>); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; "> <span style="color: #0000ff">if</span> (modalPopup != <span style="color: #0000ff">null</span>) </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; "> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; "> modalPopup._DynamicContextKey = helpId; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; "> modalPopup.show(); </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; "> } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: rgb(244, 244, 244); margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow-x: visible; overflow-y: visible; padding-top: 0px; ">}</pre><!--CRLF--></div></div><p align="justify">In the above javascript we are setting the “_DynamicContextKey” with the help of the method argument. The argument is passed by the hyper link controls in the header template of the GridView. DynamicContextKey are nothing but the string arguments to be passed to webservice/webpage method. So by varying the DynamicContextKey we can get different messages to be displayed in the ModalPopupExtender control.</p><p align="justify">The code behind method which is called by the ModalPopupExtender control is pasted below.</p><div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 500px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><div><span class="Apple-style-span" style="white-space: pre; ">[System.Web.Services.WebMethod(), System.Web.Script.Services.ScriptMethodAttribute()] </span></div><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> HelloWorld(<span style="color: #0000ff">string</span> contextKey) </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">return</span> <span style="color: #006080">"<b>Hello World</b><br/>"</span> + contextKey; </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--></div></div><p align="justify">So that’ about working with ModalPopupExtender control. Below are some of the important javascript properties and methods of ModalPopupExtender control.</p><table border="1" bordercolor="#000000" bordercolorlight="#ffffff" bordercolordark="#ffffff" width="622" bgcolor="#ffffff"><tbody></tbody><tbody><tr><td width="168"><strong>Method/Properties</strong></td><td width="452"><strong>Description</strong></td></tr><tr><td valign="top" width="168">_DynamicControlID</td><td width="452"><p align="justify">Using this property you can set/retrieve the ID for the dynamic control i.e. the control which will show the output of the method being pinged by the modal popup extender control.</p></td></tr><tr><td valign="top" width="168">_DynamicContextKey</td><td width="452">Property to set/retrieve the string parameter for the function which will be called by the ModalPopupExtender control.</td></tr><tr><td valign="top" width="168">_DynamicServicePath</td><td width="452"><p align="justify">Property to set/retrieve the path for the webservice/webpage.</p></td></tr><tr><td valign="top" width="168">_DynamicServiceMethod</td><td width="452"><p align="justify">Property to set/retrieve the method which needs to be invoked or pinged to retrieve the output.</p></td></tr><tr><td valign="top" width="168">_PopupControlID</td><td width="452"><p align="justify">The property can be used to set/retrieve the ID of the control which will be shown as the popup. Normally it will be the ID of the ASP.NET panel control.</p></td></tr><tr><td valign="top" width="168">_PopupDragHandleControlID</td><td width="452"><p align="justify">The ID of the control clicking on which the popup control can be dragged. </p></td></tr><tr><td valign="top" width="168">_BackgroundCssClass</td><td width="452"><p align="justify">CSS class name for the background of the popup can be set/retrieved using this javascript property.</p></td></tr><tr><td valign="top" width="168">_DropShadow</td><td width="452"><p align="justify">Boolean value which can be set/retrieved to enable drop shadow. A value of “true” means drop shadow is enabled, false means it is disabled.</p></td></tr><tr><td valign="top" width="168">_Drag</td><td width="452"><p align="justify">Property to set/retrieve the drag facility. If you want to enable set it as true.</p></td></tr><tr><td valign="top" width="168">_OkControlID</td><td width="452"><p align="justify">This property can be used to set/retrieve the “Ok” button. </p></td></tr><tr><td valign="top" width="168">_CancelControlID</td><td width="452"><p align="justify">Property to set/retrieve the “Cancel” button id.</p></td></tr><tr><td valign="top" width="168">_OnOkScript</td><td width="452"><p align="justify">Property to set/retrieve the script which needs to fired when “Ok” button inside the popup is clicked.</p></td></tr><tr><td valign="top" width="168">_OnCancelScript</td><td width="452"><p align="justify">Property to set/retrieve the script which needs to fired when “Cancel” button inside the popup is clicked.</p></td></tr><tr><td valign="top" width="168">_xCoordinate</td><td width="452"><p align="justify">Property to set/retrieve the X coordinates of the popup control.</p></td></tr><tr><td valign="top" width="168">_yCoordinate</td><td width="452"><p align="justify">Property to set/retrieve the Y coordinates of the popup control.</p></td></tr><tr><td valign="top" width="168">_repositionMode</td><td width="452"><p align="justify">Property to set/retrieve the Reposition mode. Reposition mode has been discussed somewhere else in this document. The property accepts integer as its value. The various values and their corresponding reposition mode are as follows. 0 means “None”, 1 means “RepositionOnWindowResize”, 2 means “RepositionOnWindowScroll” and finally 3 means<br />“RepositionOnWindowResizeAndScroll”. Each of this mode is discussed above.</p></td></tr><tr><td valign="top" width="168">_id</td><td width="452"><p align="justify">One can set/retrieve the ID of the ModalPopupExtender control.</p></td></tr></tbody></table><p align="justify">So that’ about our disussion on ModalPopupExtender control.</p><br /><p align="justify">Try to know more,</p><p align="justify">Sandeep</p>Sandeephttp://www.blogger.com/profile/17475854334307316616noreply@blogger.com201