开发者

Call JavaScript from link button

开发者 https://www.devze.com 2022-12-10 08:54 出处:网络
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.

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"
    OnClientClic开发者_运维百科k="fvalidate();"
>Update</asp:LinkButton>


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();"


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消