How to save in viewstate in Javascript

Posted by Oswaldlily under ASP.NET on 7/16/2013 | Points: 10 | Views : 2506 | Status : [Member] | Replies : 1
I need to store the filename in either Session or Viewstate in design page of
and should use in codebhind C# by inheriting session or viewstate value.

When i Use like following in viewstate,it is considering viewstate as null in codebehind.
how to rectify this error

<script language="javascript" type="text/javascript">
function GetFileName(fileUp) {
var gv = document.getElementById("<%=gv.ClientID %>");
var gvRowCount = gv.rows.length;
var rwIndex = 2;
var inputs = gv.getElementsByTagName("input");
var c;
for (var j = 2; j < gvRowCount; j++) {
var filePath = fileUp.value;
var filename = filePath.replace(/^.*[\\\/]/, '');
c = gv.rows[j].cells[15];
document.getElementById(c.childNodes[5].id).innerHTML = filename;
document.getElementById("<%=hidden_field.ClientID %>").Value = filename;
alert(document.getElementById("<%=hidden_field.ClientID %>").Value);
ViewState["hidden_field"] = filename;

return false;


Posted by: aswinialuri-19361 on: 7/30/2013 [Member] Starter | Points: 25

refer this link it might be helpful to you

Mark as Answer if it helps you
Aswini Aluri

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response