<?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>Dot Net Thoughts &#187; ASP.Net</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>thoughts about .Net, WPF, Sharepoint, Javascript and more.</description>
	<lastBuildDate>Wed, 28 Jul 2010 09:59:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>FileNot Found exception &#8211; Application_Error event in Global.asax</title>
		<link>http://www.dotnetthoughts.net/2010/07/28/filenot-found-exception-application_error-event-in-global-asax/</link>
		<comments>http://www.dotnetthoughts.net/2010/07/28/filenot-found-exception-application_error-event-in-global-asax/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 09:59:26 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Application_Error]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[File Not Found]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1017</guid>
		<description><![CDATA[Today I got a problem from my colleague, that he is getting FileNot Found exception in Application Error event in Global.asax, which is used to log application errors. But the application was working fine and good. We thought it may be because of missing images that was referring in Stylesheets. But all the image references [...]]]></description>
			<content:encoded><![CDATA[<p>Today I got a problem from my colleague, that he is getting FileNot Found exception in Application Error event in Global.asax, which is used to log application errors. But the application was working fine and good. We thought it may be because of missing images that was referring in Stylesheets. But all the image references are valid and we couldn&#8217;t find any issue. We couldn&#8217;t find anything suspicious in stack trace.</p>
<p>Stack Trace from the exception</p>
<blockquote><p>   at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)<br />
   at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context)<br />
   at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)<br />
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()<br />
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&#038; completedSynchronously)</p></blockquote>
<p>After doing some search we got an option where we can find the file causing the exception. We created a string variable and put a break point over there and debugged the code. It will display the filename causing the exception. In our case it was a HTML file which was used in a Javascript to set an IFRAME source, unfortunately the developer who copied the script missed the HTML and it was causing the exception. </p>
<p>Here is the code.</p>
<pre class="brush: csharp;">
void Application_Error(object sender, EventArgs e)
{
Exception err = Server.GetLastError();
//Insert a break point and run in debug mode.
string fileName = Context.Request.FilePath;
 Application[&quot;UnhandledException&quot;] = err;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/07/28/filenot-found-exception-application_error-event-in-global-asax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selecting controls using LINQ</title>
		<link>http://www.dotnetthoughts.net/2010/07/19/selecting-controls-using-linq/</link>
		<comments>http://www.dotnetthoughts.net/2010/07/19/selecting-controls-using-linq/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 09:35:01 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1007</guid>
		<description><![CDATA[One of my colleague asked how to get all the text boxes with no text entered in Windows form without using a For Loop. I thought of writing it with LINQ. And here is my implementation. var controls = from control in this.Controls select control; But this will generate a compile time error &#8211; Could [...]]]></description>
			<content:encoded><![CDATA[<p>One of my colleague asked how to get all the text boxes with no text entered in Windows form without using a For Loop. I thought of writing it with LINQ. And here is my implementation. </p>
<pre class="brush: csharp;">
 var controls = from control in this.Controls
                           select control;
</pre>
<p>But this will generate a compile time error &#8211; <em>Could not find an implementation of the query pattern for source type &#8216;System.Windows.Forms.Control.ControlCollection&#8217;.  &#8216;Select&#8217; not found.  Consider explicitly specifying the type of the range variable &#8216;control&#8217;.</em> But the error was self explanatory, I need to specify the type of the control. And here is the modified version.</p>
<pre class="brush: csharp;">
var controls = from Control control in this.Controls
                           select control;
</pre>
<p>And if you want to select specific type of controls you need to apply a where condition.</p>
<pre class="brush: csharp;">
var textboxes = from Control textbox in this.Controls
                where textbox is TextBox
                select textbox;
</pre>
<p>There is some other inbuilt operators is also available to select specific controls, like OfType()</p>
<pre class="brush: csharp;">
var textboxes = from textbox in this.Controls.OfType&lt;TextBox&gt;()
                select textbox;
</pre>
<p>In this method we don&#8217;t need to specify the type of the control in the from statement. And one of interesting LINQ extension method is the Cast&lt;&gt; method, which helps to enable the standard query operators to be invoked on non-generic collections by supplying the necessary type information. You can get more information from <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/bb341406.aspx">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/07/19/selecting-controls-using-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dropdownlist FindByText Problem</title>
		<link>http://www.dotnetthoughts.net/2010/07/15/dropdownlist-findbytext-problem/</link>
		<comments>http://www.dotnetthoughts.net/2010/07/15/dropdownlist-findbytext-problem/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 12:35:03 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[FindByText Problem]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1001</guid>
		<description><![CDATA[Today one of my colleague talked about a simple basic issue with Dropdownlist, the FindByText() method works as case sensitive. Because of this issue, we are getting some exceptions. So I starting looking for alternatives and one way I found it looping the items and compare it. Like the following. this.ddlItems.SelectedIndex = -1; foreach (ListItem [...]]]></description>
			<content:encoded><![CDATA[<p>Today one of my colleague talked about a simple basic issue with Dropdownlist, the FindByText() method works as case sensitive. Because of this issue, we are getting some exceptions. So I starting looking for alternatives and one way I found it looping the items and compare it. Like the following.</p>
<pre class="brush: csharp;">
this.ddlItems.SelectedIndex = -1;
foreach (ListItem item in this.ddlItems.Items)
{
    if (item.Text.Equals(&quot;Item&quot;, StringComparison.CurrentCultureIgnoreCase))
    {
        item.Selected = true;
        break;
    }
}
</pre>
<p>It is a nice option, I rewrote it as an extension method and works fine. Later I thought of wrting more generic FindByTextMethod() and here the extension method.</p>
<pre class="brush: csharp;">
/// &lt;summary&gt;
/// Searches the Collection of ListItem with a ListItem.Text property contains the specified text
/// &lt;/summary&gt;
/// &lt;param name=&quot;items&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;text&quot;&gt;The text to search for.&lt;/param&gt;
/// &lt;param name=&quot;stringComparison&quot;&gt;One of the System.StringComparison values.&lt;/param&gt;
/// &lt;returns&gt;ListItem if the collection contains the text, null otherwise.&lt;/returns&gt;
public static ListItem FindByText(this ListItemCollection items,
    string text,
    StringComparison comparisonType)
{
    ListItem result = items.OfType&lt;ListItem&gt;().
        FirstOrDefault(_string =&gt; _string.Text.Equals(text, comparisonType));
    return result;
}
</pre>
<p>And you can use it like this</p>
<pre class="brush: csharp;">
this.ddlItems.Items.FindByText(&quot;Item&quot;, StringComparison.CurrentCultureIgnoreCase).Selected = true;
</pre>
<p>Happy Coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/07/15/dropdownlist-findbytext-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing ASP.Net Forms Authentication with Active Directory Membership Provider</title>
		<link>http://www.dotnetthoughts.net/2010/06/29/implementing-asp-net-forms-authentication-with-active-directory-membership-provider/</link>
		<comments>http://www.dotnetthoughts.net/2010/06/29/implementing-asp-net-forms-authentication-with-active-directory-membership-provider/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 07:52:28 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Active Directory Authentication]]></category>
		<category><![CDATA[ASP.Net Handler]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=958</guid>
		<description><![CDATA[ActiveDirectoryMembership provider is used manage users against Active Directory, which helps to create Single Sign On for intranet application. Here is a basic implementation, which used to Authenticate users against Active Directory, using Login Control. We need to modify the web.config, like the implementation of Forms Authentication in ASP.Net. Create / Add a connection string [...]]]></description>
			<content:encoded><![CDATA[<p>ActiveDirectoryMembership provider is used manage users against Active Directory, which helps to create Single Sign On for intranet application. Here is a basic implementation, which used to Authenticate users against Active Directory, using Login Control.</p>
<p>We need to modify the web.config, like the implementation of Forms Authentication in ASP.Net.</p>
<p>Create / Add a connection string to active directory database.</p>
<pre class="brush: xml;">
&lt;connectionStrings&gt;
&lt;add name=&quot;ADConnectionString&quot; connectionString=&quot;LDAP://DOMAIN.SUBDOMAIN/DC=DOMAIN,DC= SUBDOMAIN &quot;/&gt;
&lt;/connectionStrings&gt;
</pre>
<p>Configure Membership node in the web.config with ActiveDirectoryMembershipProvider.</p>
<pre class="brush: xml;">
&lt;membership defaultProvider=&quot;MembershipADProvider&quot;&gt;
  &lt;providers&gt;
    &lt;add name=&quot;MembershipADProvider&quot;
         type=&quot;System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot;
         applicationName=&quot;dotnetthoughts&quot;
         connectionStringName=&quot; ADConnectionString &quot;
         attributeMapUsername=&quot;sAMAccountName&quot;/&gt;
  &lt;/providers&gt;
&lt;/membership&gt;
</pre>
<p>You can also provide the Username / Password in this using connectionUsername , connectionPassword attributes.</p>
<p>Modify the Authentication mode and Authorization nodes for controlling the access permissions. Currently I am using Forms Authentication defaults. (default.aspx &#8211; Home Page, and Login.aspx &#8211; Login Page)</p>
<pre class="brush: xml;">
&lt;authentication mode=&quot;Forms&quot; /&gt;
&lt;authorization&gt;
    &lt;deny users=&quot;?&quot; /&gt;
    &lt;allow users=&quot;*&quot; /&gt;
&lt;/authorization&gt;
</pre>
<p>Almost done. Now drag and drop Login control from Toolbox > Login tab to Login.aspx. Run the application, say OK to the Debug mode confirmation from Visual Studio. As we are configured the Authentication provider we don’t need to write any Code to Authentication.</p>
<p>If you don&#8217;t want to use login control, you can do something like this in the code behind for the authentication.</p>
<pre class="brush: csharp;">
if (Membership.ValidateUser(this.txtUsername.Text, this.txtPassword.Text))
{
    FormsAuthentication.RedirectFromLoginPage(this.txtUsername.Text, false);
}
else
{
    Response.Write(&quot;Authentication failed.\nUsername / Password Invalid&quot;);
}
</pre>
<p>Thanks to Sreenaja for the initial implementation. Happy Coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/06/29/implementing-asp-net-forms-authentication-with-active-directory-membership-provider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.Net Default button and Master Pages</title>
		<link>http://www.dotnetthoughts.net/2010/06/21/asp-net-default-button-and-master-pages/</link>
		<comments>http://www.dotnetthoughts.net/2010/06/21/asp-net-default-button-and-master-pages/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 07:33:34 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[BackToBasics]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=908</guid>
		<description><![CDATA[Last few days I was(am) busy with one pure ASP.Net application(why its pure because we are not using any 3rd party controls, ajax nothing. Everything is postbacking ). Today I got a weird bug from one of my QC team saying when ever they presses ENTER button, focus is on any textbox, it popups Help [...]]]></description>
			<content:encoded><![CDATA[<p>Last few days I was(am) busy with one pure ASP.Net application(why its pure because we are not using any 3rd party controls, ajax nothing. Everything is postbacking <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ). Today I got a weird bug from one of my QC team saying when ever they presses ENTER button, focus is on any textbox, it popups Help window from our application. In our application, end users can open the Help window, by clicking on some help images icons provided in the application. These images are displayed using ASP Image button controls (If you are using ASP Image controls this problem will not occur, but in our application, we need to disable it some scenarios, so can&#8217;t use ASP Image). After searching I found the issue with the default button property of ASP.Net, which helps us to submit the form using Enter Key. In my page ASP.Net considering the Help image button as default button for the Page. We can set the default button to our submit button using various methods. Set the default button property of the FORM, or create a Panel control over the controls and set the default button property of the Panel.</p>
<pre class="brush: xml;">
&lt;form id=&quot;form1&quot; runat=&quot;server&quot; defaultbutton=&quot;cmdSubmit&quot;&gt;
&lt;asp:Panel runat=&quot;server&quot; ID=&quot;plMain&quot; DefaultButton=&quot;cmdSubmit&quot;&gt;
</pre>
<p>Form tag also supports  &#8220;defaultfocus&#8221; this property allows to focus to control, on Page Load.</p>
<pre class="brush: xml;">
&lt;form id=&quot;form1&quot; runat=&quot;server&quot; defaultbutton=&quot;cmdSubmit&quot; defaultfocus=&quot;txtUser&quot;&gt;
</pre>
<p>If you are using Master Pages, there will be some slight difference because, the Form tag will not be available in the content Pages. It can fix using code behind, using FindControl method.</p>
<pre class="brush: csharp;">
(Page.Master.FindControl(&quot;Form1&quot;) as HtmlForm).DefaultButton = this.cmdSubmit.UniqueID;
</pre>
<p>Also you can do something like this</p>
<pre class="brush: csharp;">
Page.Master.Page.Form.DefaultButton = cmdSubmit.UniqueID;
</pre>
<p>Happy Coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/06/21/asp-net-default-button-and-master-pages/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Pass your own arguments to the ClientValidationFunction in a CustomValidator</title>
		<link>http://www.dotnetthoughts.net/2010/05/30/pass-your-own-arguments-to-the-clientvalidationfunction-in-a-customvalidator/</link>
		<comments>http://www.dotnetthoughts.net/2010/05/30/pass-your-own-arguments-to-the-clientvalidationfunction-in-a-customvalidator/#comments</comments>
		<pubDate>Sun, 30 May 2010 09:41:04 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[C#.Net]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=896</guid>
		<description><![CDATA[Last few days I am working on an ASP.Net, where I can create Grids, Dropdown lists with Post back , and the best part is browser compatibility, client only requires compatible with IE. Yes it was a refresher course for me, I revisited GridView templates, Page.IsPostback checking etc. Today I got a requirement like I [...]]]></description>
			<content:encoded><![CDATA[<p>Last few days I am working on an ASP.Net, where I can create Grids, Dropdown lists with Post back <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , and the best part is browser compatibility, client only requires compatible with IE. Yes it was a refresher course for me, I revisited GridView templates, Page.IsPostback checking etc. Today I got a requirement like I need to validate few radio buttons. I searched for an implementation, I found we can use required field validator for RadioButtonList, but in my case it was Radio buttons (Initially it was RadioButtonList, but due to some customization issues, I changed it to Radio Buttons). Then I implemented a custom validator, and in the client validation function I hardcoded the Radio Button ids, because for the client validation function we can&#8217;t pass the parameters to the function. Same problem again I faced in a GridView, where the problem I found was I won&#8217;t get the client id of the radio button in the Item template. <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  After doing some research I found we can extend the custom validator control using Validation Framework. And here is the implementation. Using this we can add properties to the source / sender parameter in the client side validation function.</p>
<pre class="brush: jscript;">
function ValidateRadioButtons(source, arguments) {
    var radio1 = document.getElementById(source.Radio1);
    var radio2 = document.getElementById(source.Radio2);
    var radio4 = document.getElementById(source.Radio4);
    var radio3 = document.getElementById(source.Radio3);
    var result = radio1.checked || radio2.checked || radio3.checked || radio4.checked;
    arguments.IsValid = result;
}
</pre>
<p>This is the JavaScript function which implements the validation logic. You can get the controls as part of the Source object. To get the Source.Radio1, you need to register the Radio1 as ClientValidator attribute. You can do some C# code like this.</p>
<pre class="brush: csharp;">
protected void Page_Load(object sender, EventArgs e)
{
    this.Page.ClientScript.RegisterExpandoAttribute(customCheck.ClientID, &quot;Radio1&quot;, this.radio1.ClientID, false);
    this.Page.ClientScript.RegisterExpandoAttribute(customCheck.ClientID, &quot;Radio2&quot;, this.radio2.ClientID, false);
    this.Page.ClientScript.RegisterExpandoAttribute(customCheck.ClientID, &quot;Radio3&quot;, this.radio3.ClientID, false);
    this.Page.ClientScript.RegisterExpandoAttribute(customCheck.ClientID, &quot;Radio4&quot;, this.radio4.ClientID, false);
}
</pre>
<p>And the ASPX Code is like this</p>
<pre class="brush: xml;">
&lt;asp:CustomValidator runat=&quot;server&quot; ID=&quot;customCheck&quot; ClientValidationFunction=&quot;ValidateRadioButtons&quot;
        ErrorMessage=&quot;Choose any option&quot; /&gt;
</pre>
<p>And here is the Output code generated for the custom validator.</p>
<div id="attachment_899" class="wp-caption aligncenter" style="width: 304px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/05/custom_validator_rendering.png"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2010/05/custom_validator_rendering.png" alt="Custom validator output rendering" title="Custom validator output rendering" width="294" height="68" class="size-full wp-image-899" /></a><p class="wp-caption-text">Custom validator output rendering</p></div>
<p>Happy Coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/05/30/pass-your-own-arguments-to-the-clientvalidationfunction-in-a-customvalidator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
