Retrieve the value of an ASP.Net text box [duplicated]

0

I have a textbox with id TextBox and

I have a JavaScript function

function prueba() {
  var hotel = document.getElementById("titulo").innerHTML;
  $('#MainContent_TextBox1').val(hotel);
}

Now in the codebehind I want the value I assigned to Textbox , recover it

 public void printDivs()
 {
   eWidget hotel = new eWidget();
   hotel.titulo = TextBox1.Text;
 }

But when debugeo , it tells me that it has nothing that textbox , although visually if it has

    
asked by Ernesto Emmanuel Yah Lopez 15.06.2017 в 01:02
source

1 answer

1

Replaces:

$('#MainContent_TextBox1').val(hotel);

By:

$('#<%= NombreDeTuTextBox.ClientID %>').val(hotel);

Explanation:

The definition of client-level IDs in ASP.net Webforms depends on how you use the Site.Master, the content placeholders, to ensure that you are selecting the ID (client) that you expect is necessary to specify it by .ClientID

    
answered by 15.06.2017 в 02:26