I have this javascript code:
<script>
$(document).ready(function() {
var progValue1 = 100;
var progValue2 = 30;
$("#progressbar").progressbar({ value: progValue1});
$("#progressbar2").progressbar({ value: progValue2 });
});
</script>
I would like to change the values of the two variables (progValue1
and progValue2
) from the code behind when a button is clicked .....
This is the code for the button
<asp:Button ID="btnConfirm" CssClass="button" SkinID="Common" runat="server" Text= "Confirm" OnClick="btnConfirm_Click" />
How can I change those values from the C# code for the btnConfirm
method?
To get JavaScript values in the code-behind, we need Hidden Input Control, whose runat attribute we will set to runat="Server" so that it can be accessible in code-behind. It will work as an intermediately to pass the value from client-side to server-side.
How to Pass Values from JavaScript to CodeBehind? You can also use a HTML INPUT control by setting runat="server". This is another way where we can make an Ajax call to server whenever we need the server value in javascript/jquery. When you use ASP.Net AJAX then you can use PageMethods for this.
Add two properties, i.e.
private int _progValue1 = 100;
private int _progValue2 = 30;
protected int ProgValue1 { get { return this._progValue1; }}
protected int ProgValue2 { get { return this._progValue2; }}
Modify your JS:
<script>
$(document).ready(function() {
var progValue1 = <%=ProgValue1%>;
var progValue2 = <%=ProgValue2%>;
$("#progressbar").progressbar({ value: progValue1});
$("#progressbar2").progressbar({ value: progValue2 });
});
</script>
Then set the values in your OnClick event handler:
this._progValue1 = 40;
this._progValue2 = 20;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With