Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have no issues when doing using JQuery in a aspx page without a masterpage, but when I try to use it in pages that have a masterpage, it doesn't work, so I end up putting the jquery files and other script files in the page instead of the master. please help me .

my code is-

XML
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>


     <script src="<%= ResolveUrl("http://code.jquery.com/jquery-1.8.2.js") %>" ></script>

    <script src="<%= ResolveUrl("~/js/jquery.uploadify.js") %>"  type="text/javascript"></script>


    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>Welcome</h1>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>
Posted
Updated 13-Dec-14 8:10am
v2
Comments
It should work. What errors you see on the console window of developer tool?

1 solution

Steps:
1. download uploadify [^] and unzip the file in to your project.
2. modify your master page as below
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <link rel="Stylesheet" type="text/css" href="uploadify/uploadify.css" />
   <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
   <script type="text/javascript" src="uploadify/jquery.uploadify.js"></script>
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

3. add Upload.ashx to root folder of the site with below code
C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace WebApplication1
{
    /// <summary>
    /// Summary description for Upload
    /// </summary>
    public class Upload : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Expires = -1;
            try
            {
                HttpPostedFile postedFile = context.Request.Files["Filedata"];

                string savepath = "";
                string tempPath = "";
               
                savepath = context.Server.MapPath("Uploads");
                string filename = postedFile.FileName;
                if (!Directory.Exists(savepath))
                    Directory.CreateDirectory(savepath);

                postedFile.SaveAs(savepath + @"\" + filename);
                context.Response.Write(tempPath + "/" + filename);
                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                context.Response.Write("Error: " + ex.Message);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

4. Sample content page
ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type = "text/javascript">
        $(function () {
            $("#FileUpload1").uploadify({
                height: 30,
                swf: 'uploadify/uploadify.swf',
                uploader: 'Upload.ashx',
                width: 120
            });
        }); 
</script>  
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <div style = "padding:40px">
        <asp:FileUpload ID="FileUpload1" runat="server" ClientIDMode ="Static" />
    </div>

</asp:Content>


refer below tutorial for more information:
http://www.aspsnippets.com/Articles/Implement-Uploadify-jQuery-Plugin-in-ASPNet.aspx[^]
 
Share this answer
 
v2
Comments
manvendra patel 14-Dec-14 7:37am    
thanks lot, its working .but I don't understand why it was not running .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900