Hi All,
I have a web application where I am adding a custom attribute to my ASP.NET
text box control and changing value of that attribute at client side using
JavaScript. My problem is that changed value of that custom attribute is not
reflecting back at server side. Any ideas about this problem?
Server side code:
private void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack == false)
{
this.txtTarget.Attributes.Add("myCustomAttribute", "Server Side Value");
this.txtTarget.Text = "Server Side Value";
}
else
{
Response.Write("Attribute Value In Page_Load: <b>"
+ this.txtTarget.Attributes["myCustomAttribute"]
+ "</b><br>");
}
}
Client side code:
<script>
function setTextBoxAttribute()
{
var txtTarget = document.getElementById('txtTarget');
alert('Old Attribute Value: ' +
txtTarget.getAttribute('myCustomAttribute'));
txtTarget.setAttribute('myCustomAttribute', 'Client Side Value');
txtTarget.value = 'Client Side Value';
}
</script>
PS: Using input hidden HTML control is not an option for me. I have to use
custom attributes anyhow.