2014年7月13日 星期日

[RESOLVED] Use UploadFile within UpdatePanel


Hi 


I have tried many ways to push the UploadFile work with UpdatePanel but i coudnt and i cant remove the button out side the update panel so could some one give me a solution with this code:






















Image 1:




 



Image 2:








Image 3:








Image 4:








Image 5:



















ConnectionString="<%$ ConnectionStrings:BeravaConnectionString %>"
SelectCommand="SELECT [UID], [Section], [AdsID], [Category], [Country], [State], [City], [AdsTit], [AdsDesc], [AdsPrice], [Wtags], [AdsDate], [Img1], [img2], [img3], [img4], [img5] FROM [ads] WHERE ([UID] = @UID)">














code behind:


 protected void addadsbtn_Click(object sender, EventArgs e)
{

Guid newGUID = Guid.NewGuid();
SqlConnection cn = new SqlConnection(sc);
SqlCommand cmd = new SqlCommand();

string sqlstatment = "INSERT INTO [ads] ([Section], [Category], [UID], [AdsTit], [AdsDesc], [Country], [State], [City], [AdsPrice], [Img1], [img2], [img3], [img4], [img5], [Wtags]) VALUES (@Section, @Category, @UID, @AdsTit, @AdsDesc, @Country, @State, @City, @AdsPrice, @Img1, @img2, @img3, @img4, @img5, @Wtags)";

cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstatment;

//Insert the parameters first
cmd.Parameters.AddWithValue("@Section", Catedrdoads.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Category", SubCatedrdoads.SelectedItem.Text);
cmd.Parameters.AddWithValue("@UID", USRNMElbl.Text);
cmd.Parameters.AddWithValue("@AdsTit", addadstittxtbx.Text);
cmd.Parameters.AddWithValue("@AdsDesc", desctxtbox.Text);
cmd.Parameters.AddWithValue("@Country", countrdrdolst.SelectedItem.Text);
cmd.Parameters.AddWithValue("@State", statedrdolst.SelectedItem.Text);
cmd.Parameters.AddWithValue("@City", citiesdrdolst.SelectedItem.Text);
cmd.Parameters.AddWithValue("@AdsPrice", adsaddpristxtbx.Text);
cmd.Parameters.AddWithValue("@Img1", FileUploadImg1.FileName);
cmd.Parameters.AddWithValue("@Img2", FileUploadImg2.FileName);
cmd.Parameters.AddWithValue("@Img3", FileUploadImg3.FileName);
cmd.Parameters.AddWithValue("@Img4", FileUploadImg4.FileName);
cmd.Parameters.AddWithValue("@Img5", FileUploadImg5.FileName);
cmd.Parameters.AddWithValue("@Wtags", addadswtagtxtbtn.Text);



if (FileUploadImg1.HasFile)
{
FileUploadImg1.SaveAs(Server.MapPath("~/images/AdsImgs/" + FileUploadImg1.FileName));

}
if (FileUploadImg2.HasFile)
{
FileUploadImg2.SaveAs(Server.MapPath("~/images/AdsImgs/" + FileUploadImg2.FileName));

}
if (FileUploadImg3.HasFile)
{
FileUploadImg3.SaveAs(Server.MapPath("~/images/AdsImgs/" + FileUploadImg3.FileName));

}
if (FileUploadImg4.HasFile)
{
FileUploadImg4.SaveAs(Server.MapPath("~/images/AdsImgs/" + FileUploadImg4.FileName));

}
if (FileUploadImg5.HasFile)
{
FileUploadImg5.SaveAs(Server.MapPath("~/images/AdsImgs/" + FileUploadImg5.FileName));

}


SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ad.SelectCommand = cmd;
ad.Fill(ds);

Response.Redirect("User panel.aspx");


}

Many thanks for all



If you are using an UpdatePanel, then I recommend you use the AsyncFileUpload...


http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/AsyncFileUpload/AsyncFileUpload.aspx



Matt



Thanks AZMatt for reply, but the problem i dont know how to handel with AsyncFileUpload i tried after you post your reply to find a good tutorial but i didnt find something really useful 



Your HTML markup inside the update panel is messed up.PostBackTrigger should work.Remove the unnecesary html tags and the view tag.



Hi Ashim Chatte 


thanks for your reply but in fact its very hard to remove the view tag as the project should show many of tools for the user within one page the html code above is a part of the whole one but i just past here the part of FileUpload 



file upload cannot be done with a partial post back. It requires a full post back.


You can include the file uploader inside an iframe so only the page inside the iframe will postback. It will be seen to the outside like page isn't getting postback. Of course, now one can argue it's actually postback the page inside the iframe. But it willl
not post back the page which contains the iframe. So my suggestion is to divide your page into parts and include the file uploader and the upload button inside an iframe.


Or if you don't mind posting back when uploading the file, you can take the fileuploader and the button out from the update panel or simply add a postbacktrigger.



ControlID="UploadButtonID" />

沒有留言:

張貼留言