I've been struggling with this issue for days.
1- A user clicks on one of the buttons.
2- The button click inserts a .js variable into LABEL->lbJavaScriptVar
3- Sys.Application.add_load(GridJson); invokes the .js function
The issue is, I am unable to modify the value of the variable "SHOWTHIS" inside an UpdatePanel as the value never changes.
-----------------------------[aspx]------------------------------------
<head>
<script type="text/javascript">
function GridJson()
{
alert(SHOWTHIS);
document.getElementById("Grid").innerHTML =
"<tr><td>" + SHOWTHIS+ "</td></tr>"
}
</script>
</head>
...
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button ID="btMan" runat="server" OnClick="btMan_click" Text="Man"/>
<asp:Button ID="btWoman" runat="server" OnClick="btWoman_click" Text="Woman"/>
<asp:Label ID="lbJavaScriptVar" runat="server" ></asp:Label>
<table id="Grid" border="5" class="cssMiniGrid"></table>
<script type="text/javascript">Sys.Application.add_load(GridJson);</script>
</ContentTemplate>
</asp:UpdatePanel>
-----------------------------[/aspx]------------------------------------
-----------------------------[.cs]------------------------------------
(btMan_click)...
lbJavaScriptVar.Text = "<script> var SHOWTHIS= 9999</script> ";
(btWoman_click)...
lbJavaScriptVar.Text = "<script> var SHOWTHIS = 7777</script> ";
-----------------------------[/.cs]------------------------------------
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
EDITED...I managed to resolve it thanks to your suggestions, make these changes to ensure it works
.ASPX<
[ALTER]function GridJson() ------> function GridJson(SHOWTHIS) {
.CS
[DELETE](btMan_click)...
[DELETE]lbJavaScriptVar.Text = "<script> var SHOWTHIS= 9999</script> ";
[DELETE](btWoman_click)...
[DELETE]lbJavaScriptVar.Text = "<script> var SHOWTHIS = 7777</script> ";
[INCLUDE]ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "GridJson(" + "THANKS" + ");", true);
Note: Initially, I wrote this code within a web user control, but now it's placed under the root page