TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
KRayudu V
NA
155
205.7k
how we can get javascript fileupload id in asp.cs
Nov 27 2012 6:05 AM
ASPX
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TicketMasterEntry.ascx.cs"
Inherits="PUMA.LMS.UserControls.TicketMasterEntry" %>
<script type="text/javascript">
var counter = 0;
function AddFileUpload() {
var div = document.createElement('DIV');
div.innerHTML = '<input id="file' + counter + '" name = "file' + counter +
'" type="file" />' +
'<input id="Button' + counter + '" type="button" ' +
'value="Remove" onclick = "RemoveFileUpload(this)" />';
document.getElementById("FileUploadContainer").appendChild(div);
counter++;
}
function RemoveFileUpload(div) {
document.getElementById("FileUploadContainer").removeChild(div.parentNode);
}
</script>
<table class="creditNoteRA">
<tr>
<td>
Department Name
</td>
<td>
<asp:DropDownList ID="ddldeptname" CssClass="selectPumaNormal" DataTextField="DepartmentName"
DataValueField="DepartmentName" runat="server" OnDataBound="ddldeptname_DataBound">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Issue Category Name
</td>
<td>
<asp:DropDownList ID="ddlisscategoryname" DataTextField="CatalogName" DataValueField="CatalogName"
CssClass="selectPumaNormal" runat="server" OnDataBound="ddlisscategoryname_DataBound">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Issue Name
</td>
<td>
<asp:DropDownList ID="ddlissuename" DataTextField="IssueName" DataValueField="IssueName"
CssClass="selectPumaNormal" runat="server" OnDataBound="ddlissuename_DataBound">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Desciption
</td>
<td>
<asp:TextBox ID="txtdescription" runat="server" CssClass="texboxPumaBig" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Contact Person
</td>
<td>
<asp:TextBox ID="txtcontactperson" CssClass="texboxPumaBig" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Contact Number
</td>
<td>
<asp:TextBox ID="txtcontactnumber" CssClass="texboxPumaBig" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
File Attachements
</td>
<td>
<span style="font-family: Arial">Click to add files</span>
<input id="Button1" type="button" value="add" onclick="AddFileUpload()" />
</td>
<td>
<br />
<br />
<div id="FileUploadContainer">
<!--FileUpload Controls will be added here -->
</div>
<br />
<asp:Button ID="btnsave" runat="server" CssClass="btnPuma" Text="Upload" OnClick="btnsave_Click" />
</td>
</tr>
<%-- <tr>
<td>
File Attachements
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>--%>
<%--<tr>
<td>
File Attachements
</td>
<td>
<asp:FileUpload ID="FileUpload2" runat="server" />
</td>
</tr>--%>
<%--<tr>
<td colspan="2">
<asp:Button ID="btnsave" runat="server" Text="Save" CssClass="btnPuma" OnClick="btnsave_Click"
Style="position: relative; top: 0px; left: 125px" />
</td>
</tr>--%>
</table>
ASPX.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Puma.LMS.Controller;
using PUMA.LMS.Model;
using System.IO;
namespace PUMA.LMS.UserControls
{
public partial class TicketMasterEntry : System.Web.UI.UserControl
{
TicketEntryController tec = new TicketEntryController();
TicketEntryModels temcc = new TicketEntryModels();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddldeptname.DataSource = tec.LoadDeptMastrCtrl();
ddldeptname.DataBind();
ddlissuename.DataSource = tec.LoadIssueNameCtrl();
ddlissuename.DataBind();
ddlisscategoryname.DataSource = tec.LoadIssueCategoryNameCtrl();
ddlisscategoryname.DataBind();
}
}
protected void ddldeptname_DataBound(object sender, EventArgs e)
{
ddldeptname.Items.Insert(0, "---Select---");
}
protected void ddlisscategoryname_DataBound(object sender, EventArgs e)
{
ddlisscategoryname.Items.Insert(0, "---Select---");
}
protected void ddlissuename_DataBound(object sender, EventArgs e)
{
ddlissuename.Items.Insert(0, "---Select---");
}
protected void btnsave_Click(object sender, EventArgs e)
{
temcc.DepartmentName = ddldeptname.SelectedValue;
temcc.IssueCategoryName = ddlisscategoryname.SelectedValue;
temcc.IssueName = ddlissuename.SelectedValue;
temcc.Description = txtdescription.Text;
temcc.ContactPerson = txtcontactperson.Text;
temcc.ContactNumber = txtcontactnumber.Text;
//temcc.FileAttachements = FileUpload1.FileName;
try
{
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
hpf.SaveAs(Server.MapPath("~/MaterialUpload/") + "\\" +
Path.GetFileName(hpf.FileName));
//temcc.FileAttachements = FileUpload1.FileName;
//temcc.FileAttachements = FileUpload2.FileName;
tec.TicketInsertCtrl(temcc);
}
}
}
catch(Exception ex)
{
throw ex;
}
}
}
}
i wrote code for dynamic add fileupload controller in aspx by using javascrip.I need to add the file name in database,how can i get the
fileupload
id from javascript,
Reply
Answers (
0
)
Report Control in Visual studio 2012
Publisher subscriber model