Click here to Skip to main content
14,140,660 members
Rate this:
 
Please Sign up or sign in to vote.
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Your syntax was indeed incorrect. You should do it like this:

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:

<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:

OnClientClick="isValid();"
   
v3

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190518.1 | Last Updated 24 Aug 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100