hi
there is no direct solutions as mentioned .. until you use the ajax ..
also you cant set the value of FileUpload control even from javascript
and the following didnt worked even its rendered in html :
Me.FileUpload1.Attributes("value") ="...." solution:
but you can use:
but you need also to remeber the last posted file
because in case you dont select a file from FileUpload control after a postback and then submit ,
the FileUpload.postedFile data will gone , so you have to save the posted file to the session ...
this is how :
asp.net page Code:
<form id="form1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" /> <br />
<asp:Label ID="lblCurrentFile" runat="server"></asp:Label><br />
<br />
<asp:Button ID="BtnSubmit" runat="server" Text="postBack" />
<br />
<asp:HiddenField ID="HiddenField1" runat="server" />
</form>
codeBehind:
Private Property PostedFile() As HttpPostedFile
Get
If Me.Session("postedFile") IsNot Nothing Then
Return Session("postedFile")
End If
Return Nothing
End Get
Set(ByVal value As HttpPostedFile)
Session("postedFile") = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Me.BtnSubmit.Attributes("onclick") = _
String.Format("document.getElementById('{0}').value= document.getElementById('{1}').value;", _
Me.HiddenField1.ClientID, Me.FileUpload1.ClientID)
End If
If Me.FileUpload1.PostedFile IsNot Nothing _
AndAlso Me.FileUpload1.PostedFile.ContentLength > 0 Then
Me.PostedFile = Me.FileUpload1.PostedFile
End If
If Me.HiddenField1.Value <> "" Then
Me.lblCurrentFile.Text = Me.HiddenField1.Value
End If
End Sub regards,