Showing posts with label ASP.Net. Show all posts
Showing posts with label ASP.Net. Show all posts

Wednesday, February 3, 2021

window.location.href not working - asp.net

 window.location.href not working


If we are calling function through a submit button. This may be the reason why the browser does not redirect. It will run the code in the function and then submit the page instead of redirect. 

In this case Either
1. change the type tag of your button to button
        2. you just need to add "return false;" at the bottom of your function

Wednesday, January 15, 2020

System.InvalidCastException: 'Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'

System.InvalidCastException: 'Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'

 The error because the URL is not proper. please pass the proper url containing http:// or https://.

and also check that URL is correct.

Friday, April 12, 2019

RadTimePicker, showing error as " 'SelectedDate' should be between 'MinDate' and 'MaxDate'".

The default minimum date for the RadDatePicker is 01/01/1980. So, when you try to assign the value this than this date you will get the below error:


if you will set the Mindate of RadDatePicker to a minimum range than this will fix the issue

ID="RadDateofBirth" DateInput-DateFormat="dd/MM/yyyy" MinDate="01/01/1940" DateInput-DisplayDateFormat="dd/MM/yyyy" runat="server">

This will solved the issue.

Saturday, December 30, 2017

Redirect incoming requests to specific URLs in IIS 7


The Rule "aboutus" is redirect a specific page to a another page.

The Rule "legal" is to redirect the all html files from a folder to a specific page.
<system .webserver="">
        <rewrite>
          <rules>
            <rule name="aboutus">
              <match url="^about-us.html$"></match>
              <action type="Redirect" url="/index.html"></action>
            </rule>
            <rule name="Legal">
              <match url="^Legal/(.*).html$"></match>
              <action type="Redirect" url="/index.html"></action>
            </rule>
          </rules>
        </rewrite>
     </system>

Thursday, December 28, 2017

Upload Multiple Files Using FileUpload Control In ASP.NET 4.5 +

ASP.NET 4.5 and upper versions support this feature.

Now, FileUpload  control is built to support HTML 5, therefore it is only supported in browsers supporting HTML5. For other browsers it will work like a normal file upload control in ASP.NET.

A new Attribute introduces with the ASP.NET 4.5 FileUplaod control i.e. AllowMultipleIt takes either true or false.

In order to support multiple file uploads, set AllowMulitple="true" other than false.

<asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />

In addition to this control, some new properties have been included to support code-behind coding.


HasFilesCheck whether FileUpload control has multiple files or not.

PostedFilesBasically used to get all the files from the FileUpload control in the iteration.

Example code to upload files:

   <asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />  
   <asp:Button runat="server" ID="uploadedFile" Text="Upload" OnClick="uploadFile_Click" />  

protected void uploadFile_Click(object sender, EventArgs e) {  
    if (UploadImages.HasFiles) {  
        foreach(HttpPostedFile uploadedFile in UploadImages.PostedFiles) {  
            //code to save files  
        }  
    }  
}