First put your div tag inside the form, and then try to execute the jQuery code snippet
$(function () { $("#photoUpButton").click(function (pho) { $(".pUploadDiv").css("visibility", "visible").dialog({ modal: true, height: 300, autoOpen: true }, "draggable"); $(".pUploadDiv").parent().appendTo($("form:first")); }); });
EDIT
According to your comment, I created a sample page. Please check and let me know. If you encounter any problems.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script> <script type="text/javascript"> $(function () { $("#btnOpen").click(function (pho) { $(".pUploadDiv").css("visibility", "visible").dialog({ modal: true, height: 300, autoOpen: true }, "draggable"); $(".pUploadDiv").parent().appendTo($("#form1")); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <input type="button" id="btnOpen" value="Upload Files" /></div> <div id="pUploadDiv" class="pUploadDiv"> <asp:FileUpload runat="server" ID="FileUpload1" CssClass="FileUpload" /><br /> <asp:FileUpload runat="server" ID="FileUpload2" CssClass="FileUpload" /><br /> <asp:FileUpload runat="server" ID="FileUpload3" CssClass="FileUpload" /><br /> <asp:FileUpload runat="server" ID="FileUpload4" CssClass="FileUpload" /><br /> <asp:Button runat="server" ID="UploadButton" Text="Upload" CausesValidation="true" OnClick="UploadButton_Click" /> </div> </form> <form id="form2" action=""> I am on form2 </form> <form id="form3" action=""> I am on form2 </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default5 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void UploadButton_Click(object sender, EventArgs e) { HttpFileCollection hfc = Request.Files; for (int i = 0; i < hfc.Count; i++) { HttpPostedFile hpf = hfc[i]; if (hpf.ContentLength > 0) {
source share