1

This code is wriiten in VS 2003 -asp.net

in the HTML page, I have a javascript function checkuser() defined which returns boolean. I would like to enclose the following in a call to this function

<A onclick="stageClear(); stageEditor();" href="javascript: void(0);">Add new Stage</A>

I want something like

<%if checkuser() then%> <A onclick="stageClear(); stageEditor();" href="javascript: void(0);">Add new Stage</A> <% end if %>

But I am getting the error checkuser() not defined

0

3 Answers 3

2

Your code looks as if it is looking for an asp function called checkuser.

if you wanted to do it with js you would need to do something like this:

<script type="text/javascript">
   if (checkuser()) {
      document.write('<a onclick="stageClear(); stageEditor();" href="javascript: void(0);">Add new Stage</a>');
   }
</script>
Sign up to request clarification or add additional context in comments.

Comments

2

If you intend to call the checkuser() function inside a server-side code block (as the one you show), you must define the function on the page's code behind, not on the client-side using JavaScript.

In other words, you need to have a function called

protected bool checkuser()
{
    return true;//just an example
}

And then you can call it as you intended to.

Comments

0

You can't mix your back end and your front end code.

<a onclick="clickHandler()" href="javascript:void(0)">Stuff</a>

and the JS:

<script>
    function clickHandler(){
        if(checkuser()){
            //do something
        }else{
            //do something else
        }
    }
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.