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

<channel>
	<title>Dahlin Development - Blog &#187; asp.net</title>
	<atom:link href="http://blog.dahlindevelopment.com/category/web-development/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dahlindevelopment.com</link>
	<description></description>
	<lastBuildDate>Thu, 26 Jan 2012 14:17:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Could not load file or assembly &#8216;AjaxControlToolkit&#8217; or one of its dependencies.</title>
		<link>http://blog.dahlindevelopment.com/2010/11/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies/</link>
		<comments>http://blog.dahlindevelopment.com/2010/11/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 03:53:19 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[ajaxcontroltoolkit]]></category>

		<guid isPermaLink="false">http://blog.dahlindevelopment.com/?p=340</guid>
		<description><![CDATA[This is the second time I’ve encountered this exception so I need to blog this in case I run into it again.  I had to search for the solution this time around again. It occurred after my pc crashed. Could not load file or assembly &#8216;AjaxControlToolkit&#8217; or one of its dependencies. The parameter is incorrect. [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second time I’ve encountered this exception so I need to blog this in case I run into it again.  I had to search for the solution this time around again. It occurred after my pc crashed.</p>
<h4><em>Could not load file or assembly &#8216;AjaxControlToolkit&#8217; or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0&#215;80070057 (E_INVALIDARG))</em></h4>
<p><strong>Solution:</strong><br />
Clear out the temporary framework files for your project in:<br />
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\</p>
<p><strong>Windows 7 users:<br />
</strong>C:\Users\[username]\AppData\Local\Temp\Temporary ASP.NET Files\</p>
<p><strong>For 64 bit systems with &#8216;Framework&#8217; in the path the full path is:<br />
</strong>C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\</p>
<p>All credit for this solution goes to SolutionCottage.com, <a title="http://www.solutioncottage.com/ShowSolution.aspx?solID=59" href="http://www.solutioncottage.com/ShowSolution.aspx?solID=59">http://www.solutioncottage.com/ShowSolution.aspx?solID=59</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.dahlindevelopment.com%2F2010%2F11%2Fcould-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies%2F&amp;title=Could%20not%20load%20file%20or%20assembly%20%26%238216%3BAjaxControlToolkit%26%238217%3B%20or%20one%20of%20its%20dependencies." id="wpa2a_2"><img src="http://blog.dahlindevelopment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.dahlindevelopment.com/2010/11/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add css class attribute to html helpers in asp.NET MVC 2</title>
		<link>http://blog.dahlindevelopment.com/2010/08/add-css-class-attribute-to-html-helpers-in-asp-net-mvc-2/</link>
		<comments>http://blog.dahlindevelopment.com/2010/08/add-css-class-attribute-to-html-helpers-in-asp-net-mvc-2/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 18:37:07 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://blog.dahlindevelopment.com/?p=291</guid>
		<description><![CDATA[It took me forever to find out how to do this so hoping this will save someone else the time. Here is an example: &#60;%= Html.TextBoxFor(model =&#62; model.Email, new { @class = &#34;txtLarge&#34; })%&#62; In asp.NET MVC I used _class it seems in MVC 2 you need to use the @ symbol.]]></description>
			<content:encoded><![CDATA[<p>It took me forever to find out how to do this so hoping this will save someone else the time.</p>
<p>Here is an example:</p>
<p>&lt;%= Html.TextBoxFor(model =&gt; model.Email, new { @class = &quot;txtLarge&quot; })%&gt;</p>
<p>In asp.NET MVC I used _class it seems in MVC 2 you need to use the @ symbol.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.dahlindevelopment.com%2F2010%2F08%2Fadd-css-class-attribute-to-html-helpers-in-asp-net-mvc-2%2F&amp;title=Add%20css%20class%20attribute%20to%20html%20helpers%20in%20asp.NET%20MVC%202" id="wpa2a_4"><img src="http://blog.dahlindevelopment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.dahlindevelopment.com/2010/08/add-css-class-attribute-to-html-helpers-in-asp-net-mvc-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>asp.net MVC 2 Validation &#8211; One Field Required</title>
		<link>http://blog.dahlindevelopment.com/2010/06/asp-net-mvc-2-validation-one-field-required/</link>
		<comments>http://blog.dahlindevelopment.com/2010/06/asp-net-mvc-2-validation-one-field-required/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 16:43:17 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://blog.dahlindevelopment.com/?p=261</guid>
		<description><![CDATA[Example of how to add validation for requiring one field or another.]]></description>
			<content:encoded><![CDATA[<p>I was building a form that had two fields: home phone number and mobile phone number.</p>
<p>The client needed at least one of the two fields filled out.</p>
<p>Given the existing DataAnnotations nothing fit the bill in this case. I ended up creating a custom validation attribute that is applied at the class level.</p>
<p>I based it off of the PropertiesMustMatchAttribute custom attribute that is included in the AccountModels.cs/vb file within the default ASP.NET MVC 2 application project template (just do a File-&gt;New ASP.NET MVC 2 Web Project within VS 2010 and look for this class).</p>
<p>First off in the ContactModel.cs  I added:</p>
<pre class="brush: csharp; title: ; notranslate">
using System.ComponentModel.DataAnnotations;
using System.Globalization;
</pre>
<pre class="brush: csharp; title: ; notranslate">
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
    public sealed class OneOrOtherFieldRequired : ValidationAttribute
    {
        private const string _defaultErrorMessage = &amp;quot;'{0}' or '{1}' are required.&amp;quot;;
        private readonly object _typeId = new object();

        public OneOrOtherFieldRequired(string field1, string field2)
            : base(_defaultErrorMessage)
        {
            Field1 = field1;
            Field2 = field2;
        }

        public string Field1 { get; private set; }
        public string Field2 { get; private set; }

        public override object TypeId
        {
            get
            {
                return _typeId;
            }
        }

        public override string FormatErrorMessage(string name)
        {
            return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString, Field1, Field2);
        }

        public override bool IsValid(object value)
        {
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value);
            object field1 = properties.Find(Field1, true).GetValue(value);
            object field2 = properties.Find(Field2, true).GetValue(value);
            string valueAsString1 = field1 as string;
            string valueAsString2 = field2 as string;
            if (String.IsNullOrEmpty(valueAsString1) &amp;amp;&amp;amp; String.IsNullOrEmpty(valueAsString2))
            {
                return false;
            }
            return true;
        }
    }
</pre>
<p>I then created in ContactModel.cs the ContactModel class.  In this class I have among other properties the two phone number properies: HomePhoneNumber and MobilePhoneNumber.</p>
<pre class="brush: csharp; title: ; notranslate">
 [OneOrOtherFieldRequired(&amp;quot;HomePhone&amp;quot;, &amp;quot;MobilePhone&amp;quot;, ErrorMessage=&amp;quot;Please fill in either your home or mobile number.&amp;quot;)]
    public class ContactModel
    {
       ...
        public String HomePhone { get; set; }
        public String MobilePhone { get; set; }
</pre>
<p>In the ContactController I have an action:</p>
<pre class="brush: csharp; title: ; notranslate">
        [HttpPost]
        public ActionResult Index(Contact contact)
        {
            if (ModelState.IsValid)
            {
                contact.Store();
                contact.SendEmail();
                ViewData[&amp;quot;ShowForm&amp;quot;] = false;
                return View();
            }
            ViewData[&amp;quot;ShowForm&amp;quot;] = true;
            return View(contact);
        }
</pre>
<p>When creating the view make sure to create a strongly typed view on the ContactModel</p>
<p>In the View I add the validation summary to display the error message if the requirement isn’t fulfilled.</p>
<pre class="brush: csharp; title: ; notranslate">
&amp;lt;%= Html.ValidationSummary(true, &amp;quot;Please correct invalid and required fields.&amp;quot;) %&amp;gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.dahlindevelopment.com/2010/06/asp-net-mvc-2-validation-one-field-required/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create Excel file dynamically (Simple Way)</title>
		<link>http://blog.dahlindevelopment.com/2010/05/create-excel-file-dynamically-simple-way/</link>
		<comments>http://blog.dahlindevelopment.com/2010/05/create-excel-file-dynamically-simple-way/#comments</comments>
		<pubDate>Mon, 17 May 2010 04:31:10 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[linq]]></category>

		<guid isPermaLink="false">http://blog.dahlindevelopment.com/?p=247</guid>
		<description><![CDATA[Scenerio: I’ve recently had a a few projects that I’ve created forms for.&#160; I have given the client a login to view all the form submissions, but in the end they want this data in an Excel file so they can easily manage it. Research: I have found there a quite a few ways to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Scenerio: </strong>I’ve recently had a a few projects that I’ve created forms for.&#160; I have given the client a login to view all the form submissions, but in the end they want this data in an Excel file so they can easily manage it.</p>
<p><strong>Research: </strong>I have found there a quite a few ways to achieve this.&#160; Some take advantage of the Excel interop, some create a .csv, some use third party tools, some use xml. Here is a good discussion I found on the topic at Stack Overflow, <a title="http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c" href="http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c">http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c</a>.     <br />All have pros and cons.</p>
<p><strong>Solution: </strong>Here is what I have found to be the simplest way to read your dataset in an Excel file. First off, this doesn’t product a true Excel file, but it is something Excel can read into a table which often is all you need.</p>
<p>What I found is you can write the contents of a datagrid to an output stream that can be saved as a .xls file.</p>
<p>code snippet: I am using linq to bind to a datagrid</p>
<pre class="brush: csharp; title: ; notranslate">
var registrations = from reg in db.Registrations
                    where reg.JumpPageId == int.Parse((String)e.CommandArgument)
                    orderby reg.TimeStamp descending
                    select reg;
HttpResponse response = HttpContext.Current.Response;

// first let's clean up the response.object
response.Clear();
response.Charset = &quot;&quot;;

// set the response mime type for excel
response.ContentType = &quot;application/vnd.ms-excel&quot;;
response.AddHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=registrants.xls&quot;);

// create a string writer
using (StringWriter sw = new StringWriter())
{
    using (HtmlTextWriter htw = new HtmlTextWriter(sw))
    {
        // instantiate a datagrid
        DataGrid dg = new DataGrid();
        dg.DataSource = registrations;
        dg.DataBind();
        dg.RenderControl(htw);
        response.Write(sw.ToString());
        response.End();
    }
}
 </pre>
<p>LIke I said, this doesn’t output a true Excel file so when you go to open it, you will be prompted a warning:</p>
<p><a href="http://blog.dahlindevelopment.com/wp-content/uploads/2010/05/excelwarning.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="excelwarning" border="0" alt="excelwarning" src="http://blog.dahlindevelopment.com/wp-content/uploads/2010/05/excelwarning_thumb.png" width="499" height="74" /></a> </p>
<p>It is saying the contents of the file are in a different format than what the .xls extension says it is.&#160; </p>
<p>Click Yes and it will open.</p>
</p>
<p>If you were to open this file in a text editor you will see that it really is just the datagrid html output.</p>
<p>Not the most elegant solution but it is a quick way to throw an Export to Excel button on a report page.</p>
<p>My next blog post will show how to create an Excel file using a third party tool.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.dahlindevelopment.com%2F2010%2F05%2Fcreate-excel-file-dynamically-simple-way%2F&amp;title=Create%20Excel%20file%20dynamically%20%28Simple%20Way%29" id="wpa2a_6"><img src="http://blog.dahlindevelopment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.dahlindevelopment.com/2010/05/create-excel-file-dynamically-simple-way/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.NET PostBackUrl not working on Server</title>
		<link>http://blog.dahlindevelopment.com/2010/04/asp-net-postbackurl-not-working-on-server/</link>
		<comments>http://blog.dahlindevelopment.com/2010/04/asp-net-postbackurl-not-working-on-server/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 06:03:23 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Rackspace Cloud]]></category>

		<guid isPermaLink="false">http://blog.dahlindevelopment.com/?p=208</guid>
		<description><![CDATA[Scenerio: I have a simple contact form in which I want to post to a different page. Pretty simple, just set the PostBackUrl property of the button to the page I want to post to. It works like it should locally.  When I deploy it to the server, Rackspace Cloud, it doesn’t work. Research: After [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Scenerio:</strong> I have a simple contact form in which I want to post to a different page.<br />
Pretty simple, just set the PostBackUrl property of the button to the page I want to post to. It works like it should locally.  When I deploy it to the server, Rackspace Cloud, it doesn’t work.</p>
<p><strong>Research: </strong>After Binging for a while I found that the issue was due to a javascript error.  If you VIew Source of the page, you’ll notice that the rendered html uses javascript to perform the PostBack.</p>
<p>&lt;input style=&#8221;border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&#8221; id=&#8221;imgButton&#8221; class=&#8221;submit&#8221; onclick=&#8221;javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&amp;quot;imgButton&amp;quot;, &amp;quot;&amp;quot;, false, &amp;quot;&amp;quot;, &amp;quot;/quick-contact.aspx&amp;quot;, false, false))&#8221; src=&#8221;/i/qcsubmit.gif&#8221; type=&#8221;image&#8221; name=&#8221;imgButton&#8221; /&gt;</p>
<p>I then was able to capture the javascript error in IE. *Sidenote, what is a good way to do this? I ended up putting my cursor in the form, hit enter and quickly clicked on the browser stop button. There must be a better way.</p>
<p><img style="display: inline; border-width: 0px;" title="postback" src="http://blog.dahlindevelopment.com/wp-content/uploads/2010/04/postback_thumb.png" border="0" alt="postback" width="472" height="316" /></p>
<p>“Webform_PostbackOptions” is undefined.</p>
<p>Ok…. Why is that? I found this in the comments at a blog post on <a title="http://pocketnerd.blogspot.com/2008/01/webformpostbackoptions-is-undefined.html" href="http://pocketnerd.blogspot.com/2008/01/webformpostbackoptions-is-undefined.html">http://pocketnerd.blogspot.com/2008/01/webformpostbackoptions-is-undefined.html</a></p>
<blockquote><p>“I was getting this error in a load balanced production environment, but once the network admin turned on sticky sessions, all the errors went away. I assume it was trying to load the .axd file from the other web server and perhaps that caused a security problem which didn&#8217;t allow the file to load. Not sure but just thought I&#8217;d share what fixed it for me. “</p></blockquote>
<p>I don’t have server access when hosting in the Cloud.</p>
<p>The WebForm_PostBackOptions function should be in the WebResource.axd file that you’ll see is referenced in the html on load.</p>
<p>&lt;script src=&#8221;/WebResource.axd?d=Ttwk99ZBtJ8argpvGbO64g2&amp;amp;t=633750447951477990&#8243; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;</p>
<p>I tried browsing to this file and this indeed was the issue, 404 Not Found.</p>
<p><strong>Solution: </strong> I loaded the page locally.  Viewed Source, grabbed the WebResource.axd and querystring, browsed to this file. This gave me the output of the javascript.  I copied that all and placed it into a postbackfix.js file.  I then referenced this js file on the page.  Uploaded the new js and aspx files.  Works now.</p>
<p>This took me a few hours of banging my head (not to Quit Riot) to figure out.  Hope this helps someone else.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.dahlindevelopment.com%2F2010%2F04%2Fasp-net-postbackurl-not-working-on-server%2F&amp;title=ASP.NET%20PostBackUrl%20not%20working%20on%20Server" id="wpa2a_8"><img src="http://blog.dahlindevelopment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.dahlindevelopment.com/2010/04/asp-net-postbackurl-not-working-on-server/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Feedback tab widget in ASP.NET</title>
		<link>http://blog.dahlindevelopment.com/2010/02/feedback-tab-widget-in-asp-net/</link>
		<comments>http://blog.dahlindevelopment.com/2010/02/feedback-tab-widget-in-asp-net/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 03:45:52 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.dahlindevelopment.com/?p=181</guid>
		<description><![CDATA[I recently had a client that wanted a Feedback tab that you find on a lot of sites now a days.  Something similar to Get Satisfaction or uservoice. I couldn’t find anything out there that I liked so here is what I came up with. The approach I am about to describe will place the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a client that wanted a Feedback tab that you find on a lot of sites now a days.  Something similar to <a href="http://www.getsatisfaction.com/widgets" target="_blank">Get Satisfaction</a> or <a href="http://uservoice.com/" target="_blank">uservoice</a>.</p>
<p><img style="display: inline; border: 0px;" title="feedback" src="http://blog.dahlindevelopment.com/wp-content/uploads/2010/02/feedback.png" border="0" alt="feedback" width="192" height="244" /></p>
<p>I couldn’t find anything out there that I liked so here is what I came up with. The approach I am about to describe will place the Feedback tab on every page that is using your Master Page.</p>
<p>I am using the <a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Default.aspx" target="_blank">ASP.NET AJAX Control Toolkit</a> for the modal.</p>
<p>First we need to set the modal up.</p>
<ol>
<li>Make sure you have the AjaxControlToolkit assembly in your project references.</li>
<li>Add the page directive for the Control Kit at the top of your Master Page:
<pre class="brush: xml; title: ; notranslate">
&lt;%@ Register Assembly=&quot;AjaxControlToolkit&quot; Namespace=&quot;AjaxControlToolkit&quot; TagPrefix=&quot;ajaxToolkit&quot; %&gt;
</pre>
</li>
<li>Add the ScriptManager to your Master Page:
<pre class="brush: xml; title: ; notranslate">
&lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; /&gt;
</pre>
</li>
<li>Place the Feedback tab on your site by adding it as an ASP.NET ImageButton and adding a cssclass to it:
<pre class="brush: xml; title: ; notranslate">
&lt;asp:ImageButton ID=&quot;lbFeedback&quot; CssClass=&quot;tab&quot; runat=&quot;server&quot; ImageUrl=&quot;images/feedback.gif&quot; /&gt;
</pre>
</li>
<li>Add this styling to your css stylesheet:
<pre class="brush: css; title: ; notranslate">
.tab{position: fixed; right: 0; top: 250px;}
</pre>
<p>This will position the tab on the right of the browser window.</li>
<li>Now add the Feedback form inside a panel that will appear in the modal to the bottom of your Master Page just before the &lt;/form&gt;.
<pre class="brush: xml; title: ; notranslate">
&lt;asp:Panel ID=&quot;pnlModal&quot; runat=&quot;server&quot; CssClass=&quot;modal&quot;&gt;
        &lt;p&gt;Thank you for taking the time to leave us
            feedback. Good or bad we want to know how your experience was at our
            establishment.&lt;/p&gt;
        &lt;p&gt;&lt;label&gt;Name:&lt;/label&gt;&lt;br /&gt;&lt;asp:TextBox ID=&quot;txtName&quot; runat=&quot;server&quot; /&gt;&lt;/p&gt;
        &lt;p&gt;&lt;label&gt;Email:&lt;/label&gt;&lt;br /&gt;&lt;asp:TextBox ID=&quot;txtEmail&quot; runat=&quot;server&quot; /&gt;&lt;/p&gt;
        &lt;p&gt;&lt;label&gt;Message:&lt;/label&gt;&lt;br /&gt;&lt;asp:TextBox ID=&quot;txtMessage&quot; runat=&quot;server&quot; TextMode=&quot;MultiLine&quot; Columns=&quot;40&quot; Rows=&quot;10&quot; /&gt;&lt;/p&gt;
        &lt;asp:Button ID=&quot;btnSubmit&quot; runat=&quot;server&quot; Text=&quot;Submit&quot;
            onclick=&quot;btnSubmit_Click&quot; /&gt;
        &lt;asp:Button ID=&quot;btnCancel&quot; runat=&quot;server&quot; Text=&quot;Cancel&quot; /&gt;
    &lt;/asp:Panel&gt;
</pre>
</li>
<li>Add the Modal Popup Extender control to handle the modal:
<pre class="brush: xml; title: ; notranslate">
&lt;ajaxToolkit:ModalPopupExtender ID=&quot;mpe&quot; runat=&quot;server&quot; TargetControlID=&quot;lbFeedback&quot; PopupControlID=&quot;pnlModal&quot; BackgroundCssClass=&quot;modalbg&quot; CancelControlID=&quot;btnCancel&quot;&gt;&lt;/ajaxToolkit:ModalPopupExtender&gt;
</pre>
</li>
<li>Lets add a Thank you message that is only visible after the feedback form is submitted. I add this at the top of the Master Page:
<pre class="brush: xml; title: ; notranslate">
&lt;div id=&quot;thankyou&quot; runat=&quot;server&quot; visible=&quot;false&quot; class=&quot;thankyoumessage&quot;&gt;Thank you for leaving feedback&lt;/div&gt;
</pre>
</li>
</ol>
<p>We now have a non-functioning Feedback form appearing inside a modal when the Feedback tab is clicked.  A cancel button is there if they decide not too leave feedback after all.</p>
<p>By adding the ASP.NET Button control in the modal it will do a PostBack back to the page that can be handled in the Master Page’s code-behind.  In the button handler I add the logic to simply email the submitted form to a desired email.  See my <a href="http://blog.dahlindevelopment.com/2010/01/sending-email-on-rackspace-cloud-using-asp-net/" target="_blank">previous post</a> on how to do that.</p>
<p><img style="display: inline; border: 0px;" title="thankyou" src="http://blog.dahlindevelopment.com/wp-content/uploads/2010/02/thankyou_thumb.png" border="0" alt="thankyou" width="405" height="66" /></p>
<p>At the end of the Submit Button handler I have a Page Redirect that sends the visitor back to the page they are on.  Two reasons for this:</p>
<ol>
<li>In the redirect I pass a QueryString param to the page letting it know that Feedback has been submitted.  In the PageLoad of the Master Page I check for this param and if it is present display a Thank You at the top of the page.</li>
<li>Secondly I do a redirect so the visitor won’t do a refresh to get ride of the Thank You message, thus re-sending the feedback info again.</li>
</ol>
<pre class="brush: csharp; title: ; notranslate">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack &amp;&amp; !String.IsNullOrEmpty(Request.QueryString[&quot;fb&quot;]))
        {
            // the feedback form has been filled out, display a thank you message.
            thankyou.Visible = true;
        }
    }

    /// &lt;summary&gt;
    /// Handle the feedback form submit
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;sender&quot;&gt;&lt;/param&gt;
    /// &lt;param name=&quot;e&quot;&gt;&lt;/param&gt;
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // add the logic to handle the submited form fields

        string currentPage = Request.Path;
        Response.Redirect(currentPage + &quot;?fb=1&quot;);
    }
</pre>
<p>To sharpen it up a bit some final touches in the style sheet for the modal and the thank you message:</p>
<pre class="brush: css; title: ; notranslate">
.thankyoumessage{background-color:#cc0000; color:#fff; padding:20px; font-size:3em; text-align:center}
.modal{background-color:#fff; border:solid 3px gray; padding:8px; width:350px; height:450px;}
.modalbg{filter: Alpha(Opacity=70); -moz-opacity:0.7; opacity: 0.7; width: 100%; height: 100%; background-color: #000000; position: absolute; z-index: 500; top: 0px; left: 0px;}
</pre>
<p>I’ve put together a simple example website with all this working for <a href="http://blog.dahlindevelopment.com/downloads/feedback.zip">download here</a>.</p>
<p>There certainly is more that can be added upon this such as making the thank you message only visible for 3 seconds.  But, I think this is a good foundation.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.dahlindevelopment.com%2F2010%2F02%2Ffeedback-tab-widget-in-asp-net%2F&amp;title=Feedback%20tab%20widget%20in%20ASP.NET" id="wpa2a_10"><img src="http://blog.dahlindevelopment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.dahlindevelopment.com/2010/02/feedback-tab-widget-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sending email on Rackspace Cloud using asp.net</title>
		<link>http://blog.dahlindevelopment.com/2010/01/sending-email-on-rackspace-cloud-using-asp-net/</link>
		<comments>http://blog.dahlindevelopment.com/2010/01/sending-email-on-rackspace-cloud-using-asp-net/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 06:31:20 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Rackspace Cloud]]></category>

		<guid isPermaLink="false">http://blog.dahlindevelopment.com/?p=164</guid>
		<description><![CDATA[I have hosted with the Rackspace Cloud now for about two years.  I really couldn’t be happier with them and would recommend them to anyone.  The one thing I have seemed to have issues with is sending emails from my web applications. After talking with support and doing some testing I have a solution that [...]]]></description>
			<content:encoded><![CDATA[<p>I have hosted with the Rackspace Cloud now for about two years.  I really couldn’t be happier with them and would recommend them to anyone.  The one thing I have seemed to have issues with is sending emails from my web applications. After talking with support and doing some testing I have a solution that should last.</p>
<p>Here is an example of a basic contact form.</p>
<p>First set the smtp information in the web.config</p>
<pre class="brush: xml; title: ; notranslate">
&lt;system.net&gt;
 &lt;mailSettings&gt;
 &lt;smtp&gt;
 &lt;network host=&quot;mail.emailsrvr.com&quot; userName=&quot;info@mydomain.com&quot; password=&quot;mypassword&quot; port=&quot;25&quot;/&gt;
 &lt;/smtp&gt;
 &lt;/mailSettings&gt;
 &lt;/system.net&gt;
</pre>
<p>I put this at the very bottom of the web.config just before the closing tag.</p>
<p>Note that the userName and password must be of a valid email address of the domain you are sending from. Make sure to set this up through their control panel.</p>
<p>I also add in the appSettings of the web.config the email addresses of whom to send it to and the subject line. Just best practices.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;appSettings&gt;
 &lt;add key=&quot;mailTo&quot; value=&quot;joel@mydomain.com&quot;/&gt;
 &lt;add key=&quot;mailSubject&quot; value=&quot;Contact Form inquiry&quot;/&gt;
 &lt;/appSettings&gt;
</pre>
<p>Now my example is of an asp.net web application in c#. I am going to assume everyone knows how to setup the page, lets go to the code-behind.</p>
<p>You will need to add these three lines to your using block.</p>
<pre class="brush: csharp; title: ; notranslate">
using System.Web.Configuration;
using System.Text;
using System.Net.Mail;
</pre>
<pre>The submit button handler:</pre>
<pre class="brush: csharp; title: ; notranslate">
 /// &lt;summary&gt;
 /// Handles the contact form submit
 /// &lt;/summary&gt;
 /// &lt;param name=&quot;sender&quot;&gt;&lt;/param&gt;
 /// &lt;param name=&quot;e&quot;&gt;&lt;/param&gt;
 protected void imtbtnSubmit_Click(object sender, ImageClickEventArgs e)
 {
 StringBuilder body = new StringBuilder();
 body.AppendFormat(&quot;Company Name: {0}{1}&quot;, txtCompany.Text, Environment.NewLine);
 body.AppendFormat(&quot;Contact Name: {0}{1}&quot;, txtName.Text, Environment.NewLine);
 body.AppendFormat(&quot;Phone: {0}{1}&quot;, txtPhone.Text, Environment.NewLine);
 body.AppendFormat(&quot;Email: {0}{1}&quot;, txtEmail.Text, Environment.NewLine);
 body.AppendLine();
 body.AppendLine(&quot;Message&quot;);
 body.AppendLine(txtMessage.Text);

 MailMessage message = new MailMessage(txtEmail.Text, WebConfigurationManager.AppSettings[&quot;mailTo&quot;], WebConfigurationManager.AppSettings[&quot;mailSubject&quot;], body.ToString());

 SmtpClient client = new SmtpClient();
 client.Send(message);

 pnlForm.Visible = false;
 lblMessage.Visible = true;
 }
</pre>
<p>Pretty simple stuff, the import part is system.net in the web.config, making sure you have the correct host and port  and a valid email.</p>
<p>You would think they would have this in their knowledge base, but as of this writing they don&#8217;t. I hope this helps someone.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.dahlindevelopment.com%2F2010%2F01%2Fsending-email-on-rackspace-cloud-using-asp-net%2F&amp;title=Sending%20email%20on%20Rackspace%20Cloud%20using%20asp.net" id="wpa2a_12"><img src="http://blog.dahlindevelopment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.dahlindevelopment.com/2010/01/sending-email-on-rackspace-cloud-using-asp-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Keep mulitple ListViews on the same page.</title>
		<link>http://blog.dahlindevelopment.com/2009/12/keep-mulitple-listviews-on-the-same-page/</link>
		<comments>http://blog.dahlindevelopment.com/2009/12/keep-mulitple-listviews-on-the-same-page/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 17:44:27 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.dahlindevelopment.com/?p=149</guid>
		<description><![CDATA[I just had a project that required me to have a list of articles both in the the left nav and main content area. In the left nav is was just a list of the titles.  The titles were links to anchors in the main page since the actual articles were a bit lengthy. The [...]]]></description>
			<content:encoded><![CDATA[<p>I just had a project that required me to have a list of articles both in the the left nav and main content area.</p>
<p>In the left nav is was just a list of the titles.  The titles were links to anchors in the main page since the actual articles were a bit lengthy.</p>
<p>The client only wanted 5 articles to be displayed per page.  So paging was needed.  I used two separate ListViews to display the news items.  Along with that each ListView had a  DataPager to handle the paging.</p>
<p>The trick was if a user clicked on page 2 in the left nav how would we update the main content ListView to move to page 2 as well?</p>
<p>To accomplish this I accessed the PagePropertiesChanging handler and updated both DataPager PageProperties.</p>
<p>So if a user clicked in the left nav the code-behind is:</p>
<pre class="brush: csharp; title: ; notranslate">
protected void lvLeftNav_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
    dpNews.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
    dpLeftNav.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
    BindNews();
 }
</pre>
<p>As you see I update both DataPagers.</p>
<p>Here is the code-behind for the main news content code-behind:</p>
<pre class="brush: csharp; title: ; notranslate">
protected void lvNews_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
    dpNews.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
    dpLeftNav.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
    BindNews();
}
</pre>
<p>I should mention that the BindNews() method handles binding both the Left Nav and Main News to the same News List&lt;News&gt;.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.dahlindevelopment.com%2F2009%2F12%2Fkeep-mulitple-listviews-on-the-same-page%2F&amp;title=Keep%20mulitple%20ListViews%20on%20the%20same%20page." id="wpa2a_14"><img src="http://blog.dahlindevelopment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.dahlindevelopment.com/2009/12/keep-mulitple-listviews-on-the-same-page/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Search Results &#8211; Webpage has expired on back button</title>
		<link>http://blog.dahlindevelopment.com/2009/12/search-results-webpage-has-expired-on-back-button/</link>
		<comments>http://blog.dahlindevelopment.com/2009/12/search-results-webpage-has-expired-on-back-button/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 18:34:05 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.dahlindevelopment.com/?p=143</guid>
		<description><![CDATA[I’ve been asked this a few times now so I thought I would blog my solution to point others to this next time I am asked. Often times people will create a simple search on their site. The most obvious way to do this is with a simple textbox and button.  You then handle the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.dahlindevelopment.com/wp-content/uploads/2009/12/search.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="search" src="http://blog.dahlindevelopment.com/wp-content/uploads/2009/12/search_thumb.png" border="0" alt="search" width="244" height="31" /></a></p>
<p>I’ve been asked this a few times now so I thought I would blog my solution to point others to this next time I am asked.</p>
<p>Often times people will create a simple search on their site. The most obvious way to do this is with a simple textbox and button.  You then handle the search when the button is clicked in the code-behind.</p>
<p>It may look something like this:</p>
<pre class="brush: csharp; title: ; notranslate">
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(txtSearch.Text.Trim()))
        {
            BindSearch(txtSearch.Text.Trim());
        }
    }
</pre>
<p>Pretty straight forward.  The problem here is you’re doing a postback to the same page.  You won’t have a history of the previous searches in your browser. After doing a search and you want to see what you had for results from the previous search and simply hit back in your browser you’ll see this</p>
<p><a href="http://blog.dahlindevelopment.com/wp-content/uploads/2009/12/expired.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="expired" src="http://blog.dahlindevelopment.com/wp-content/uploads/2009/12/expired_thumb.png" border="0" alt="expired" width="473" height="182" /></a></p>
<p>So what I have always done to avoid this is to simply do a Response.Redirect to the page instead of just calling the BindSearch() method and put the search term in the query string.</p>
<pre class="brush: csharp; title: ; notranslate">
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(txtSearch.Text.Trim()))
        {
            Response.Redirect(&quot;/Search.aspx?search=&quot; + txtSearch.Text.Trim());
        }
    }
</pre>
<p>This is a pretty simple solution, does anyone else have a different way to handle this?</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.dahlindevelopment.com%2F2009%2F12%2Fsearch-results-webpage-has-expired-on-back-button%2F&amp;title=Search%20Results%20%26ndash%3B%20Webpage%20has%20expired%20on%20back%20button" id="wpa2a_16"><img src="http://blog.dahlindevelopment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.dahlindevelopment.com/2009/12/search-results-webpage-has-expired-on-back-button/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Controls not being registered in designer.cs</title>
		<link>http://blog.dahlindevelopment.com/2009/08/controls-not-being-registered-in-designer-cs/</link>
		<comments>http://blog.dahlindevelopment.com/2009/08/controls-not-being-registered-in-designer-cs/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 03:10:49 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.dahlindevelopment.com/?p=94</guid>
		<description><![CDATA[I’ve encountered this a few times now. When dealing with a webform with an extraordinary amount of controls, ie. textboxes, dropdownlists, panels, etc. I’ve noticed that after x amount of controls have been added they are no longer registered in the designer.cs file.&#160; I notice this by first the control not showing up in intellisense [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve encountered this a few times now. </p>
<p>When dealing with a webform with an extraordinary amount of controls, ie. textboxes, dropdownlists, panels, etc. I’ve noticed that after x amount of controls have been added they are no longer registered in the designer.cs file.&#160; </p>
<p>I notice this by first the control not showing up in intellisense when trying to use it in code-behind.&#160; If I manually type it out I will still get a build error.&#160; </p>
<p>So, at this point I have to manually register any new controls in the designer.cs file.&#160; At the top of the file it says, </p>
<blockquote><p><em>//&#160;&#160;&#160;&#160; Changes to this file may cause incorrect behavior and will be lost if       <br />//&#160;&#160;&#160;&#160; the code is regenerated.</em></p>
</blockquote>
<p>However it seems that they are never lost and now everything works fine.&#160; I am not sure if this is normal behavior and this is what you are suppose to do, but so far it has worked for me.</p>
<p>Has anyone else seen this, does anyone know the exact amount of controls that you can add to a page before they are no longer registered in the designer.cs?</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.dahlindevelopment.com%2F2009%2F08%2Fcontrols-not-being-registered-in-designer-cs%2F&amp;title=Controls%20not%20being%20registered%20in%20designer.cs" id="wpa2a_18"><img src="http://blog.dahlindevelopment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.dahlindevelopment.com/2009/08/controls-not-being-registered-in-designer-cs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

