How to change the value of having a job in Asp.net via javascript?

Asked

Viewed 73 times

1

I need to change the text of a label side by Javascript and then reload the page

Follow the code of the label

<asp:Label runat="server" ID="ValorMax" Visible="false">10</asp:Label>

You need to put javascript on this button

<input type="button" id="btn01" value="2" />

I need that when the id="btn01" button is clicked, change the Label id="Valormax" value from 10 to 20

Reload the page

  • I suggest you confirm how you have your code, because what you have put here is incomplete at label level, missing < and >. In addition it is necessary to be more explicit in what you want to do exactly. Change the text for what value ? Based on what ? When this exchange should be made ?

  • I don’t know ASP very well, but if you put document.getElementById('ValorMax').textContent = 20; on the page, this changes the value?

  • Have some technical impediment to do this action via . net?

  • Your question, until a certain point works, after the reload page is lost value and come back 10 again.

1 answer

0

Citation

When the asp:label is rendered, ends up becoming a tag "span" of HTML.

$(document).ready(function(){
  $('#btn01').click(function(){
    $('#ValorMax').html(20);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<span runat="server" ID="ValorMax" Visible="false">10</span>

<input type="button" id="btn01" value="2" />

I have tried to answer your question directly because I know you will use this as an example for more complex things. To reload the page just run the code below, I did not put in the example as you would not see the value change.

location.reload();

I put a JQuery, because it is recommended to use because it speeds development, but there is the way to do with javascript conventional without the Framework JQuery.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.