Tips & Trickshttp://forums.asp.net/53.aspx/1?Tips+TricksCool code and exciting examples, provided by our members.Fri, 17 May 2013 07:19:05 -0400urn:uuid:00000000-0000-0000-0000-000000000053urn:uuid:00000000-0000-0000-0000-000005396927http://forums.asp.net/p/1906740/5396927.aspx/1?ASP+NET+Cookies+OverviewASP.NET Cookies Overview <p><span>A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site.</span></p> <ul> <li> <p><a href="http://msdn.microsoft.com/en-us/library/ms178194.aspx#Scenarios">Scenarios</a></p> </li><li> <p><a href="http://msdn.microsoft.com/en-us/library/ms178194.aspx#Background">Background</a></p> </li><li> <p><a href="http://msdn.microsoft.com/en-us/library/ms178194.aspx#CodeExamples">Code Examples</a></p> </li><li> <p><a href="http://msdn.microsoft.com/en-us/library/ms178194.aspx#ClassReference">Class Reference</a></p> </li><li> <p><a href="http://msdn.microsoft.com/en-us/library/ms178194.aspx#AdditionalResources">Additional Resources</a></p> </li><li> <p><a href="http://msdn.microsoft.com/en-us/library/ms178194.aspx#WhatsNew">What's New</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/ms178194.aspx">http://msdn.microsoft.com/en-us/library/ms178194.aspx</a></p> </li></ul> <p><span><br> </span></p> 2013-05-17T11:19:05-04:002013-05-17T11:19:05.577-04:00urn:uuid:00000000-0000-0000-0000-000005394819http://forums.asp.net/p/1906240/5394819.aspx/1?Interesting+about+Asp+Net+MVCInteresting about Asp.Net MVC <p><span size="3" style="font-size:medium">As we all know that&nbsp;<b>MVC</b>&nbsp;has been a life-saver for Asp.Net , giving the power to do more . Now solution to</span></p> <p>&nbsp;<span>a complex application has been made easier due to the available MVC semantics. I am already amazed about</span></p> <p>&nbsp;<span>the following features which MVC provides :</span></p> <ul> <li><span>Test driven development (TDD)</span> </li><li><span>Routing Infrastructure</span> </li><li><span>Loosely coupled architecture</span> </li><li><span>Code Re-usability</span> </li><li><span>No Viewstate</span> </li><li><span>Full control over rendered HTML</span> </li><li><span>Enhanced support for dependency injection providing resilience to app.</span> </li><li><span>Support for javascript &amp; ouptout caching<br> </span></li></ul> <p><span></span><span>So let's focus on some of the other revolutionary facets which has made development tasks simple .</span></p> <p></p> <p><span></span><span>First let's talk about&nbsp;</span><b>MVC jQuery validation</b><span>&nbsp;which is done on the front end (client side), without submitting</span></p> <p><span size="3" style="font-size:medium">data to the controller (Server side). So it can save you some bandwidth/processing. If you have a slow or</span></p> <p><span size="3" style="font-size:medium">overloaded server, users will get a quicker response to validation errors this way as well. Server side validation is</span></p> <p><span size="3" style="font-size:medium">essential/required since it makes sure you are getting good data before you save it. The client side is nice to</span></p> <p><span size="3" style="font-size:medium">have, but shouldn't be all you have since its possible to bypass. For jquery validation add the scripts</span></p> <p><span size="3" style="font-size:medium">&quot;<b>jquery.validate.min.js</b>&quot; &amp; &quot;<b>jquery.validate.unobtrusive.min.js</b>&quot; to your view .</span></p> <p><span size="3" style="font-size:medium">Also add the following in App-Settings of web-config :</span></p> <ul> <li><span size="3" style="font-size:medium"><b>&lt;add key=&quot;ClientValidationEnabled&quot; value=&quot;true&quot;/&gt;</b></span> </li><li><span size="3" style="font-size:medium"><b>&lt;add key=&quot;UnobtrusiveJavaScriptEnabled&quot; value=&quot;true&quot;/&gt;</b></span> </li></ul> <p><span size="3" style="font-size:medium"><span></span>We even have&nbsp;<b>Remote Validation</b>&nbsp;which fires for the custom validation logic developed, so when client</span></p> <p><span size="3" style="font-size:medium">presses submit button it shows the error fabricated . For eg : We set the remote attribute in model for property</span>&nbsp;</p> <p><span size="3" style="font-size:medium">[<b>Remote</b>(&quot;<b>RegisterClientUser</b>&quot;, &quot;<b>Registration</b>&quot;, ErrorMessage = &quot;User name is already taken!&quot;)]</span></p> <p><span size="3" style="font-size:medium">public String UserName { get; set; }</span></p> <p><span size="3" style="font-size:medium"><span></span>Then we declare it's respective action in controller .</span></p> <p><span size="3" style="font-size:medium">public class&nbsp;<b>RegistrationController</b>&nbsp;: Controller</span></p> <p><span size="3" style="font-size:medium">{</span></p> <p><span size="3" style="font-size:medium"><span></span>// GET: /Registration/</span></p> <p><span size="3" style="font-size:medium"><span></span>private UserEntities userDB;</span></p> <p><span size="3" style="font-size:medium"><span></span>public RegistrationController()</span></p> <p><span size="3" style="font-size:medium"><span></span>{</span></p> <p><span size="3" style="font-size:medium"><span></span>userDB = new UserEntities();</span></p> <p><span size="3" style="font-size:medium"><span></span>}</span></p> <p><span size="3" style="font-size:medium"><span></span>public ViewResult RegisterClientUser()</span></p> <p><span size="3" style="font-size:medium"><span></span>{</span></p> <p><span size="3" style="font-size:medium"><span></span>return View(new UserModel());</span></p> <p><span size="3" style="font-size:medium"><span></span>}</span></p> <p><span size="3" style="font-size:medium"><span></span>[HttpPost]</span></p> <p><span size="3" style="font-size:medium"><span></span>public ActionResult&nbsp;<b>RegisterClientUser</b>(UserModel um)</span></p> <p><span size="3" style="font-size:medium"><span></span>{</span></p> <p><span size="3" style="font-size:medium"><span></span>try</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>{</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>clientuser user = new clientuser();</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>return Json(!um.UserName.Equals(userDB.clientuser.Find(um.UserName))</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>, JsonRequestBehavior.AllowGet);</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>if (ModelState.IsValid)</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>{</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>// your code</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>}</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>return RedirectToAction(&quot;Index&quot;, &quot;Home&quot;);</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>}</span></p> <p><span size="3" style="font-size:medium"><span></span>catch</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>{</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>ViewBag.updateError = &quot;Unable to register&quot;;</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>return View(um);</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>}</span></p> <p><span size="3" style="font-size:medium"><span></span>}</span></p> <p><span size="3" style="font-size:medium">}</span></p> <p><span size="3" style="font-size:medium"><span></span>Next I would like to speak about is&nbsp;<b>Adaptive Rendering</b>&nbsp;which allows your website is aware of the</span>&nbsp;</p> <p><span size="3" style="font-size:medium">browser’s proportions and corresponds to them, so it can present its content as user-friendly as possible.That</span></p> <p><span size="3" style="font-size:medium">means even if you resize , the content is clipped. The meta-tag &quot;Viewport &quot; is helpful indeed. For eg:</span></p> <p><span size="3" style="font-size:medium">Appending&nbsp;<b>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;/&gt;</b>&nbsp;would help us scale the complete</span></p> <p><span size="3" style="font-size:medium">page properly even on mobile.</span></p> <p><span size="3" style="font-size:medium"><span></span>Then we have&nbsp;<b>Bundling and Minification</b>&nbsp;which are more useful in production than in development as</span></p> <p><span size="3" style="font-size:medium">well can significantly improve your first page hit download time.</span></p> <p><span size="3" style="font-size:medium"></span><b><span></span>Bundling</b><span>&nbsp;reduces the number of individual HTTP requests to server by combining multiple CSS files</span><span>and Javascript files into single CSS file and javascript file. We have to register bundles function in<span>&nbsp;</span>Application_Start() of Global Asax . Now to bundle js scripts together as one we add them into 1 bundle.</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span><b>bundles.Add(new ScriptBundle(&quot;~/bundles/jqueryval&quot;).Include(</b></span></p> <p><span size="3" style="font-size:medium"><b><span><span></span></span>&quot;~/Scripts/jquery.unobtrusive*&quot;,</b></span></p> <p><span size="3" style="font-size:medium"><b><span><span></span></span>&quot;~/Scripts/jquery.validate*&quot;));</b></span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>Similarly we do for stylesheets as follows</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span><b>bundles.Add(newStyleBundle(&quot;~/Content/Styles/css&quot;).Include(</b></span></p> <p><span size="3" style="font-size:medium"><b><span></span>&quot;~/Content/Styles/css/style</b></span><b>.css&quot;));</b></p> <p><b><span></span>Minification</b><span>&nbsp;reduces the file download size of CSS and javascript files by removing whitespace,&nbsp;comments and other unnecessary characters. Here we have to zip or minify the css &amp; js files in order to<span>&nbsp;</span>reduce load.</span></p> <p><span size="3" style="font-size:medium"><span><span></span></span>For eg: we can use&nbsp;<b>gzip</b>&nbsp;to minify the files so &quot;smaller files, less kb on the wire, faster page load&quot;.</span></p> <p></p> <p><span size="3" style="font-size:medium"><span></span>Hope I could do justice to this blog by providing you all adequate detail on the above mentioned features of</span></p> <p><span size="3" style="font-size:medium">MVC . I would even be posting more on my development experiences &amp; issues faced periodically . In the</span></p> <p><span size="3" style="font-size:medium">meanwhile if you get stuck @ any phase in development, you guys can mail me so that I can help you .</span></p> <p><span size="3" style="font-size:medium">So STAY&nbsp;</span><span>TUNED !&nbsp;<img alt=";)" src="http://static.websimages.com/JS/Punymce/plugins/emoticons/img/wink.gif"></span></p> <p></p> <p>Find More tutorials and articles <a href="http://shalinjirawla.webs.com/" title="Shalin Jirawla" target="_blank"> here</a></p> <p><span size="3" style="font-size:medium">Regards,</span></p> <p><span size="3" style="font-size:medium">Shalin Jirawla</span></p> <p><span size="3" style="font-size:medium">shalinitengg10@gmail.com</span></p> 2013-05-15T13:33:08-04:002013-05-15T13:33:08.15-04:00urn:uuid:00000000-0000-0000-0000-000005376599http://forums.asp.net/p/1902024/5376599.aspx/1?How+to+Add+Remove+DataRow+from+DataTable+in+MemoryHow to Add/Remove DataRow from DataTable in Memory <p>I thought I would post this as I spent several days getting it to work. All the posts I found were incomplete in one way or another.</p> <p>I welcome any comments on improving its efficiency.</p> <p>First add your DataTable variable to you&nbsp;class, but outside of any method</p> <pre class="prettyprint">public partial class YourClassName: System.Web.UI.UserControl { DataTable dt; }</pre> <p>Next add this to Page_Load</p> <pre class="prettyprint">protected void Page_Load(object sender, EventArgs e) { if (GridView1.Rows.Count == 0) { // Create new DataTable instance dt = new DataTable("YourTableName"); // Add columns to new DataTable dt.Columns.Add(new DataColumn("Column_Name_1", Type.GetType("System.Int32"))); dt.Columns.Add(new DataColumn("Column_Name_2", Type.GetType("System.String"))); // Add the new DataTable to Session // I add this to session before adding a ghost row because when real data is added, it will not be needed. // The ghost row is used so that GridView will show the FooterTemplate when no data is actually present. Session.Add("YourTableName", dt); // Create a DataRow for the new DataTable DataRow dr = dt.NewRow(); // Add data to the new DataRows' 2 columns. // This is a ghost row (that will be hidden on RowDataBound), so the GridView will show the FooterTemplate dr[0] = Convert.ToInt32("0"); dr[2] = null; // Add new DataRow to the DataTable dt.Rows.Add(dr); // Bind DataTable to GridView GridView1.DataSource = dt; GridView1.DataBind(); } }</pre> <p>Your GridView should now show you only the HeaderTemplate and FooterTemplate,</p> <p></p> <p>This last part adds or removes values on the RowCommand event</p> <pre class="prettyprint">protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int Column_1_Value; string Column_2_Value = string.Empty; DataRow dr; switch (e.CommandName) { case "Add": Column_1_Value = ((TextBox)((GridView)sender).FooterRow.FindControl("TextBox1")).Text Column_2_Value = ((TextBox)((GridView)sender).FooterRow.FindControl("TextBox2")).Text // Get the DataTable from Session dt = (DataTable)Session["YourTableName"]; // Create a new DataRow dr = dt.NewRow(); dr[0] = Convert.ToInt32(Column_1_Value); dr[1] = Column_2_Value; // Add DataRow to DataTable dt.Rows.Add(dr); // Clear out old DataTable from Session // (not sure if this is needed as I dont know if just adding it back will overwrite or update exisiting Session value) Session.Remove("YourTableName"); // Add DataTable to Session Session.Add("YourTableName", dt); // Bind DataTable to GridView GridView2.DataSource = dt; GridView2.DataBind(); break; case "Remove": GridViewRow gvr = (GridViewRow)(((Button)e.CommandSource).NamingContainer); Column_1_Value = ((Label)gvr.FindControl("Label1")).Text; Column_2_Value = ((Label)gvr.FindControl("Label2")).Text; // Get the DataTable from Session dt = (DataTable)Session["YourTableName"]; // Set what DataRow in the DataTable will be removed dr = dt.Rows[gvr.RowIndex]; // Remove DataRow dt.Rows.Remove(dr); // Clear out old DataTable from Session Session.Remove("YourTableName"); // Add DataTable to Session Session.Add("YourTableName", dt); // Bind DataTable to GridView GridView2.DataSource = dt; GridView2.DataBind(); break; } }</pre> <p></p> <p>I hope is makes sense to anyone that has been trying to slay this dragon.</p> <p>Hope I can save you some time.</p> 2013-04-26T19:52:43-04:002013-04-26T19:52:43.74-04:00urn:uuid:00000000-0000-0000-0000-000005118955http://forums.asp.net/p/1836657/5118955.aspx/1?Http+Web+Request+Helper+ClassHttp Web Request Helper Class <p><span>Hi Every one,</span></p> <p><span>I just wana share this class with MVC developers that can really help them with posting and getting the contents from other sites, same like the form post/get. Before we have implemented this class it was a nightmare to post data from code/service classes either it is the text or the xml to external sites and same when we want to get the response from web service or any external web page.</span></p> <p><span>You can add this class in your project and can call the static methods from anywhere service classes, views or controller.</span></p> <pre class="prettyprint">public static class HttpWebRequestHelper { private static string FormContentType = &quot;application/x-www-form-urlencoded&quot;; private static string XMLContentType = &quot;text/xml&quot;; private static string POST = &quot;POST&quot;; private static string FormatPostParameters(NameValueCollection nameValueCollection) { StringBuilder sb = new StringBuilder(); foreach (string key in nameValueCollection) { sb.Append(key &#43; &quot;=&quot; &#43; HttpUtility.UrlEncode(nameValueCollection[key]) &#43; &quot;&amp;&quot;); } sb.Length = sb.Length - 1; return sb.ToString(); } private static string FormatPostParameters(Dictionary&lt;string,string&gt; parameters) { StringBuilder sb = new StringBuilder(); foreach (string key in parameters.Keys) { sb.Append(HttpUtility.UrlEncode(key) &#43; &quot;=&quot; &#43; HttpUtility.UrlEncode(parameters[key]) &#43; &quot;&amp;&quot;); } sb.Length = sb.Length - 1; return sb.ToString(); } public static HttpWebResponse SendFormPostRequest(string url, Dictionary&lt;string,string&gt; parameters) { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.ContentType = FormContentType; httpWebRequest.Method = POST; string postData = FormatPostParameters(parameters); byte[] requestBytes = Encoding.UTF8.GetBytes(postData); httpWebRequest.ContentLength = requestBytes.Length; using (Stream requestStream = httpWebRequest.GetRequestStream()) { requestStream.Write(requestBytes, 0, requestBytes.Length); requestStream.Close(); } Task&lt;WebResponse&gt; responseTask = Task.Factory.FromAsync&lt;WebResponse&gt;(httpWebRequest.BeginGetResponse, httpWeb Request.EndGetResponse, null); return (HttpWebResponse)responseTask.Result; } public static HttpWebResponse SendNonFormPostRequest(string data, string url) { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.ContentType = XMLContentType; httpWebRequest.Method = POST; httpWebRequest.KeepAlive = false; httpWebRequest.Timeout = 500000; StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream()); sw.WriteLine(data); sw.Close(); Task&lt;WebResponse&gt; responseTask = Task.Factory.FromAsync&lt;WebResponse&gt;(httpWebRequest.BeginGetResponse, httpWeb Request.EndGetResponse, null); return (HttpWebResponse)responseTask.Result; } public static string GetHttpWebResponseData(HttpWebResponse response) { string data = string.Empty; if (response != null) { StreamReader incomingStreamReader = new StreamReader(response.GetResponseStream()); data = incomingStreamReader.ReadToEnd(); incomingStreamReader.Close(); response.GetResponseStream().Close(); } return data; } }</pre> 2012-08-23T19:48:32-04:002012-08-23T19:48:32.613-04:00urn:uuid:00000000-0000-0000-0000-000004130725http://forums.asp.net/p/1614340/4130725.aspx/1?TreeView+Collapse+All+Nodes+Except+SelectedNode+s+Parent+NodesTreeView - Collapse All Nodes Except SelectedNode's Parent Nodes <p><b>Control Markup</b></p> <pre class="prettyprint">protected void tv_Menu_DataBound(object sender, EventArgs e) { tv_Menu.CollapseAll(); if (tv_Menu.SelectedNode != null) { TreeNode tn = tv_Menu.SelectedNode; switch (tn.Depth) { case 5: tn.Parent.Parent.Parent.Parent.Parent.Expand(); tn.Parent.Parent.Parent.Parent.Expand(); tn.Parent.Parent.Parent.Expand(); tn.Parent.Parent.Expand(); tn.Parent.Expand(); break; case 4: tn.Parent.Parent.Parent.Parent.Expand(); tn.Parent.Parent.Parent.Expand(); tn.Parent.Parent.Expand(); tn.Parent.Expand(); break; case 3: tn.Parent.Parent.Parent.Expand(); tn.Parent.Parent.Expand(); tn.Parent.Expand(); break; case 2: tn.Parent.Parent.Expand(); tn.Parent.Expand(); break; case 1: tn.Parent.Expand(); break; } } }</pre><br> <p></p> <p><br> </p> <p style="padding-left:90px"><br> <br> </p> 2010-10-19T09:32:27-04:002010-10-19T09:32:27.19-04:00urn:uuid:00000000-0000-0000-0000-000005370068http://forums.asp.net/p/1900516/5370068.aspx/1?HTML5+placeholder+on+old+browsersHTML5 placeholder on old browsers <p>Let me start by mention that I'm not related in any way with the author of this plugin so the main purpose of this post is to share something I have found and not advertise anything.</p> <p>I found it and I think I must share with the community because I think is very usefull.</p> <p>I wanted to use the html5 placeholder on my textboxes but, when I open my html on old browsers, the placeholder text was not showed.</p> <p>I found this jquery plugin that solves this problem.</p> <p>&nbsp;You can find it on <a href="https://github.com/mathiasbynens/jquery-placeholder"> https://github.com/mathiasbynens/jquery-placeholder</a></p> <p>If you know any other way to solve this problem please share it.</p> 2013-04-20T13:51:15-04:002013-04-20T13:51:15.16-04:00urn:uuid:00000000-0000-0000-0000-000005075857http://forums.asp.net/p/1826226/5075857.aspx/1?examples+of+Checkboxes+and+Radio+Buttons+in+WebPagesexamples of Checkboxes and Radio Buttons in WebPages <p>For what it's worth, I have put together a sample web page (razor/c#) illustrating some of the more common use cases involving checkboxes and radio buttons.</p> <p>Perhaps this can help those who, like me, may have struggled with how to work these html controls.</p> <p>There are three cases of checkboxes:</p> <p>(1)&nbsp; Simple checkbox with no return value specified.&nbsp; When unchecked, nothing is returned; when checked, &quot;on&quot; is returned.&nbsp; The checked state of the checkbox is preserved.</p> <p>(2) Checkbox where a return value&nbsp;is specified.&nbsp; When unchecked, nothing is returned; when checked, the string in the value attribute is returned.&nbsp; The checked state of the checkbox is preserved.</p> <p>(3) A group of checkboxes, all sharing the same name attribute and each having a specified return value.&nbsp; If any one or more&nbsp;of the checkboxes are checked, the value(s) will be returned in a (comma-separated) string containing the value attribute string(s) corresponding to the checked checkbox.&nbsp; If none are checked, no value is returned.&nbsp; This use case illustrates the use of the .Split method to convert the comma-separated values string into an array of strings, which can be evaluated in a for loop.&nbsp; &nbsp; The checked state of each checkbox is preserved.</p> <p>There is one use case for radio buttons, showing buttons for yes and no (with the no button being checked by default.&nbsp; The checked state of the radio button is preserved.</p> <p>Run the page and play with the checkboxes/radio buttons, clicking the &quot;Submit&quot; button to see the results.&nbsp;</p> <p>Hopefully this can be useful to beginners like me.</p> <pre class="prettyprint">@{ //illustrates usage of radio buttons and check boxes Page.title = &quot;Checkboxes/Radio Butttons Use Cases&quot;; Layout = &quot;~/_SiteLayout.cshtml&quot;; var cbox1 = Request[&quot;cbox1&quot;]; var cbox2 = Request[&quot;cbox2&quot;]; var cbox3 = Request[&quot;cbox3&quot;].As&lt;string&gt;(&quot;&quot;);//defaults to empty string var rad1=Request[&quot;rad1&quot;]; } &lt;form method=&quot;post&quot; action=&quot;&quot;&gt; &lt;fieldset class=&quot;useCase&quot;&gt; &lt;h4&gt;Checkbox with persistent return value of &quot;on&quot; or null: &lt;input type=&quot;checkbox&quot; name=&quot;cbox1&quot; @(Request[&quot;cbox1&quot;] == &quot;on&quot; ? &quot; checked&quot; : &quot;&quot;) /&gt;&lt;/h4&gt; Value in Cbox1 (should be &quot;on&quot; when checked): @cbox1&lt;br /&gt; &lt;input type=&quot;submit&quot; value=&quot;submit&quot; /&gt; &lt;/fieldset&gt; &lt;fieldset class=&quot;useCase&quot;&gt; &lt;h4&gt;Checkbox with persistent return value of &quot;XYZ&quot; XYZ: &lt;input type=&quot;checkbox&quot; name=&quot;cbox2&quot; value=&quot;XYZ&quot; @(Request[&quot;cbox2&quot;] == &quot;XYZ&quot; ? &quot; checked&quot; : &quot;&quot;) /&gt;&lt;/h4&gt; Value in Cbox2 (should be &quot;XYZ&quot; when checked): @cbox2 &lt;input type=&quot;submit&quot; value=&quot;submit&quot; /&gt; &lt;/fieldset&gt; &lt;fieldset class=&quot;useCase&quot;&gt; &lt;h4&gt;Multiple Checkboxes, returning 0, one,or more persistent values Dogs:&lt;input type=&quot;checkbox&quot; name=&quot;cbox3&quot; value=&quot;Dogs&quot; @(cbox3.Contains(&quot;Dogs&quot;) ? &quot; checked&quot; : &quot;&quot;) /&gt; Cats:&lt;input type=&quot;checkbox&quot; name=&quot;cbox3&quot; value=&quot;Cats&quot; @(cbox3.Contains(&quot;Cats&quot;) ? &quot; checked&quot; : &quot;&quot;) /&gt; Birds:&lt;input type=&quot;checkbox&quot; name=&quot;cbox3&quot; value=&quot;Birds&quot; @(cbox3.Contains(&quot;Birds&quot;) ? &quot; checked&quot; : &quot;&quot;) /&gt; Snakes:&lt;input type=&quot;checkbox&quot; name=&quot;cbox3&quot; value=&quot;Snakes&quot; @(cbox3.Contains(&quot;Snakes&quot;) ? &quot; checked&quot; : &quot;&quot;) /&gt;&lt;/h4&gt; &lt;p&gt;Value in Cbox3 (should be comma-separated string when any is checked): @cbox3&lt;br /&gt; Here are the values from the checkedboxes:&lt;br /&gt; @foreach (var cbox in cbox3.Split(',')) { @cbox&lt;br /&gt; } &lt;/p&gt; &lt;input type=&quot;submit&quot; value=&quot;submit&quot; /&gt; &lt;/fieldset&gt; &lt;br /&gt;&lt;br /&gt; &lt;fieldset class=&quot;useCase&quot;&gt; &lt;h4&gt;radio Buttons to yield either &quot;y&quot; or&quot;n&quot; (default=&quot;n&quot;): &lt;input type=&quot;radio&quot; name=&quot;rad1&quot; value=&quot;y&quot; @(rad1==&quot;y&quot;?&quot; checked&quot;:&quot;&quot;)/&gt;Yes &lt;input type=&quot;radio&quot; name=&quot;rad1&quot; value=&quot;n&quot; @(rad1==&quot;n&quot;||rad1.IsEmpty()?&quot; checked&quot;:&quot;&quot;) /&gt;No &lt;/h4&gt; &lt;p&gt;Here is the value: @rad1&lt;/p&gt; &lt;input type=&quot;submit&quot; value=&quot;submit&quot; /&gt; &lt;/fieldset&gt; &lt;/form&gt;</pre> <p></p> 2012-07-20T22:00:30-04:002012-07-20T22:00:30.053-04:00urn:uuid:00000000-0000-0000-0000-000002395206http://forums.asp.net/p/1269499/2395206.aspx/1?Character+Counter+for+Multiline+TextboxCharacter Counter for Multiline Textbox <p>Best one I found: </p> <p>http://javascript.internet.com/forms/character-counter.html</p> <p>Also works with a regular textbox, of course.&nbsp; Although this is a javascript widget, I used it with an ASP.NET textbox using this markup:</p> <p>&lt;asp:TextBox ID=&quot;tbx_EntryDescription&quot; runat=&quot;server&quot; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Height=&quot;180px&quot; Width=&quot;220px&quot; TextMode=&quot;MultiLine&quot; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OnKeyUp=&quot;toCount('tbx_EntryDescription','chr_EntryBanner','{CHAR} characters left',350);&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:TextBox&gt;&lt;br /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;span id=&quot;chr_EntryBanner&quot;&gt;350 characters left.&lt;/span&gt;</p> <p>Don't forget to put this code in the &lt;head&gt; section of your page:&nbsp;</p> <p>&lt;script type=&quot;text/javascript&quot; src=&quot;charcount.js&quot;&gt;&lt;/script&gt;</p> <p>And then put the &quot;charcount.js&quot; (or whatever you name the .js file) in the same directory as your page. HTH someone...<br> &nbsp;</p> 2008-06-02T15:01:51-04:002008-06-02T15:01:51.777-04:00urn:uuid:00000000-0000-0000-0000-000005207124http://forums.asp.net/p/1857871/5207124.aspx/1?Simple+captcha+codeSimple captcha code <p><span style="text-decoration:underline"><strong>The handler:</strong></span></p> <pre class="prettyprint">&lt;%@ WebHandler Language=&quot;VB&quot; Class=&quot;textimg&quot; %&gt; Imports System Imports System.Web Imports System.Drawing Imports System.Drawing.Text Public Class textimg : Implements IHttpHandler, IReadOnlySessionState Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim s As String = HttpContext.Current.Session(&quot;RandomImgText&quot;) context.Response.ContentType = &quot;image/gif&quot; CreateImage(s).Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif) End Sub Private Shared Function CreateImage(sImageText As String) As Bitmap Dim bmpImage As New Bitmap(1, 1) Dim iWidth As Integer = 0 Dim iHeight As Integer = 0 Dim MyFont As New Font(&quot;Arial&quot;, 18, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel) Dim MyGraphics As Graphics = Graphics.FromImage(bmpImage) iWidth = CInt(MyGraphics.MeasureString(sImageText, MyFont).Width) &#43; 20 iHeight = CInt(MyGraphics.MeasureString(sImageText, MyFont).Height) &#43; 4 bmpImage = New Bitmap(bmpImage, New Size(iWidth, iHeight)) MyGraphics = Graphics.FromImage(bmpImage) MyGraphics.Clear(Color.Beige) MyGraphics.TextRenderingHint = TextRenderingHint.AntiAlias MyGraphics.DrawString(sImageText, MyFont, New SolidBrush(Color.Brown), 10, 4) MyGraphics.Flush() Return (bmpImage) End Function Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return True End Get End Property End Class</pre> <p><span style="text-decoration: underline;"><strong>Usage:</strong></span></p> <p></p> <pre class="prettyprint"> Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Dim s As String = CreateRandomString(6) Session("RandomImgText") = s End If End Sub Public Shared Function CreateRandomString(ByVal lenght As Integer) As String Dim guidResult As String = System.Guid.NewGuid().ToString() guidResult = guidResult.Replace("-", String.Empty) Return guidResult.Substring(0, lenght) End Function Protected Function ValidateForm() As Boolean Dim IsValid As Boolean = True If Not txtImg.Text = Session("RandomImgText") Then IsValid = False Return IsValid End Function</pre> <p><br> <br> </p> 2012-11-11T07:30:00-05:002012-11-11T07:30:00.553-05:00urn:uuid:00000000-0000-0000-0000-000005333315http://forums.asp.net/p/1889954/5333315.aspx/1?URL+ShorteningURL Shortening <p>I come across these in my search of a URL Shrinker. &nbsp;This is not an advertisment scheme just wanting to do my part.</p> <p>Import system.io<br> import system.net</p> <p>AdFly pays you for shrinking urls</p> <pre class="prettyprint">Dim Link As String = &quot;$URL_to_shrink$&quot; Dim API_KEY As String = &quot;$ADFLY_API_KEY$&quot; 'change this with your api key. Dim ID As String = &quot;$ADFLY_ID$&quot; 'change this with your id. Dim wr As HttpWebRequest = WebRequest.Create(&quot;http://api.adf.ly/api.php?key=&quot; &amp; API_KEY &amp; &quot;&amp;uid=&quot; &amp; ID &amp; &quot;&amp;advert_type=int&amp;domain=q.gs&amp;url=&quot; &amp; Link) Dim ws As HttpWebResponse = wr.GetResponse Dim read As StreamReader = New StreamReader(ws.GetResponseStream) Dim responeString As String = read.ReadToEnd</pre> <p>here is another for google url shrinking</p> <pre class="prettyprint">Public Shared Function Shorten(url As String) As String Dim key As String = "&#36;MYGOOGLEAPIKEY&#36;" Dim post As String = "{""longUrl"": """ &amp; url &amp; """}" Dim shortUrl As String = url Dim request As HttpWebRequest = DirectCast(WebRequest.Create("https://www.googleapis.com/urlshortener/v1/url?key=" &amp; key), HttpWebRequest) Try request.ServicePoint.Expect100Continue = False request.Method = "POST" request.ContentLength = post.Length request.ContentType = "application/json" request.Headers.Add("Cache-Control", "no-cache") Using requestStream As Stream = request.GetRequestStream() Dim postBuffer As Byte() = Encoding.ASCII.GetBytes(post) requestStream.Write(postBuffer, 0, postBuffer.Length) End Using Using response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse) Using responseStream As Stream = response.GetResponseStream() Using responseReader As New StreamReader(responseStream) Dim json As String = responseReader.ReadToEnd() shortUrl = Regex.Match(json, """id"": ?""(?&lt;id&gt;.+)""").Groups("id").Value End Using End Using End Using Catch ex As Exception ' if Google's URL Shortner is down... System.Diagnostics.Debug.WriteLine(ex.Message) System.Diagnostics.Debug.WriteLine(ex.StackTrace) End Try Return shortUrl End Function Shorten(yourlink.com)</pre> <p>Hope this helps some</p> 2013-03-16T01:28:18-04:002013-03-16T01:28:18.267-04:00urn:uuid:00000000-0000-0000-0000-000005339521http://forums.asp.net/p/1892274/5339521.aspx/1?When+Publish+goes+away+on+your+projectWhen "Publish" goes away on your project <p>This may be off topic (winforms/console)&nbsp;but I figure it was worth posting anyway to save someone else countless hours troubleshooting. Say you have a .net&nbsp;windows service that you've built and suddenly when you go to do Publish, the link is not there. You go to Build &gt; Publish and it is grayed out. What's probably happened is your Application setting Output type is no longer an application but more likely a Class. When you flip it back to either Windows or Console, your publish button will come back.</p> 2013-03-21T14:57:58-04:002013-03-21T14:57:58.733-04:00urn:uuid:00000000-0000-0000-0000-000005340051http://forums.asp.net/p/1892421/5340051.aspx/1?Dynamic+Themes+in+MVC+RazorDynamic Themes in MVC Razor <p>Hi,</p> <p>I struggled for the whole day to apply themes dynamically in MVC and found a solution by combining few googling results</p> <p>and the solution follows</p> <p>I done it by swapping CSS only. If you are looking for HTML, then it's not appropriate solution.</p> <p>Step 1: Create Dummy CSS Redmond.css ( Copy of Site.css with colors and bg colors changed)</p> <p>Step 2: From Layout Change the Styles Reference as following</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;link href= @HttpContext.Current.Application[&quot;Theme&quot;] as string rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;</p> <p>Step 3: In Index Method(Startup Method of application), set Theme value as follows</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public ActionResult Index()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (HttpContext.Application[&quot;Theme&quot;] == null)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpContext.Application[&quot;Theme&quot;] = LoadTheme();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ViewBag.Message = &quot;Modify this template to jump-start your ASP.NET MVC application.&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return View();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>where LoadTheme is a common Method</p> <p>&nbsp;public string LoadTheme(string Theme = null)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string sLocation = &quot;/Content/&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Theme == null)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sLocation &#43;= &quot;themes/&quot; &#43; &quot;Site.css&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (Theme == &quot;RedMond&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sLocation &#43;= &quot;themes/&quot; &#43; &quot;RedMond.css&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpContext.Application[&quot;Theme&quot;] = sLocation;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return HttpContext.Application[&quot;Theme&quot;] as string;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>Step 4: Declare 2 buttons as follows to allow user to change themes</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type=&quot;button&quot; id=&quot;RedMond&quot; value=&quot;RedMond Theme&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type=&quot;button&quot; id=&quot;Default&quot; value=&quot;Default Theme&quot; /&gt;</p> <p>Step 5 : Fire JQuery Event to call common Method LoadTheme on button click</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;script type=&quot;text/javascript&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#36;(document).ready(function () {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#36;('#RedMond').click(function () {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#36;.ajax({<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url: &quot;/Home/LoadTheme/?Theme=&quot; &#43; &quot;RedMond&quot;,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; success: function (data) {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#36;(&quot;link[rel=stylesheet]&quot;).attr({ href: data });<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#36;('#Default').click(function () {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#36;.ajax({<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url: &quot;/Home/LoadTheme&quot;,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; success: function (data) {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#36;(&quot;link[rel=stylesheet]&quot;).attr({ href: data });<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br> &nbsp;&nbsp;&nbsp; &lt;/script&gt;</p> <p>That's It. Hope this helps.</p> 2013-03-22T06:14:11-04:002013-03-22T06:14:11.207-04:00urn:uuid:00000000-0000-0000-0000-000001064190http://forums.asp.net/p/922913/1064190.aspx/1?Easy+in+memory+image+processing+grayscale+sepia+negative+resize+brightness+and+contrast+Easy in memory image processing(grayscale, sepia, negative, resize, brightness and contrast) <p>Howdie y'all,<br> <br> Here's&nbsp;the image processor i created and use with pleasure. So maybe you'll enjoy it as much a I do!<br> <br> It converts to: Grayscale, sepia and negative,<br> It resizes with high quality,<br> and sets brightness and contrast,<br> <br> ALL ON THE FLY!<br> <br> You can also call all these sweet functions from your code so you can, for example, resize and grayscale an uploaded image bij just 2 lines of code!<br> <br> And it's ten times faster then looping thru al you pixels.<br> <br> So how does it work???<br> <br> <br> <strong>First:</strong><br> <u>Create this class and compile it into a dll:</u><br> <br> &lt;code&gt;<br> using System;<br> using System.Drawing;<br> using System.Drawing.Drawing2D;<br> using System.Drawing.Imaging;<br> using System.IO;<br> using System.Web;</p> <p>namespace YourNamespace<br> {<br> &nbsp;&nbsp;&nbsp; public class ImageProcessor : IHttpHandler<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void ProcessRequest(HttpContext context)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string src = (context.Request.QueryString[&quot;src&quot;] == null) ? string.Empty : context.Server.MapPath(context.Server.UrlDecode(context.Request.QueryString[&quot;src&quot;]));</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; context.Response.Clear();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (File.Exists(src))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; context.Response.ContentType = &quot;image/jpeg&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int wi = (context.Request.QueryString[&quot;w&quot;] == null) ? 0 : Convert.ToInt32(context.Request.QueryString[&quot;w&quot;]);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int hi = (context.Request.QueryString[&quot;h&quot;] == null) ? 0 : Convert.ToInt32(context.Request.QueryString[&quot;h&quot;]);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool gb = (context.Request.QueryString[&quot;g&quot;] == null) ? false : Convert.ToBoolean(context.Request.QueryString[&quot;g&quot;]);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool nb = (context.Request.QueryString[&quot;n&quot;] == null) ? false : Convert.ToBoolean(context.Request.QueryString[&quot;n&quot;]);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool sb = (context.Request.QueryString[&quot;s&quot;] == null) ? false : Convert.ToBoolean(context.Request.QueryString[&quot;s&quot;]);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float bf = (context.Request.QueryString[&quot;b&quot;] == null) ? 0 : Convert.ToSingle(context.Request.QueryString[&quot;b&quot;]);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float cf = (context.Request.QueryString[&quot;c&quot;] == null) ? 0 : Convert.ToSingle(context.Request.QueryString[&quot;c&quot;]);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (Stream imgStream = File.OpenRead(src))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (Bitmap b = Resize(imgStream, wi, hi))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (gb)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ToGrayscale(b);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (nb)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ToNegative(b);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (sb)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ToSepia(b);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (bf != 0)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetBrightness(b, bf);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (cf != 1)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetContrast(b, cf);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b.Save(context.Response.OutputStream, ImageFormat.Jpeg);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; context.Response.End();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public bool IsReusable<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get { return true; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Bitmap Resize(Stream SourceImage, int MaxWidth, int MaxHeight)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bitmap b = null;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (System.Drawing.Image i = System.Drawing.Image.FromStream(SourceImage))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int _maxWidth = (MaxWidth &gt; 0) ? MaxWidth : i.Width;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int _maxHeight = (MaxHeight &gt; 0) ? MaxHeight : i.Height;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double _scaleWidth = (double)_maxWidth / (double)i.Width;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double _scaleHeight = (double)_maxHeight / (double)i.Height;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double _scale = (_scaleHeight &lt; _scaleWidth) ? _scaleHeight : _scaleWidth;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _scale = (_scale &gt; 1) ? 1 : _scale;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int _newWidth = (int)(_scale * i.Width);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int _newHeight = (int)(_scale * i.Height);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = new Bitmap(_newWidth, _newHeight);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (Graphics g = Graphics.FromImage(b))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.CompositingQuality = CompositingQuality.HighQuality;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.SmoothingMode = SmoothingMode.HighQuality;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.InterpolationMode = InterpolationMode.HighQualityBicubic;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.DrawImage(i, new Rectangle(0, 0, _newWidth, _newHeight));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.Save();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return b;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void ToGrayscale(Bitmap b)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ColorMatrix cm = new ColorMatrix(new float[][]{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {0.3086f, 0.3086f, 0.3086f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {0.6094f, 0.6094f, 0.6094f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {0.0820f, 0.0820f, 0.0820f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f, 1f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f, 0f, 1f}});</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ApplyColorMatrix(b, cm);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void ToNegative(Bitmap b)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ColorMatrix cm = new ColorMatrix(new float[][]{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {0.992f,&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp; 0f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp; 0f, 0.992f,&nbsp;&nbsp;&nbsp;&nbsp; 0f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp; 0f, 0.992f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp; 0f, 1f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {0.004f, 0.004f, 0.004f, 0f, 1f}});</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ApplyColorMatrix(b, cm);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cm = new ColorMatrix(new float[][]{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {-1f,&nbsp; 0f,&nbsp; 0f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] { 0f, -1f,&nbsp; 0f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] { 0f,&nbsp; 0f, -1f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] { 0f,&nbsp; 0f,&nbsp; 0f, 1f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] { 0f,&nbsp; 0f,&nbsp; 0f, 0f, 1f}});</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ApplyColorMatrix(b, cm);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void ToSepia(Bitmap b)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ColorMatrix cm = new ColorMatrix(new float[][]{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {0.393f, 0.349f, 0.272f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {0.769f, 0.686f, 0.534f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {0.189f, 0.168f, 0.131f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp; 0f, 1f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp; 0f, 0f, 1f}});</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ApplyColorMatrix(b, cm);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void SetBrightness(Bitmap b, float Brightness)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ApplyColorMatrix(b, CreateBrightnessMatrix(Brightness));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void SetContrast(Bitmap b, float Contrast)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ApplyColorMatrix(b, CreateContrastMatrix(Contrast));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static ColorMatrix CreateBrightnessMatrix(float Brightness)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Brightness &lt; -1 || Brightness &gt; 1)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new ArgumentOutOfRangeException(&quot;Brightness value is out of range&quot;);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ColorMatrix cm = new ColorMatrix(new float[][]{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp; 0,&nbsp; 0},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp; 0,&nbsp; 0},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1f,&nbsp; 0,&nbsp; 0},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 1f,&nbsp; 0},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {Brightness, Brightness, Brightness, 1f, 1f}});</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return cm;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static ColorMatrix CreateContrastMatrix(float Contrast)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Contrast &lt; 0 || Contrast &gt; 3)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new ArgumentOutOfRangeException(&quot;Contrast value is out of range&quot;);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float Trans = (1f - Contrast) / 2f;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ColorMatrix cm = new ColorMatrix(new float[][]{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {Contrast,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f, Contrast,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f, Contrast, 0f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0f, 1f, 0f},<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new float[] {&nbsp;&nbsp; Trans,&nbsp;&nbsp;&nbsp; Trans,&nbsp;&nbsp;&nbsp; Trans, 0f, 1f}});</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return cm;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void ApplyColorMatrix(Bitmap b, ColorMatrix cm)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (Graphics g = Graphics.FromImage(b))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageAttributes ia = new ImageAttributes();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ia.SetColorMatrix(cm);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.DrawImage(b, new Rectangle(0, 0, b.Width, b.Height), 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, ia);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.Save();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }<br> }</p> <p>&lt;/code&gt;<br> <br> <br> <strong>Second:<br> </strong><u>Add this line to you web.config in &lt;system.web&gt;:<br> </u></p> <p><br> &lt;httpHandlers&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;add verb=&quot;GET&quot;&nbsp;path=&quot;ImageProcessor.ashx&quot;&nbsp;type=&quot;YourNamespace.ImageProcessor, NameOfDll&quot; /&gt;<br> &lt;/httpHandlers&gt;<br> <br> <strong>Third:<br> </strong><u>Set the src attribute of an image to:<br> </u><br> ImageProcessor.ashx?src=..%2fUploads%2fMyImage.jpg&amp;amp;w=0&amp;amp;h=0&amp;amp;g=False&amp;amp;n=True&amp;amp;s=False&amp;amp;b=0&amp;amp;c=1<br> <br> Where:<br> <strong>src</strong> stands for the UrlEncoded Path of your image<br> <strong>w</strong> stands for the maximum with an image can be<br> <strong>h</strong>&nbsp;stands for the maximum height an image can be<br> <strong>g</strong> stands for grayscaling the image<br> <strong>n</strong> stands for negative of the image<br> <strong>s</strong> stands for sepia of the image<br> <strong>b</strong> stands for brightness of the image (between -1 and 1)<br> <strong>c</strong> stand for contrast of the image (between 0 and 3 where 1 is standard)<br> <br> <strong>Fourth:<br> </strong><u>To make it easier create this control as well and compile and&nbsp;use it together:<br> </u><br> &lt;code&gt;<br> using System;<br> using System.ComponentModel;<br> using System.Drawing;<br> using System.Text;<br> using System.Web;<br> using System.Web.UI;<br> using System.Web.UI.WebControls;</p> <p>namespace YourNamespace<br> {<br> &nbsp;&nbsp;&nbsp; [<br> &nbsp;&nbsp;&nbsp; DefaultProperty(&quot;src&quot;),<br> &nbsp;&nbsp;&nbsp; ToolboxData(&quot;&lt;{0}:BetterImage runat=\&quot;server\&quot;&gt;&lt;/{0}:BetterImage&gt;&quot;),<br> &nbsp;&nbsp;&nbsp; ToolboxBitmap(typeof(System.Web.UI.WebControls.Image))<br> &nbsp;&nbsp;&nbsp; ]<br> &nbsp;&nbsp;&nbsp; public class BetterImage : System.Web.UI.WebControls.Image<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bindable(true),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Category(&quot;Behavior&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DefaultValue(0),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description(&quot;Maximum width of the image.&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual int MaxWidth<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object b = ViewState[&quot;MaxWidth&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (b == null) ? 0 : (int)b;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ViewState[&quot;MaxWidth&quot;] = value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bindable(true),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Category(&quot;Behavior&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DefaultValue(0),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description(&quot;Maximum height of the image.&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual int MaxHeight<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object b = ViewState[&quot;MaxHeight&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (b == null) ? 0 : (int)b;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ViewState[&quot;MaxHeight&quot;] = value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bindable(true),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Category(&quot;Behavior&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DefaultValue(false),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description(&quot;Grayscale the image.&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual bool Grayscale<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object b = ViewState[&quot;Grayscale&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (b == null) ? false : (bool)b;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ViewState[&quot;Grayscale&quot;] = value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bindable(true),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Category(&quot;Behavior&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DefaultValue(false),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description(&quot;Negative of the image.&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual bool Negative<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object b = ViewState[&quot;Negative&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (b == null) ? false : (bool)b;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ViewState[&quot;Negative&quot;] = value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bindable(true),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Category(&quot;Behavior&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DefaultValue(false),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description(&quot;Sepia of the image.&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual bool Sepia<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object b = ViewState[&quot;Sepia&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (b == null) ? false : (bool)b;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ViewState[&quot;Sepia&quot;] = value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bindable(true),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Category(&quot;Behavior&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DefaultValue(0),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description(&quot;Brightness of the image.&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual float Brightness<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object b = ViewState[&quot;Brightness&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (b == null) ? 0: (float)b;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (value &lt; -1 || value &gt; 1)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new ArgumentOutOfRangeException(&quot;Brightness value is out of range&quot;);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ViewState[&quot;Brightness&quot;] = value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bindable(true),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Category(&quot;Behavior&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DefaultValue(1),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description(&quot;Contrast of the image.&quot;),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual float Contrast<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object b = ViewState[&quot;Contrast&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (b == null) ? 1 : (float)b;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (value &lt; 0 || value &gt; 3)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new ArgumentOutOfRangeException(&quot;Contrast value is out of range&quot;);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ViewState[&quot;Contrast&quot;] = value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected override void AddAttributesToRender(HtmlTextWriter writer)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (MaxWidth &gt; 0 || MaxHeight &gt; 0 || Grayscale || Negative || Sepia || Brightness != 0 || Contrast != 1)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StringBuilder newSrc = new StringBuilder(&quot;ImageProcessor.ashx?src=&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newSrc.Append(HttpContext.Current.Server.UrlEncode(base.ImageUrl) &#43; &quot;&amp;w=&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newSrc.Append(MaxWidth &#43; &quot;&amp;h=&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newSrc.Append(MaxHeight &#43; &quot;&amp;g=&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newSrc.Append(Grayscale &#43; &quot;&amp;n=&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newSrc.Append(Negative &#43; &quot;&amp;s=&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newSrc.Append(Sepia &#43; &quot;&amp;b=&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newSrc.Append(Brightness &#43; &quot;&amp;c=&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newSrc.Append(Contrast);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; base.ImageUrl = newSrc.ToString();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; base.AddAttributesToRender(writer);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }<br> }<br> &lt;/code&gt;<br> <br> <strong>Fifth:<br> </strong><u>After compiling add this control to your Toolbox and simply use it as you would any other control!</u><br> <br> <br> That's all!!<br> <br> Ohh.... no it's not... this post is getting even more exciting.....&nbsp;I've packed these two controls and two other ones&nbsp;in a sample web which you can <a href="http://www.waterwijkers.nl/Uploads/samples/BetterImageProcessor.zip">download here</a>. If you don't agree with me that this is a&nbsp;BetterImageProcessor just let me know!<br> <br> Cheers,<br> <br> Wes</p> 2005-09-27T07:40:43-04:002005-09-27T07:40:43.237-04:00urn:uuid:00000000-0000-0000-0000-000005191926http://forums.asp.net/p/1854112/5191926.aspx/1?How+to+make+the+text+wrap+in+a+treeview+structure+How to make the text wrap in a treeview structure? <p>This is how I wrapped the text.</p> <p>Basically NodeWrap does the trick.</p> <p></p> <p><span face="Courier New" style="font-family:Courier New"><span face="Courier New" style="font-family:Courier New"></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">&lt;</span></span><span face="Courier New" color="#800000" style="font-family:Courier New; color:#800000"><span face="Courier New" color="#800000" style="font-family:Courier New; color:#800000">asp</span></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">:</span></span><span face="Courier New" color="#800000" style="font-family:Courier New; color:#800000"><span face="Courier New" color="#800000" style="font-family:Courier New; color:#800000">TreeView</span></span><span face="Courier New" style="font-family:Courier New"> </span><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000"><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000">ID</span></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">=&quot;TreeView1&quot;</span></span><span face="Courier New" style="font-family:Courier New"> </span><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000"><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000">runat</span></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">=&quot;server&quot;</span></span><span face="Courier New" style="font-family:Courier New"> </span><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000"><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000">ExpandDepth</span></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">=&quot;0&quot;</span></span></span><span face="Courier New" style="font-family:Courier New"><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000"><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000">PopulateNodesFromClient</span></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">=&quot;true&quot;</span></span><span face="Courier New" style="font-family:Courier New"> </span><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000"><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000">ShowLines</span></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">=&quot;true&quot;</span></span><span face="Courier New" style="font-family:Courier New"> </span><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000"><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000">ShowExpandCollapse</span></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">=&quot;true&quot;</span></span></span><span face="Courier New" style="font-family:Courier New"><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000"><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000">OnTreeNodePopulate</span></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">=&quot;TreeView1_TreeNodePopulate&quot;</span></span><span face="Courier New" style="font-family:Courier New"> </span><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000"><span face="Courier New" color="#ff0000" style="font-family:Courier New; color:#ff0000">NodeWrap</span></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">=&quot;true&quot;</span></span><span face="Courier New" style="font-family:Courier New"> </span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff">&gt;</span></span></span><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"><span face="Courier New" color="#0000ff" style="font-family:Courier New; color:#0000ff"></span></span></p> 2012-10-25T22:55:54-04:002012-10-25T22:55:54.95-04:00urn:uuid:00000000-0000-0000-0000-000002054834http://forums.asp.net/p/1193229/2054834.aspx/1?Finding+Controls+in+a+Repeater+HeaderFinding Controls in a Repeater Header <p>The rationale behind many Microsoft ASP.NET controls is sound, but at times their implementation is frustrating, and even using VS2008, old issues still exist</p> <p>For example, using a repeater, it is possible find controls in a header during databinding by adding a listener to the ItemCreated or ItemDataBound events.</p> <p>Once a repeater is bound, only the bound Items are easily accessible through the Items property.&nbsp; If you subsequently want to get to a control in a header (or footer), there is no obvious method.</p> <p>If you perform a recursive search of the repeater and its controls, you will see that the control structure does contain the header.&nbsp; So, what's an easy way to find controls in the header?</p> <p>What I do is add a static helper class to a web site that contains a recursive control finder.&nbsp; Now, you need to be aware that with repeated items, there will be the same named item within each repeated item (that is ID&nbsp;: client ID and Unique ID are managed to be unique)</p> <p>Since a header and footer only exists once, their controls are easier to find by name (assuming there is no control with that name elsewhere in the repeater control descendants).</p> <p>&nbsp;</p> <p>Here is some code to find controls by name and type</p> <font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;summary&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> Finds the control by name, starting at a control and drilling down</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;/summary&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;param name=&quot;controlName&quot;&gt;&lt;/param&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;param name=&quot;searchStart&quot;&gt;&lt;/param&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;returns&gt;&lt;/returns&gt;</p> </font><font size="2"></font><font color="#0000ff" size="2">static</font><font size="2"> </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#2b91af" size="2">Control</font><font size="2"> RecursiveFindControl(</font><font color="#0000ff" size="2">string</font><font size="2"> controlName, </font><font color="#2b91af" size="2">Control</font><font size="2"> searchStart)</font><font size="2"> <p>{</p> </font><font color="#0000ff" size="2">if</font><font size="2"> (searchStart.ID == controlName)</font><font size="2"> <p></font><font color="#0000ff" size="2">return</font><font size="2"> searchStart;</p> <p></font><font color="#0000ff" size="2">else</p> </font><font size="2"> <p>{</p> </font><font color="#0000ff" size="2">foreach</font><font size="2"> (</font><font color="#2b91af" size="2">Control</font><font size="2"> child </font><font color="#0000ff" size="2">in</font><font size="2"> searchStart.Controls)</font><font size="2"> <p>{</p> </font><font color="#2b91af" size="2">Control</font><font size="2"> result = RecursiveFindControl(controlName, child);</font><font size="2"> <p></font><font color="#0000ff" size="2">if</font><font size="2"> (result != </font> <font color="#0000ff" size="2">null</font><font size="2">)</p> </font><font color="#0000ff" size="2">return</font><font size="2"> result;</font><font size="2"> <p>}</p> <p>}</p> </font><font color="#0000ff" size="2">return</font><font size="2"> </font><font color="#0000ff" size="2">null</font><font size="2">;</font><font size="2"> <p>}</p> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;summary&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> Finds the first control derived from a particulr type, recursively, starting with the saerch start control and recursively drilling down</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;/summary&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;param name=&quot;controlType&quot;&gt;&lt;/param&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;param name=&quot;searchStart&quot;&gt;&lt;/param&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;returns&gt;&lt;/returns&gt;</p> </font><font size="2"></font><font color="#0000ff" size="2">static</font><font size="2"> </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#2b91af" size="2">Control</font><font size="2"> RecursiveFindControl(</font><font color="#2b91af" size="2">Type</font><font size="2"> controlType, </font><font color="#2b91af" size="2">Control</font><font size="2"> searchStart)</font><font size="2"> <p>{</p> <p></font><font color="#008000" size="2">// if the control is derived from the type passed, return that control</p> </font><font size="2"></font><font color="#0000ff" size="2">if</font><font size="2"> (searchStart.GetType().IsSubclassOf(controlType))</font><font size="2"> <p></font><font color="#0000ff" size="2">return</font><font size="2"> searchStart;</p> <p></font><font color="#0000ff" size="2">else</p> </font><font size="2"> <p>{</p> <p></font><font color="#008000" size="2">// iterate the children</p> </font><font size="2"></font><font color="#0000ff" size="2">foreach</font><font size="2"> (</font><font color="#2b91af" size="2">Control</font><font size="2"> child </font><font color="#0000ff" size="2">in</font><font size="2"> searchStart.Controls)</font><font size="2"> <p>{</p> </font><font color="#2b91af" size="2">Control</font><font size="2"> result = RecursiveFindControl(controlType, child);</font><font size="2"> <p></font><font color="#0000ff" size="2">if</font><font size="2"> (result != </font> <font color="#0000ff" size="2">null</font><font size="2">)</p> </font><font color="#0000ff" size="2">return</font><font size="2"> result;</font><font size="2"> <p>}</p> <p>}</p> </font><font color="#0000ff" size="2">return</font><font size="2"> </font><font color="#0000ff" size="2">null</font><font size="2">;</font><font size="2"> <p>}</p> </font> 2007-12-12T09:02:01-05:002007-12-12T09:02:01.773-05:00urn:uuid:00000000-0000-0000-0000-000005333163http://forums.asp.net/p/1889914/5333163.aspx/1?ASP+NET+How+to+Lock+a+user+accountASP .NET How to Lock a user account <p>This is an informational post to try and help people find the information I was looking for more quickly.</p> <p>I know there are people out there that will argue that&nbsp;my need for this function is a result of not setting my memberships up in a more&nbsp;productive fashion, but I really didn't want to go back and redesign all my pages to make up for this short-sightedness (sp?).&nbsp; Long story short what I've run into is that my site will allow you to request an account but it will not let you register on the site unless I manually approve it.&nbsp; This is for a company Intranet and because of the low volume of requests it seemed the easiest way to handle it at the time.&nbsp; The problem is that even at the very basic level of access, there are sensitive items that I didn't want available to the public.&nbsp; Sometimes it is neccessary for me to give someone temporary access to the site.&nbsp; Rather than having to delete their account after we are finished I wanted to be able to have an account I could just turn on and off as desired (lock/unlock).&nbsp; The built-in functions allow for IsApproved = True/False or User.UnlockUser(), but I couldn't find a User.LockUser() function anywhere.&nbsp; I googled searched for a while but everything kept taking me back to &quot;IsApproved&quot; true/false.&nbsp; This would not however, stop a user from authenticating and gaining access to the root of our site.</p> <p>In the process of searching I saw many other people asking the same question but they couldn't find an answer on how to &quot;Lock&quot; a user account.&nbsp; As I stated before all the posts I saw kept pointing back to IsApproved = True/False.&nbsp; My hope is that this thread might save future people some time.&nbsp; It doesn't look like ASP .NET has a built-in module for locking a useraccount, just unlocking.&nbsp; So if, like me, you find yourself in need of the ability to lock user accounts you might find this next little bit of code helpful.&nbsp; I have a process to first find and select a user account.&nbsp; Please use what ever works best for you here.&nbsp; For my scenario with right around 25 accounts, I elected to just use a dropdownlist, but any method that will allow you to access their asp .net membershipuser information will work fine.&nbsp; Beyond that I have two buttons that change on selected item change, button lock and button unlock.&nbsp; They switch their enabled property back and forth based on the selected user's locked status.&nbsp; Once you can grab your user's account information you'll need some code like this to manually lock their account:</p> <pre class="prettyprint">Sub BtnLock_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnLock.Click Try Dim strUser As String = DLUsers.SelectedValue Dim usr As MembershipUser = Membership.GetUser(strUser) Dim strSQL As String = &quot;Update aspnet_Membership set IsLockedOut = 1 Where LoweredEmail = '&quot; &amp; LCase(usr.Email) &amp; &quot;'&quot; 'This connection string needs to match your webconfig file for your asp .net application database Dim cnStr As String = ConfigurationManager.ConnectionStrings(&quot;ApplicationServices&quot;).ConnectionString Dim cnn As New Data.SqlClient.SqlConnection(cnStr) cnn.Open() Dim cmd As New Data.SqlClient.SqlCommand(strSQL, cnn) cmd.ExecuteNonQuery() cnn.Close() BtnLock.Enabled = False BtnUnlock.Enabled = True Catch ex As Exception End Try End Sub</pre> <p></p> <p>I hope this saves someone else the time I spent looking for it.</p> <p>Cheers!</p> 2013-03-15T19:20:35-04:002013-03-15T19:20:35.68-04:00urn:uuid:00000000-0000-0000-0000-000002035475http://forums.asp.net/p/1188712/2035475.aspx/1?Dynamically+hiding+web+parts+based+on+current+user+roles+Dynamically hiding web parts based on current user roles. <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">The approach allows you to set permissions to Web Parts based on any of the current user’s roles. If a user does not have a matching Role that the Web Part is configured for, the Web Part will simple not be Visible in the Declarative Catalog. If the user is later removed from the role, the Web Parts will disappear from the Zones the next time the Web page is refreshed.</font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3"></font>&nbsp;</p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">(1) Add a <strong><em>WebPartManager</em></strong>, <strong><em>WebPartZone</em></strong>, <strong> <em>CatalogZone</em></strong>, and a <strong><em>DeclarativeCatalogPart</em></strong> to a <em><strong>Default.aspx</strong></em> file and configure them as you would normally.</font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3"></font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">(2) Add and event handler for OnAuthorizeWebPart to the WebPartManager (You can also do this in the property page for the WebPartManager).</font></p> <blockquote> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3"><em>&lt;asp:WebPartManager ID=&quot;WebPartManager1&quot; runat=&quot;server&quot; <strong>OnAuthorizeWebPart=&quot;AuthorizeWebParts&quot;</strong>&gt;</em></font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3"><em>&lt;/asp:WebPartManager&gt;</em></font></p> </blockquote> <p><font face="Times New Roman" size="3">(3) Add an AuthorizationFilter tag containing all of the roles that can access that particular control separated by a semi-colon. In this example I am using the roles AccountManagerRole, AdminRole, ManagerRole, UserRole, and TesterRole as outlined below (NOTE: I added these roles using the <em>ASP.NET Configuration Tool</em> under the <em>Security</em> tab and created a few users with mixed role assignements for testing):</font></p> <blockquote> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3"><em>&lt;WebPartsTemplate&gt;</em></font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3"><em>&lt;asp:Calendar ID=&quot;Calendar1&quot; <strong>AuthorizationFilter = &quot;AccountManagerRole; AdminRole; ManagerRole; UserRole; TesterRole&quot;</strong> title=&quot;Calendar&quot;<span style="">&nbsp; </span>runat=&quot;server&quot;/&gt;</em></font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3"><em>&lt;/WebPartsTemplate&gt;</em></font><font face="Times New Roman" size="3">&nbsp;</font> </p> </blockquote> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">(4) Add <span style="">&nbsp;</span>the following code to the <em>AuthorizeWebParts</em> function in the<strong><em> Default.aspx<u>.cs</u></em></strong> file:</font></p> <p><font face="Times New Roman" size="3">&nbsp;</font><span style="font-size:10pt; color:blue; font-family:'Courier New'">protected</span><span style="font-size:10pt; font-family:'Courier New'"> <span style="color:blue">void</span> AuthorizeWebParts(<span style="color:blue">object</span> sender, <span style="color:teal">WebPartAuthorizationEventArgs</span> e)</span><span style="font-size:10pt; font-family:'Courier New'">{</span> </p> <p class="MsoNormal" style="margin:0in 0in 0pt"><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green">&nbsp;&nbsp;&nbsp;&nbsp; // Author: James Edgell 11/28/07</span></span></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green">&nbsp;&nbsp;&nbsp;&nbsp; // This function is called for each web part by the OnAuthorizeWebPart</span></span></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green"></span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green">&nbsp;&nbsp;&nbsp;&nbsp; // event in the WebPartManager.</span></span></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green"></span></span>&nbsp;</p> <p><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green"></span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green">&nbsp;&nbsp;&nbsp;&nbsp; // If no roles are set, simply exit<br> </span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue"><span style="font-size:10pt; color:blue; font-family:'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp; if</span><span style="font-size:10pt; font-family:'Courier New'"><font color="#000000"> (</font><span style="color:teal">String</span><font color="#000000">.IsNullOrEmpty(e.AuthorizationFilter))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue"><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue">return</span><font color="#000000">;</font></span></span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue"></span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue"><span style="font-size:10pt; font-family:'Courier New'"><font color="#000000"></font></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></span></p> <p><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue"><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green">&nbsp;&nbsp;&nbsp;&nbsp; // Separate the different roles into and array of strings<br> </span></span></span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue"><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue">&nbsp;&nbsp;&nbsp;&nbsp; string</span><font color="#000000">[] rolesArray = e.AuthorizationFilter.Split(</font><span style="color:blue">new</span><font color="#000000"> </font><span style="color:teal">Char</span><font color="#000000">[] { </font><span style="color:maroon">';'</span><font color="#000000"> });</font></span></span></span></p> <p><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue"><span style="font-size:10pt; font-family:'Courier New'"></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green">&nbsp;&nbsp;&nbsp;&nbsp; // Assume the user does not have access to the web part<br> </span></span><span style="font-size:10pt; font-family:'Courier New'"><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp; e.IsAuthorized = </font><span style="color:blue">false</span><font color="#000000">;</font></span></span></span></p> <p><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue"><span style="font-size:10pt; font-family:'Courier New'"><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green">// Loop until the first role that allows the user access to the<br> </span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green">&nbsp;&nbsp;&nbsp;&nbsp; // web part is encountered.<br> &nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue"><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue">foreach</span><font color="#000000"> (</font><span style="color:blue">string</span><font color="#000000"> roleStr </font><span style="color:blue">in</span><font color="#000000"> rolesArray)<br> </font></span><span style="font-size:10pt; font-family:'Courier New'"><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="font-size:10pt; font-family:'Courier New'"><font color="#000000">roleStr.Trim();<br> </font></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</span><font color="#000000"> (</font><span style="color:teal">Roles</span><font color="#000000">.IsUserInRole(roleStr))<br> </font></span><span style="font-size:10pt; font-family:'Courier New'"><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:green">// the user ihas the rights, so authorize them<br> </span></span><span style="font-size:10pt; font-family:'Courier New'"><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.IsAuthorized = </font><span style="color:blue">true</span><font color="#000000">;<br> </font></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break</span><font color="#000000">;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font color="#000000"><span style="font-size:10pt; font-family:'Courier New'">}<br> &nbsp;&nbsp;&nbsp;&nbsp; </span></font><span style="font-size:10pt; font-family:'Courier New'"><font color="#000000">}<br> </font></span><span style="font-size:10pt; font-family:'Courier New'"><font color="#000000">}</font></span></span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue"> </p> </span></span><font face="Times New Roman" size="3"></font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">By setting the <em>AuthorizationFilter</em> to the authorized roles for each control in the <em> WebPartsTemplate</em>, ASP.NET will dynamically grant access and visibility of the individual Web Parts. For example: If I do not wish Users or Testers to have access to the <em>Calendar1</em> Web Part, simply remove the <em>UsersRole</em> and <em>TestersRole</em> from the <em>AuthorizationFilter</em> tag, such as:</font></p> <blockquote> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3"><em>&lt;asp:Calendar ID=&quot;Calendar1&quot; <strong>AuthorizationFilter = &quot; AccountManagerRole; AdminRole; ManagerRole &quot;</strong> title=&quot;Calendar&quot;<span style="">&nbsp; </span>runat=&quot;server&quot;/&gt;</em></font></p> </blockquote> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">This will work with any combination of <em>User Roles</em> set in the ASP.NET Membership system or the <em>ASP.NET Configuration</em> <em>Tool</em>. It’s that simple! </font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3"></font>&nbsp;</p> 2007-11-30T21:03:25-05:002007-11-30T21:03:25.563-05:00urn:uuid:00000000-0000-0000-0000-000005303243http://forums.asp.net/p/1883108/5303243.aspx/1?Confirm+value+returnConfirm value return <p>I just want to share this with you guys. If you are trying to get return value back from comfirm messagebox, here is the simple way.</p> <p>&nbsp;1. insert HiddenField in the .aspx</p> <p>2. Create a javascript function and include this code.&nbsp; like this</p> <p>function DeleteMsg() {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var Dmsg = confirm(&quot;You about to Delete all this record(s). Are you sure you want to continue ?&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.getElementById('&lt;%=HiddenDmsg.ClientID%&gt;').value = Dmsg;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return&nbsp; HiddenDmsg;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>3. Drag a Button in the interface and call your java function. Like this</p> <p>&lt;asp:Button ID=&quot;btnDelete&quot; runat=&quot;server&quot; Text=&quot;Delete&quot; onclick=&quot;btnDelete_Click&quot; class=&quot; &quot; OnClientClick=&quot;return DeleteMsg();&quot; /&gt;</p> <p><strong>4. Received the value&nbsp; like this</strong></p> <p>&nbsp;protected void btnDelete_Click(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string DelMsg = HiddenDmsg.Value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>Hope this will help somebody.</p> 2013-02-16T00:06:49-05:002013-02-16T00:06:49.927-05:00urn:uuid:00000000-0000-0000-0000-000004827740http://forums.asp.net/p/1768549/4827740.aspx/1?This+is+how+to+export+data+from+ASP+Net+database+into+ExcelThis is how to export data from ASP.Net database into Excel <p>Moderators, if this should go into another forum that is more appropriate, please feel free to place it there.</p> <p>I've seen a lot of examples of how to export data into an Excel spreadsheet using ASP.NET and most have been wrong.<br> This code works and is very simple to follow.<br> This is my first contribution to the forums, enjoy...Paul</p> <p>// these namespaces need to be added to your code behind file<br> using System.Configuration;<br> using System.Data.SqlClient;<br> using System.Data;</p> <p>namespace MySpot.UserPages<br> {<br> &nbsp;&nbsp;&nbsp; public partial class Journal : System.Web.UI.Page<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[&quot;MySpotDBConnStr&quot;].ConnectionString);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable dt = new DataTable();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // regular page_load from .aspx file<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected void Page_Load(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!IsPostBack)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // added a button with ID=btnDownload and double clicked it's onclick event to auto create method<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected void btnDownload_Click(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string queryStr = &quot;SELECT * from table&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataAdapter sda = new SqlDataAdapter(queryStr, conn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sda.Fill(dt);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ExportTableData(dt);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // this does all the work to export to excel<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void ExportTableData(DataTable dtdata)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string attach = &quot;attachment;filename=journal.xls&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.ClearContent();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.AddHeader(&quot;content-disposition&quot;, attach);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.ContentType = &quot;application/ms-excel&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (dtdata != null)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (DataColumn dc in dtdata.Columns)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(dc.ColumnName &#43; &quot;\t&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //sep = &quot;;&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(System.Environment.NewLine);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (DataRow dr in dtdata.Rows)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; dtdata.Columns.Count; i&#43;&#43;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(dr[i].ToString() &#43; &quot;\t&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(&quot;\n&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.End();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }<br> }</p> <p>In IE9 the regular bar comes on down at the bottom asking to save or open, just click open and there it is<br> In FireFox that pesky download box comes on, then pops up a dialog, click open and there it is<br> in Opera it asks to save or open, click open and there it is.</p> 2012-02-11T16:40:05-05:002012-02-11T16:40:05-05:00urn:uuid:00000000-0000-0000-0000-000005260704http://forums.asp.net/p/1872004/5260704.aspx/1?Apply+Transactions+Apply Transactions <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;<br> using System.Data.SqlClient;<br> <br> public partial class _Default : System.Web.UI.Page <br> {<br> &nbsp;&nbsp;&nbsp; protected void Page_Load(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {<br> <br> &nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; protected void btnSave_Click(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string ConStr = &quot;Data Source=ADMIN\\SQLEXPRESS;Database=shail;Integrated Security=True;&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection con = new SqlConnection(ConStr);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.Open();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (SqlTransaction Trans = con.BeginTransaction())<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand com = new SqlCommand(&quot;SaveUpdateStuPer&quot;,con);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.CommandType = CommandType.StoredProcedure;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.Parameters.AddWithValue(&quot;@Action&quot;, 0);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.Parameters.AddWithValue(&quot;@StdId&quot;, 0);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.Parameters.AddWithValue(&quot;@Name&quot;, txtName.Text);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.Parameters.AddWithValue(&quot;@Age&quot;, Convert.ToString(txtAge.Text));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.Transaction = Trans;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.ExecuteNonQuery();<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand com1 = new SqlCommand(&quot;SaveUpdateStuClass&quot;, con);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com1.CommandType = CommandType.StoredProcedure;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com1.Parameters.AddWithValue(&quot;@Action&quot;, 0);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com1.Parameters.AddWithValue(&quot;@ClassId&quot;, txtClassId.Text);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com1.Parameters.AddWithValue(&quot;@Class&quot;, txtClass.Text);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com1.Transaction = Trans;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com1.ExecuteNonQuery();<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand com2 = new SqlCommand(&quot;SaveUpdateStuSub&quot;, con);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com2.CommandType = CommandType.StoredProcedure;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com2.Parameters.AddWithValue(&quot;@Action&quot;, 0);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com2.Parameters.AddWithValue(&quot;@SubId&quot;, txtSubId.Text);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com2.Parameters.AddWithValue(&quot;@Subject&quot;, txtSubject.Text);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com2.Transaction = Trans;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com2.ExecuteNonQuery();<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Trans.Commit();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.Close();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblMsg.Text = &quot;Saving Done..&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (Exception ex)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Trans.Rollback();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblMsg.Text = &quot;Saving Failed..&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtName.Text = &quot;&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtAge.Text = &quot;&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtClassId.Text = &quot;&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtClass.Text = &quot;&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtSubId.Text = &quot;&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtSubject.Text = &quot;&quot;;<br> <br> <br> &nbsp;&nbsp;&nbsp; }<br> }</p> 2013-01-05T17:54:33-05:002013-01-05T17:54:33.717-05:00