Asp.net postback in gridview?

File upload control is not designed to maintain filepath on poskback.. but you can have a workaround of it.. try storing filepaths in session variables.. I know it bit clumsy but seems like the only way to do this.. one more thing you can do to lessen you effort is to create a UserControl that will manage this for you...

Up vote 0 down vote favorite share g+ share fb share tw.

In my asp.net application I have a gridview control, in which I added a template column with fileupload control. And outside the gridview in the page I have a button control which performs some task. My issue is that when I click the button, the file which I chosen via file upload control in gridview has get refreshed and the file path vanishes.

How can I stop refreshing the gridiew when I click the button. Button is not inside the grid. Protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = new DataTable(); DataColumn dc1 = new DataColumn("id", typeof(string)); dt.Columns.

Add(dc1); dr = dt.NewRow(); dr0 = "abcd"; dt.Rows. Add(dr); DataSet ds = new DataSet(); ds.Tables. Add(dt); GridView1.

DataSource = ds; GridView1.DataBind(); } } asp.net link|improve this question edited Jan 4 at 6:23Tarun1,214313 asked Jan 4 at 5:36user7035269916 88% accept rate.

– Pavan Jan 4 at 5:45 If you are using ASP. NET Ajax, then place your gridview in a separate update panel. – Pavan Jan 4 at 5:53.

File upload control is not designed to maintain filepath on poskback.. but you can have a workaround of it.. try storing filepaths in session variables.. I know it bit clumsy but seems like the only way to do this.. one more thing you can do to lessen you effort is to create a UserControl that will manage this for you... //If first time page is submitted and we have file in FileUpload control but not in session // Store the values to SEssion Object if (Session"FileUpload1" == null && FileUpload1. HasFile) { Session"FileUpload1" = FileUpload1; Label1. Text = FileUpload1.

FileName; } // Next time submit and Session has values but FileUpload is Blank // Return the values from session to FileUpload else if (Session"FileUpload1"! = null && (! FileUpload1. HasFile)) { FileUpload1 = (FileUpload) Session"FileUpload1"; Label1.

Text = FileUpload1. FileName; } // Now there could be another sictution when Session has File but user want to change the file // In this case we have to change the file in session object else if (FileUpload1. HasFile) { Session"FileUpload1" = FileUpload1; Label1.

Text = FileUpload1. FileName; } for more info http://www.codeproject.com/Tips/101834/How-to-Maintain-FileUpload-Control-s-State-after-P.aspx Regards.

File upload control will never persists its value between postbacks. You can maintain a Label field in your GridView which holds the path of the file uploded via FileUpload control. When you click on the button outside your GridView, copy the values from FileUpload control to lable.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions