English 中文(简体)
通过按钮命令由服务器端调用客户端
原标题:
  • 时间:2009-03-16 10:54:53
  •  标签:

我有类似这样的简单代码...如下...

<%@ 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.

问题回答

尝试一下:

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

OnClick 用于服务器端点击事件。

如果您正在使用VS 2008(.NET 3.5),请改用OnClientClick。

你得到的错误是相当合乎逻辑的。 "OnClick" 属性用于将 "服务器端处理程序" 与单击事件链接起来。因为这些处理程序是服务器端处理程序,VS 查看了映射到你的 aspx 页面的 .vb 文件,并没有找到名称为 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!





相关问题
热门标签