Click here to Skip to main content
16,018,394 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,
I set value to hiddenfield in client side and then i tried to read the value in server side. I can't read that value. The value came always empty string. Can u anyone help me.

Here my code :


JavaScript
function DownloadFile(control) {
                   $("#<%=hdnSelectedFile.ClientID%>").val(control.innerHTML);
                   alert("hidden field value : " + $("#<%=hdnSelectedFile.ClientID%>").val())
                   $("#<%=btnDownloadFile.ClientID%>").click();
               }


C#
protected void btnDownloadFile_Click(object sender, EventArgs e)
   {
       try
       {
           // the file name to get
           string fileName = hdnPreviousUploadFileNames.Value;
           // get the file bytes to download to the browser
           string path = Server.MapPath(@"testpath\");
           byte[] fileBytes = System.IO.File.ReadAllBytes(path + fileName);
           // NOTE: You could also read the file bytes from a database as well.
           StreamFileToBrowser(fileName, fileBytes);
       }

       catch (Exception ex)
       {

       }
   }


Thanks for Advance..
Posted

 
Share this answer
 
Comments
Member 11307706 3-Jan-15 2:09am    
Hey peter,
Thanks for your link. It is working ya. :)
XML
<asp:HiddenField ID="Hfproductid" runat="server" />

 var hfproductid = document.getElementById('<%= Hfproductid.ClientID  %>');
 prod_id=100;
 hfproductid .innerHTML = prod_id;


In My Code Behind
------------------
 string invid = HfInvoices.Value; //invid =""; always
 
Share this answer
 
v3
if you have hidden field with id Hfproductid, do as below
JavaScript
var hfproductid =  document.getElementById('<%= Hfproductid.ClientID %>');
hfproductid .value=prod_id;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900