Jump to content

AjayGohil

Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by AjayGohil

  1. Try this way

    <input type="text" id="txtName" name="usrname" >
    <input type="submit" value="Submit" name="Submit" onclick="chklength()" />
    
    
    <script>
      function chklength()
      {
        var name=$("#txtName").val();
        if(name.length < 9){
        alert("Name must be nine characters ");
      }
    </script>
  2. Try this code for file upload

    View File

    <!DOCTYPE html>  
    <html>  
    <head>  
        <title></title>  
    </head>  
    <body>  
        <form id="form1" runat="server">  
            <div>  
                <p>Upload File</p>  
                <asp:FileUpload ID="FileUpload" runat="server" />  
            </div>  
            <p>  
                <asp:Button ID="ButtonUpload" runat="server" Text="Upload File" OnClick="Button_Click" />  
            </p>  
        </form>  
        <p>  
            <asp:Label runat="server" ID="FileUploadStatus"></asp:Label>  
        </p>  
    </body>  
    </html>  

    aspx.cs file

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    namespace FileUploadControlls  
    {  
        public partial class WebControls : System.Web.UI.Page  
        {  
            protected System.Web.UI.HtmlControls.HtmlInputFile File1;  
            protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;  
            protected void Page_Load(object sender, EventArgs e)  
            {  
            }  
            protected void Button1_Click(object sender, EventArgs e)  
            {  
                if ((FileUpload.PostedFile != null) && (FileUpload.PostedFile.ContentLength > 0))  
                {  
                    string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);  
                    string SaveLocation = Server.MapPath("upload") + "\\" + fn;  
                    try  
                    {  
                        FileUpload.PostedFile.SaveAs(SaveLocation);  
                        FileUploadStatus.Text = "The file has been uploaded.";  
                    }  
                    catch (Exception ex)  
                    {  
                        FileUploadStatus.Text = "Error: " + ex.Message;  
                    }  
                }  
                else  
                {  
                    FileUploadStatus.Text = "Please select a file to upload.";  
                }  
            }  
        }  
    }

     

×
×
  • Create New...