[RESOLVED]Very basic html/javascript problem

I’m trying to get a very basic javascript test working.  I’m getting:

BC30456: ‘handleuploadbutton’ is not a member of ‘ASP.default_aspx’.

Thanks for any clues since, apparently, I don’t have one.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="temp2._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>

        <script type="text/javascript">
            function handleuploadbutton(uploadButton) {
                document.getElementById(uploadButton).visible = false;
            }

        </script>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:Button ID="Button1" runat="server" Text="Button" 
    OnClick="handleuploadbutton('Button2')"
    />
    <asp:Button ID="Button2" runat="server" Text="Button" />
    </form>
</body>
</html>

It looks like you are trying to use the button’s server side event.  I believe the client side event is OnClientClick.  I just did a quick search to confirm what I was thinking and found pretty much the same answer on StackOverflow.

http://stackoverflow.com/questions/9081510/how-to-run-the-javascript-fn-using-onclick-button-event-asp-net

I changed OnClick to OnClientClick and the error went away. thanks.

I’m trying to get button2 to disappear when I click button1, 

Can you see what I’m doing wrong? It seems to reload the page but both buttons are still there.

Thanks.

You will want to set the ClientIDMode to static so that the name generated will be the same.  You will also want to return false in your button to prevent the post back.  Here is some code I did real quick in a test page that hides Button 2 when I click
Button 1.

<asp:Button ID="btnButton1" ClientIDMode="Static" runat="server" OnClientClick="HideButton2(); return false;" Text="Button 1" />
<asp:Button ID="btnButton2" ClientIDMode="Static" runat="server" Text="Button 2" />

<script>
    function HideButton2()
    {
        var button2 = document.getElementById("btnButton2");
        button2.style.visibility = "hidden";
    }
</script>

Thank you for both the OnClientClick and return false;  

It’s all working now.

Leave a Reply