0

I develop a webpage in that the user want to call a JavaScript function. Based on what the function returns I want to continue the link button URL. I paste my code below.

<script type="text/javascript">
    function fvalidate()
    {
        var i = document.getElementById('txtvalue').value;
        if(i=='23')
        {
            Here I want to execute server side code
        }
        else
        {
            I want to show some alert message to the user and the page won't refresh.
        }
    }
</script>
<asp:LinkButton
    Width="35px"
    ID="updateUserL"
    runat="server"
    OnClick="updateForm_Click"
    CssClass="btn"
    OnClientClick="fvalidate();"
>Update</asp:LinkButton>
3
  • i got answer , Thanks for help Commented Nov 11, 2009 at 13:15
  • 10
    Hey @Sakthivel: When people say you should "accept" an answer, they mean that you must click on the check mark next to the one answer that best answers your question. Go back to each question you've ever asked and do that. Otherwise, people will stop helping you (people want to be recognized for the help they give). Commented Nov 11, 2009 at 13:22
  • @Good Two Shoes: This question wouldn't have had a bounty when that comment was made. Commented Nov 17, 2009 at 13:48

2 Answers 2

20

Modify your function as follows:

function fvalidate()
{
   var i = document.getElementById('txtvalue').value;
   if(i=='23') 
   {   
    return true;
   }
   else    
   { 
    prompt("Your Message");
    return false;
   }
}

And modify your OnClientClick so it reads OnClientClick="return fvalidate();"

Sign up to request clarification or add additional context in comments.

Comments

3

The OnClientClick should read somthing like

OnClientClick="javascript:return fvalidate();"

and then the function

function fvalidate()  
{  
   var i = document.getElementById('txtvalue').value;  
    if(i=='23') return true;  
else    return false;  
}

return true will then pass to the server side code.

1 Comment

You don't need to specify "javascript:" on the OnClientClick.

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.