简体   繁体   中英

Set server side text from javascript using form c#

I have asp lable

<asp:Label ID="lbl_qustionID" runat="server" Text="1" />

I set lable text to 6 using javascript

<button onclick="replayFrom('6')">set label number to 6</button>

My script function is :

<script>
            function replayFrom(qustionId) {
                document.getElementById("<%=lbl_qustionID.ClientID%>").innerText = qustionId;                
            }
</script>

When I check lable text from c# code behind label text is "1" allways ! I'm using .NET 2.0 Classic and WebForms Thanks for suggesion

<button onclick="replayFrom('6')">set label number to 6</button>

This button tag refresh your page. First its change label when you click on button but after that it will refresh the Page.

I will recommend you please use input tag when you deal with javascript and when do not need to communicate with server

  <input type="button" onclick="replayFrom('6')" value="button"/>    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM