<?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>Eclipsed4utoo&#039;s Blog&#187; ASP.Net</title>
	<atom:link href="http://eclipsed4utoo.com/blog/tag/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://eclipsed4utoo.com/blog</link>
	<description>Not Your Ordinary Programmer</description>
	<lastBuildDate>Thu, 08 Sep 2011 17:09:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ASP.Net &#8211; Forms Based Authentication With Textboxes</title>
		<link>http://eclipsed4utoo.com/blog/aspnet-forms-based-authentication-textboxes/</link>
		<comments>http://eclipsed4utoo.com/blog/aspnet-forms-based-authentication-textboxes/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 23:00:39 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[authentication]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=678</guid>
		<description><![CDATA[There are a number of different ways to do Forms Authentication in ASP.Net. In this tutorial, we will deal with Forms Authentication using two standard TextBoxes. So first, we are going to create a new ASP.Net application project. You can give it whatever name you want to. Once the project has been created, we will [...]]]></description>
			<content:encoded><![CDATA[<p>There are a number of different ways to do Forms Authentication in ASP.Net. In this tutorial, we will deal with Forms Authentication using two standard TextBoxes.</p>
<p>So first, we are going to create a new ASP.Net application project. You can give it whatever name you want to.</p>
<p>Once the project has been created, we will need to add a new <strong>WebForm</strong> to the project. This is done by right-clicking on the project &#8211;&gt; Add &#8211;&gt; New Item&#8230; &#8211;&gt; WebForm</p>
<p><img class="alignnone size-full wp-image-679" title="1" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2011/07/1.png" alt="1" width="638" height="355" /></p>
<p>Next, we are going to simply add 3 <strong>Labels</strong>, 2 <strong>Textboxes</strong>, and a <strong>Button</strong>. Here is the markup&#8230;</p>
<pre class="brush: csharp;">&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    &lt;div&gt;
        &lt;table&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;asp:Label ID=&quot;label1&quot; runat=&quot;server&quot; Text=&quot;Username:&quot; /&gt;
                &lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:TextBox ID=&quot;txtUserName&quot; runat=&quot;server&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;asp:Label ID=&quot;label2&quot; runat=&quot;server&quot; Text=&quot;Password:&quot; /&gt;
                &lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:TextBox ID=&quot;txtPassword&quot; runat=&quot;server&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;asp:Button ID=&quot;btnLogin&quot; runat=&quot;server&quot; Text=&quot;Login&quot; onclick=&quot;btnLogin_Click&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;asp:Label ID=&quot;lblInformation&quot; runat=&quot;server&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
</pre>
<p>Just a really simply form with a textbox for the Username and Password. The third label will be used to show an error if the login fails.</p>
<p>Next, we are going to have our login code&#8230;</p>
<pre class="brush: csharp;">public partial class Login : System.Web.UI.Page
{
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        bool validLogin = false;

        validLogin = IsValidUser(txtUserName.Text.Trim(), txtPassword.Text.Trim());

        if (validLogin)
            // this will redirect the user back to the page they were originally trying to visit.
            //   if the user came directly to the Login page, it will redirect to the &quot;defaultURL&quot; from
            //   the web.config
            FormsAuthentication.RedirectFromLoginPage(txtUserName.Text.Trim(), false);
        else
            // not a valid login
            lblInformation.Text = &quot;Incorrect Login Information&quot;;
    }

    private bool IsValidUser(string userName, string password)
    {
        // this is a very simple example where I am looking for this exact
        //   user name and password.  This could be any type of validation.
        if (userName == &quot;admin&quot; &amp;&amp; password == &quot;password&quot;)
            return true;
        else
            return false;
    }
}</pre>
<p>The <strong>FormsAuthentication.RedirectFromLoginPage</strong> method will redirect users to the page they were trying to visit before they were redirected to the Login page. If they came directly to the login page, this code will redirect them to the <strong>defaultUrl </strong>from the <strong>web.config</strong>.</p>
<p>We now need to make some changes to the <strong>web.config</strong> file.</p>
<pre class="brush: csharp;">&lt;system.web&gt;
  &lt;!-- some other attributes --&gt;

  &lt;authentication mode=&quot;Forms&quot;&gt;
    &lt;forms
      name=&quot;.LOGIN&quot;
      loginUrl=&quot;Login.aspx&quot;
      defaultUrl=&quot;Default.aspx&quot; /&gt;
  &lt;/authentication&gt;

  &lt;authorization&gt;
    &lt;deny users=&quot;?&quot;/&gt;
  &lt;/authorization&gt;
&lt;/system.web&gt;</pre>
<p>Some explanation about some of the <strong>authentication </strong>attributes:</p>
<p><strong>name </strong>- this can really be anything.<br />
<strong>loginUrl </strong>- this is the page where the user will be redirect to when they are not authenticated.<br />
<strong>defaultUrl </strong>- this is the page that the user will be redirected to after authentication IF they came directly to the login page.</p>
<p>There are other attributes, but these are the only necessary ones.</p>
<p>The <strong>&lt;deny users=&#8221;?&#8221;/&gt;</strong> means to deny all non-authenticated users. So anybody who is not authenticated will be redirected to the login page.</p>
<p>Now, on our <strong>Default.aspx</strong> page, we are simply going to add a label that will display the user name that logged in.</p>
<pre class="brush: csharp;">&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    &lt;div&gt;
        &lt;asp:Label ID=&quot;lblUserDisplay&quot; runat=&quot;server&quot; /&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;</pre>
<p>And the code for the <strong>Default.aspx </strong>page is just as simple&#8230;</p>
<pre class="brush: csharp;">public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblUserDisplay.Text = &quot;Hello &quot; + User.Identity.Name;
    }
}</pre>
<p>Now, if you set the <strong>Login.aspx</strong> page as the Startup page in Visual Studio(right-click on page &#8211;&gt; Set As Startup Page) then start debugging, you will see the login screen come up. Put in &#8220;admin&#8221; for the user name, and &#8220;password&#8221; for the password, then hit the Login button, you will now be redirected to the defaultUrl(most likely the default.aspx page). You will also notice that you are greeted with a message.</p>
<p>Now, add a third <strong>WebForm </strong>to the project. This will be just a dummy form. Set it as the startup page, then run the project. You will now be redirected to the Login page, and after logging in, you will be redirected back to the dummy page.</p>
<p>This is only one way to do Forms Authentication in ASP.Net.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/aspnet-forms-based-authentication-textboxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.Net &#8211; AJAX and an External Javascript File</title>
		<link>http://eclipsed4utoo.com/blog/aspnet-ajax-external-javascript-file/</link>
		<comments>http://eclipsed4utoo.com/blog/aspnet-ajax-external-javascript-file/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 22:00:44 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[javacript]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=264</guid>
		<description><![CDATA[Recently, I needed to add a color picker to a web application.  I thought I would try the new AJAX toolkit, but the toolkit was full of issues so I had to resort to doing it with javascript.  I downloaded a color picker that somebody had done(and donated for their development). When I went to [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I needed to add a color picker to a web application.  I thought I would try the new AJAX toolkit, but the toolkit was full of issues so I had to resort to doing it with javascript.  I downloaded a color picker that somebody had done(and donated for their development).</p>
<p>When I went to add the external javascript file and the other associated files, my AJAX page would no longer show up.  Anything inside of an UpdatePanel would not show up.  I did some searching and found that using an external javascript file can cause AJAX to fail.</p>
<p>I originally had this code which was giving me issues.</p>
<pre class="brush: xml;">
&lt;asp:Content ID=&quot;Content1&quot; ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;&gt;
    &lt;asp:ScriptManagerProxy ID=&quot;ScriptManagerProxy1&quot; runat=&quot;server&quot; /&gt;
    &lt;script src=&quot;../Javascript/jscolor/jscolor.js&quot; type=&quot;text/javascript&quot; /&gt;

    &lt;asp:UpdatePanel ID=&quot;UpdatePanel1&quot; runat=&quot;server&quot;&gt;
       &lt;%--   some controls  --%&gt;
    &lt;/asp:UpdatePanel&gt;
&lt;/asp:Content&gt;
</pre>
<p>I used the <strong>ScriptReference </strong>in the <strong>ScriptManagerProxy</strong> to add a reference to the javascript file:</p>
<pre class="brush: xml;">
&lt;asp:Content ID=&quot;Content1&quot; ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;&gt;
    &lt;asp:ScriptManagerProxy ID=&quot;ScriptManagerProxy1&quot; runat=&quot;server&quot;&gt;
       &lt;Scripts&gt;
          &lt;asp:ScriptReference Path=&quot;~/Javascript/jscolor/jscolor.js&quot; /&gt;
       &lt;/Scripts&gt;
    &lt;/asp:ScriptManagerProxy&gt;

    &lt;asp:UpdatePanel ID=&quot;UpdatePanel1&quot; runat=&quot;server&quot;&gt;
       &lt;%--   some controls  --%&gt;
    &lt;/asp:UpdatePanel&gt;
&lt;/asp:Content&gt;
</pre>
<p>And that worked.  The controls inside the <strong>UpdatePanel</strong> now show up.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/aspnet-ajax-external-javascript-file/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ASP.Net &#8211; Closing page with Javascript without notification</title>
		<link>http://eclipsed4utoo.com/blog/aspnet-closing-page-javascript-notification/</link>
		<comments>http://eclipsed4utoo.com/blog/aspnet-closing-page-javascript-notification/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 01:52:54 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=201</guid>
		<description><![CDATA[This is a short post on closing an IE window from a button click. This is normally a simple task.  You could use code like this: // This code does not work in Firefox 3.5 or Chrome 3.0 protected void btnClose_Click(object sender, EventArgs e) { Response.Write(&#34;&#60;script language='javascript'&#62;window.close();&#60;/script&#62;&#34;); } And that would work&#8230;for the most part.  [...]]]></description>
			<content:encoded><![CDATA[<p>This is a short post on closing an IE window from a button click.</p>
<p>This is normally a simple task.  You could use code like this:</p>
<pre class="brush: csharp;">
// This code does not work in Firefox 3.5 or Chrome 3.0
protected void btnClose_Click(object sender, EventArgs e)
{
     Response.Write(&quot;&lt;script language='javascript'&gt;window.close();&lt;/script&gt;&quot;);
}
</pre>
<p>And that would work&#8230;for the most part.  Only in IE, you would be given this message..</p>
<p><img class="alignnone size-full wp-image-203" title="Image" src="http://eclipsed4utoo.com/blog/wp-content/uploads/2009/11/11-2-2009-2-25-49-PM.png" alt="Image" width="360" height="130" /></p>
<p>Now, if you wanted to get around that message, you could need to do this:</p>
<pre class="brush: csharp;">
// This code works in IE 7, Firefox 3.5, and Chrome 3.0
protected void btnClose_Click(object sender, EventArgs e)
{
     Response.Write(&quot;&lt;script language='javascript'&gt;window.open('','_self',''); window.close();&lt;/script&gt;&quot;);
}
</pre>
<p>This will no longer show the message and just close the window.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/aspnet-closing-page-javascript-notification/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.Net &#8211; AJAX with Continuous Progress Bar</title>
		<link>http://eclipsed4utoo.com/blog/aspnet-ajax-continuous-progress-bar/</link>
		<comments>http://eclipsed4utoo.com/blog/aspnet-ajax-continuous-progress-bar/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 17:31:16 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Progress Bar]]></category>
		<category><![CDATA[progressbar]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=133</guid>
		<description><![CDATA[I was recently asked about getting a Progress Bar to work in ASP.Net.  It didn&#8217;t need to be a progress bar that had a percentage, just something that would alert a user that something is happening behind the scenes. So I did some Google searching, and found tons of resources where people had created their [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently asked about getting a Progress Bar to work in ASP.Net.  It didn&#8217;t need to be a progress bar that had a percentage, just something that would alert a user that something is happening behind the scenes.</p>
<p>So I did some Google searching, and found tons of resources where people had created their own Progress Bar controls.  While that was all fine and good, I wasn&#8217;t looking to download somebody else&#8217;s custom control, and I wasn&#8217;t going to make my own.  So I wanted to figure out how I could use existing ASP.Net and AJAX controls to accomplish this task.</p>
<p>It turned out to be easier than I thought it would be.</p>
<p>I knew that I needed the progress bar to show modally, so that the user would not be able to interact with the form during the postback.  So I decided to use the <strong>ModalPopupExtender</strong> AJAX control.</p>
<p>So first, I have my <strong>Button</strong>, the <strong>ModalPopupExtender</strong>, the <strong>Panel</strong> that the extender will display, the <strong>Script Manager</strong>, and a <strong>hidden</strong> control.</p>
<pre class="brush: xml;">
&lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; /&gt;
&lt;asp:UpdatePanel ID=&quot;UpdatePanel1&quot; runat=&quot;server&quot;&gt;
    &lt;ContentTemplate&gt;
        &lt;div&gt;
            &lt;asp:Button ID=&quot;btnSubmit&quot; OnClick=&quot;btnSubmit_Click&quot; OnClientClick=&quot;StartProgressBar()&quot;
                     runat=&quot;server&quot; Text=&quot;Submit Time&quot; Width=&quot;170px&quot; /&gt;

            &lt;ajaxToolkit:ModalPopupExtender ID=&quot;ProgressBarModalPopupExtender&quot; runat=&quot;server&quot;
                     BackgroundCssClass=&quot;ModalBackground&quot; BehaviorID=&quot;ProgressBarModalPopupExtender&quot;
                     TargetControlID=&quot;hiddenField&quot; PopupControlID=&quot;Panel1&quot; /&gt;

            &lt;asp:Panel ID=&quot;Panel1&quot; runat=&quot;server&quot; Style=&quot;display: none; background-color: #C0C0C0;&quot;&gt;
                 &lt;img src=&quot;progressbar.gif&quot; alt=&quot;&quot; /&gt;
            &lt;/asp:Panel&gt;

            &lt;asp:HiddenField ID=&quot;hiddenField&quot; runat=&quot;server&quot; /&gt;
       &lt;/div&gt;
   &lt;/ContentTemplate&gt;
&lt;/asp:UpdatePanel&gt;
</pre>
<p>If you notice, the <strong>TargetControlID </strong>attribute of the extender is NOT the button.  The reason for this is that the default functionality of the <strong>ModalPopupExtender </strong>is to require a button click from the <strong>Panel </strong>to close it.  Since I want the <strong>Panel </strong>to stay visible while the server does it&#8217;s processing, I set the <strong>TargetControlID </strong>to the <strong>hidden </strong>control.</p>
<p>Another thing to notice is the <strong>BackgroundCssClass </strong>attribute of the <strong>ModalPopupExtender</strong>.  This is REQUIRED for the extender to actual be modal.  Without it, the extender is a non-modal popup.(more on this later)</p>
<p>Also notice that the <strong>Button </strong>has both of the click events populated.  The <strong>OnClick </strong>event will be the server-side event handler.</p>
<pre class="brush: csharp;">
protected void btnSubmit_Click(object sender, EventArgs e)
{
     Thread.Sleep(7000);
     ProgressBarModalPopupExtender.Hide();
}
</pre>
<p>This event simply pauses server processing for 7 seconds to simulate a long running process.</p>
<p>The <strong>OnClientClick </strong>event will be calling a javascript function&#8230;</p>
<pre class="brush: jscript;">
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
    function StartProgressBar() {
        var myExtender = $find('ProgressBarModalPopupExtender');
        myExtender.show();
        return true;
    }
&lt;/script&gt;
</pre>
<p>And last, the CSS entry for the background of the <strong>ModalPopupExtender</strong>.</p>
<p>If you do not already have a CSS class added to your project, you will need to add one, and link it to the page in the <strong>HEAD </strong>tag.</p>
<pre class="brush: xml;">
&lt;link href=&quot;main.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
<p>Then add this entry to the CSS file.</p>
<pre class="brush: xml;">
.ModalBackground
{
    background-color:Gray;

    filter:alpha(opacity=50);
    -moz-opacity:0.5;
    -khtml-opacity: 0.5;
    opacity: 0.5;
}
</pre>
<p>If using Visual Studio 2008, you will get warnings saying that &#8220;filter&#8221; and &#8220;opacity&#8221; are not known CSS properties.  This is an issue with Visual Studio.  They are valid properties and they do work.  The 4 properties that are listed in the CSS entry should handle the opacity for all major browsers.  I have tested with IE7, Firefox 3.5, and Chrome.</p>
<p>And that is all you have to do.  The <strong>ModalPopupExtender </strong>will show when the button is clicked, and the server will start processing the code.  When the server has completed and sends the response back to the browser, it will hide the <strong>ModalPopupExtender</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/aspnet-ajax-continuous-progress-bar/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>ASP.Net &#8211; Pushing File to Browser</title>
		<link>http://eclipsed4utoo.com/blog/aspnet-pushing-file-browser/</link>
		<comments>http://eclipsed4utoo.com/blog/aspnet-pushing-file-browser/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 16:25:20 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[SaveFileDialog]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=100</guid>
		<description><![CDATA[Here is a short snippet that will push/serve a file from the server to the browser for download. ****** NOTE ******* This will not work inside of an AJAX UpdatePanel.  If the code is called from a button click event, that button will need to be outside of any AJAX UpdatePanel. protected void DownloadFile(string fullFilePath) [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a short snippet that will push/serve a file from the server to the browser for download.</p>
<p><strong>****** NOTE *******<br />
This will not work inside of an AJAX UpdatePanel.  If the code is called from a button click event, that button will need to be outside of any AJAX UpdatePanel.</strong></p>
<pre class="brush: csharp;">
protected void DownloadFile(string fullFilePath)
{
      // Gets the File Name
      string fileName = fullFilePath.Substring(fullFilePath.LastIndexOf('\\') + 1);
      byte[] buffer;

      using (FileStream fileStream = new FileStream(fullFilePath, FileMode.Open))
      {
           int fileSize = (int)fileStream.Length;

           buffer = new byte[fileSize];

           // Read file into buffer
           fileStream.Read(buffer, 0, (int)fileSize);
      }

      Response.Clear();

      Response.Buffer = true;
      Response.BufferOutput = true;
      Response.ContentType = &quot;application/x-download&quot;;
      Response.AddHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=&quot; + fileName);
      Response.CacheControl = &quot;public&quot;;
      // writes buffer to OutputStream
      Response.OutputStream.Write(buffer, 0, buffer.Length);
      Response.End();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/aspnet-pushing-file-browser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.Net &#8211; Uploading File To Server</title>
		<link>http://eclipsed4utoo.com/blog/asp-net-uploading-file-to-server/</link>
		<comments>http://eclipsed4utoo.com/blog/asp-net-uploading-file-to-server/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 16:27:31 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Uploading Files]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=97</guid>
		<description><![CDATA[Here is a small snippet of code that will allow visitors to your website to upload files to your server. This code will open an OpenFileDialog box to allow the user to select a file. &#60;asp:TableCell&#62; Select File: &#60;input id=&#34;uplTheFile&#34; type=&#34;file&#34; runat=&#34;server&#34; style=&#34;width: 476px; height: 26px&#34; /&#62; &#60;/asp:TableCell&#62; This code will add a button to [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a small snippet of code that will allow visitors to your website to upload files to your server.</p>
<p>This code will open an OpenFileDialog box to allow the user to select a file.</p>
<pre class="brush: xml;">
&lt;asp:TableCell&gt;
     Select File:
     &lt;input id=&quot;uplTheFile&quot; type=&quot;file&quot; runat=&quot;server&quot; style=&quot;width: 476px; height: 26px&quot; /&gt;
&lt;/asp:TableCell&gt;
</pre>
<p>This code will add a button to the form to upload the file.</p>
<pre class="brush: xml;">
&lt;asp:TableCell&gt;
     &lt;asp:Button ID=&quot;cmdUploadFile&quot; value=&quot;Upload&quot; runat=&quot;server&quot; Text=&quot;Upload&quot; OnClick=&quot;cmdUploadFile_Click&quot; /&gt;
&lt;/asp:TableCell&gt;
</pre>
<p><strong>cmdUploadFile_Click</strong> Event</p>
<pre class="brush: csharp;">
protected void cmdUploadFile_Click(object sender, EventArgs e)
{
     string strFileNameOnServer = uplTheFile.PostedFile.FileName;
     string appDataPath = HttpContext.Current.Server.MapPath(&quot;~/App_Data&quot;);

     if (string.IsNullOrEmpty(strFileNameOnServer))
     {
           lblInformation.Text = &quot;Error - a file name must be specified.&quot;;
           return;
     }

     if (uplTheFile.PostedFile != null)
     {
          try
          {
               uplTheFile.PostedFile.SaveAs(appDataPath + &quot;\\&quot; + strFileNameOnServer);
          }
          catch (Exception ex)
          {
               lblInformation.Text = &quot;Error saving &lt;b&gt;&quot; + strFileNameOnServer + &quot;&lt;/b&gt;&lt;br&gt;.  &quot; + ex.Message;
          }
      }
}
</pre>
<p>This will upload the file into the <strong>App_Data</strong> folder of the website.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/asp-net-uploading-file-to-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.Net &#8211; Calling JavaScript from Code Behind</title>
		<link>http://eclipsed4utoo.com/blog/asp-net-calling-javascript-from-code-behind/</link>
		<comments>http://eclipsed4utoo.com/blog/asp-net-calling-javascript-from-code-behind/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 13:07:30 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=38</guid>
		<description><![CDATA[.Net gives us the ability to call javascript code from the code behind. This means that you don&#8217;t have to write the javascript code in the &#8220;Source&#8221; of the aspx page. Just for an example, let&#8217;s say that you have a button on a form that just want to popup an alert that says &#8220;HEY&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>.Net gives us the ability to call javascript code from the code behind. This means that you don&#8217;t have to write the javascript code in the &#8220;Source&#8221; of the aspx page.</p>
<p>Just for an example, let&#8217;s say that you have a button on a form that just want to popup an alert that says &#8220;HEY&#8221; when it is clicked.</p>
<pre class="brush: csharp;">
protected void btnHey_Click(object sender, EventArgs e)
{
     StringBuilder sb = new StringBuilder();
     sb.Append(&quot;&lt;script language='javascript'&gt;alert('HEY');&lt;/script&gt;&quot;);

     // if the script is not already registered
     if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), &quot;HeyPopup&quot;))
          ClientScript.RegisterClientScriptBlock(Page.GetType(), &quot;HeyPopup&quot;, sb.ToString());
}
</pre>
<p>To run a method that is already defined in the .aspx page, you would use similar code, but with one difference:</p>
<pre class="brush: csharp;">
// javascript method
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
    function ShowMessage(myMessage){
        alert(myMessage);
    }
&lt;/script&gt;

// C# code
protected void btnHey_Click(object sender, EventArgs e)
{
   StringBuilder sb = new StringBuilder();
   sb.Append(&quot;ShowMessage('hey');&quot;);

   // if the script is not already registered
   if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), &quot;HeyPopup&quot;))
       // notice that I added the boolean value as the last parameter
       ClientScript.RegisterClientScriptBlock(Page.GetType(), &quot;HeyPopup&quot;, sb.ToString(), true);
</pre>
<p>And it&#8217;s that simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/asp-net-calling-javascript-from-code-behind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

