I am reading a phone number from the database in C#, and want to copy it to a textbox on my web form.
My text box is masked using JQuery.
I don't know how to access C# variables from JQuery or Java Script. So my approach is to have a hidden
variable on my web form. Then in C# I use the text box property of the hiddenlabel control, to set the value of the
hidden label control.
I figure that once the text on my label control is set in C#, that I can then access it in JQuery or Java Script.
Accessing it for the purpose of populating my text box control "txtPhone"
However when I try and access the value for my hidden label control, it is coming back as null. so if I trace into
the JQuery below, the value for "var" is null, before attempting to display it with the alert command.
So why is the value for by label control coming back as null, from my C# code?
If their is a better way to set the textbox from C#, I am open to doing it that way?
Please help!
(
<script type="text/javascript">
var txtTheValue = document.getElementById('<%= hiddenLabel.ClientID %>');
alert(txtTheValue .innerHTML);
$(document).ready(function () {
$("#<%=txtPhone.ClientID%>").val(txtTheValue .innerHTML).mask("(999) 999-9999 Ext.9999");
});
</script>
// This code works, if I hard code a value. However I need to send the value back from C#
//$(document).ready(function()
// {
// $("#<%=MaskedTextBox.ClientID%>").val("30398765437812").mask("(999) 999-9999 Ext.9999");
// });
Open in new window