---
title: "read html attributes in asp.net"  
description: "read html attributes in asp.net"  
author: "Anonymous User"  
published: 2014-09-02  
updated: 2014-09-02  
canonical: https://www.mindstick.com/forum/2222/read-html-attributes-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net", "html", "html5 tags", "html attribute", "html attributes in asp.net", "read html attributes in asp.net", "attributes in asp.net", "attributes"]  
reading_time: 1 minute  

---

# read html attributes in asp.net

I have a hidden [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) in my [aspx page](https://www.mindstick.com/forum/218/how-do-i-create-an-aspx-page-that-periodically-refreshes-itself) as below.

<input type="hidden" value="" runat="server" id="homeExcelData" [filename](https://www.mindstick.com/interview/23463/difference-between-include-filename-and-include-filename)=""/>

On click of a button, iam doing a a form.Sumbit();

Before submitting, i am setting the [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) of the hidden control as below.

document.getElementById("homeExcelData").attributes["filename"] = "test.xls";

$("#homeExcelData").attr("filename","test.xls");

$("#homeExcelData").prop("filename","test.xls");

alert($("#homeExcelData").attr("filename"));

$("#homeExcelData").val(excelData);

In the [code behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-code-behind), during [postback](https://www.mindstick.com/blog/342/postback-in-asp-dot-net), i can get the excelData by homeExcelData.Value which i set in the javascript.

But the value of the [attribute](https://www.mindstick.com/blog/221/attributes-reflection) "filename" is coming as [empty string](https://www.mindstick.com/forum/12697/json-stringify-is-sending-empty-string)(not as null) instead of "test.xls".

Please help me to fix it.

[Server side](https://www.mindstick.com/forum/318/how-to-call-javascript-fuction-in-server-side) code:

string fileName = homeExcelData.Attributes["filename"] ?? "report.xls";

## Replies

### Reply by Sumit Kesarwani

Hi Chintoo, \
try this:\

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

// Set attribute on page Load

homeExcelData.Attributes.Add("filename","test.xls");

}

}

protected void btnCheckValues_Click(object sender, EventArgs e)

{

Response.Write( homeExcelData.Attributes["filename"].ToString());

}


---

Original Source: https://www.mindstick.com/forum/2222/read-html-attributes-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
