Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I want to use my variable that i was declared in code behind,

What I have tried:

i have used this code ,

<asp:AquaButton ID="btnWorkflowMass" runat="server" OnClientClick='if(<%=bAlert %> = "True"){}else{LoadWorkflowMass();}'
meta:resourcekey="btnWorkflowMassResource1" >

in code behind i declared bAlert :
public bool bAlert;

i want to cheek befor i call LoadWorkflowMass() methode.

and i have synthaxe error.
Posted
Updated 24-Aug-18 11:05am

I find it much easier to store values in a hidden field rather than use that type of syntax, which I', not eve sure will work the way you want it to.

You need to understand the separation of what is processed on the server and how that is sent and then processed on the client. Then programming web applications will make more sense to you.

So, put a hidden field on the page, set it's value in C# and then change your OnClientClick to call a JavaScript function. In the function get the value of your hidden field and then do what you need to do.

It's all basic web stuff.
 
Share this answer
 
Your syntax was indeed incorrect. You should do it like this:

HTML
OnClientClick="if('<%= bAlert%>'){alert('true');}else{LoadWorkflowMass();}return false;"


While that works, I'd still recommend you to place your logic within a JavaScript function so you can easily read and debug them. For example:

JavaScript
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function isValid() {
            var result = '<%= bAlert%>';
            if (result) {
                alert('true');
            }
            else {
                LoadWorkflowMass();
            } 
            return false;
        }
    </script>
</head>


Then you simply call the function above like this:

HTML
OnClientClick="isValid();"
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900