In a WebForms project, on a particular page, I have a javascript method in the aspx file. Inside I use 2 embedded code blocks.
<script type="text/javascript">
function showMessage(idActityGroup) {
var r = confirm("Message");
if (r == true) {
//First Code Block
<%string idActityGroup = "' + idActityGroup + '";
//Second Code Block
'<%Session["waitList"] = "yes"; %>';
//Last javascript instruction
window.location.href = '/Register';
}
</script>
The problem is that these two lines are executed each time a click event of a button is triggered. When in the event of the codebehind button it has done its work, it enters the aspx and executes those two lines. And I just want them to run when the function is called. The method is inside an updatePanel. I have tried to get the javascript function out of the updatePanel but the same thing is still happening.
Is there any way to avoid this behavior? Thank you very much.