kantotan
kantotan

Reputation:

Calling Client side by server side Thru Button Command

I have simple code like this... as follow...

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="AlinmaWebApp._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>Untitled Page</title>
    <style type="text/css">
        #formHt
        {
            height: 284px;
        }
        .DivStyle
        {
            height :250px;
            background-color :Green ;
            display : block;
        }

    </style>

<script language="javascript" type ="text/javascript" >

    function TryClose() {
        document.getElementById("DivBah").style.height = '1px';
        document.getElementById("DivBah").style.display = 'none';
        return;
    }
</script>


</head>
<body onload="TakeIT() return;" >
    <form id="formHt" runat="server">
    <div id="DivBah" class="DivStyle" >
        Just Try if this part will Collapse or not</div>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="TryClose()"/>
    </form>
</body>
</html>

That gave me Error message like => "TryClose" is not a part of "default_._ASPX" What is possible error on this type of coding? Since i always use this type in Simple ASP Program before.

Upvotes: 0

Views: 547

Answers (2)

Ahmed
Ahmed

Reputation: 11423

If you're using vs 2008 (.NET 3.5) use OnClientClick instead.

The error that you got is pretty logical. The "OnClick" attribute is used to wire up handlers "Server Side Handlers" to the click event. Because those handlers are server-side handlers, VS took a look at your .vb file that is mapped to your aspx page and found no method with the name TryClose().

TryClose() here is a client-side function; in order to use it as a handler to the click event "on the client" you need to wire it up using the OnClientClick attribute. Hope this helps!

Upvotes: 1

Canavar
Canavar

Reputation: 48098

Try this :

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="TryClose()"/>

OnClick used for server side click event.

Upvotes: 1

Related Questions