Reputation: 727
I want to be able to upload file and get the new saved path back, without any postback. I have already tried to use updatepanel
BUT then the fileupload was found as null.
Practically I want to get the File_Path_Text
in order to use it in a javascript method.
The follwoing is the code I am using;
protected void get_path(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(@"C:\temp\" + FileUpload1.FileName);
File_Path_Text = @"C:\temp\" + FileUpload1.FileName;
}
}
The following is the asp part;
<asp:FileUpload ID="FileUpload1" runat="server" accept="kml"/>
<asp:Button id="Button1" text="Add layer to map" OnClick="get_path" runat="server" />
Upvotes: 2
Views: 808
Reputation: 38713
create a ashx file( http handler) and put the below code(put your path) there.
window.open('<%=Server.MapPath("~/path")%>')
Upvotes: 0
Reputation: 148178
You can assign the text to hidden field and make that hidden field server accessible. You can also use public property to assign value to it and access it on client.
Html
<input type="hidden" runat="serer" id="hdnText" />
Code behind
hdnText.Value = @"C:\temp\" + FileUpload1.FileName;
Javascript
alert(document.getElementById("<%= hdnText.ClientID %>").value);
To upload file asynchronously you can use some jQuery plugin, like Ajax File Upload
Upvotes: 1
Reputation: 17724
A very simple option is uploadify. You can hook it up to an HttpHandler and have your uploads happen in the background while the application remains interactive.
UpdatePanels will give you trouble with uploading files.
Upvotes: 1