I have a hidden TextBox
control on my page that updates a span
tag on the keyup
event using jQuery. When the page is posted back to the server, the innerHTML
attribute is empty.
How do I get the value that was set during the keyup
event?
Client side code:
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$('#MyHiddenTextBox').keyup(function(){
if($(this).val().length > 0){
SetSpanValue();
}
});
});
function SetSpanValue() {
var mytext = $('#MyHiddenTextBox').val();
$('#MySpanTag').html(mytext);
}
</script>
<style type="text/css">
.USBBox
{
position: absolute;
left: -999em;
}
</style>
<asp:TextBox ID="MyHiddenTextBox" runat="server" CssClass="USBBox" />
<span id="MySpanTag" runat="server" enableviewstate="true" />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
Server side code
protected void btnSubmit_Click(object sender, EventArgs e)
{
string x = MySpanTag.InnerHtml; //this is coming back empty
}