Home > DeveloperSection > Forums > read html attributes in asp.net
Chintoo Semi

Total Post:135

Points:947
Posted on    September-02-2014 12:19 AM

 ASP.Net
Ratings:


 1 Reply(s)
 621  View(s)
Rate this:

I have a hidden variable in my aspx page as below.

  <input type="hidden" value="" runat="server" id="homeExcelData" filename=""/>

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

Before submitting, i am setting the 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, during postback, i can get the excelData by homeExcelData.Value which i set in the javascript.

But the value of the attribute "filename" is coming as empty string(not as null) instead of "test.xls".

Please help me to fix it.

Server side code:

 string fileName = homeExcelData.Attributes["filename"] ?? "report.xls";



Sumit Kesarwani

Total Post:378

Points:2694
Supported
Posted on    September-02-2014 12:43 AM

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());

}


Don't want to miss updates? Please click the below button!

Follow MindStick