Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 通过按钮命令逐个服务器调用客户端_Asp.net_Javascript - Fatal编程技术网

Asp.net 通过按钮命令逐个服务器调用客户端

Asp.net 通过按钮命令逐个服务器调用客户端,asp.net,javascript,Asp.net,Javascript,我有这样简单的代码。。。如下 <%@ 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-transition

我有这样简单的代码。。。如下

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

无标题页
#福姆特
{
高度:284px;
}
.DivStyle
{
高度:250px;
背景颜色:绿色;
显示:块;
}
函数TryClose(){
document.getElementById(“DivBah”).style.height='1px';
document.getElementById(“DivBah”).style.display='none';
返回;
}
试试看这部分是否会倒塌
这给了我错误消息,比如=>“TryClose”不是“default.\u ASPX”的一部分 这种类型的编码可能有什么错误? 因为我以前总是在简单的ASP程序中使用这种类型。

如果您使用的是vs 2008(.NET 3.5),请改用OnClientClick

你犯的错误很符合逻辑。“OnClick”属性用于将处理程序“服务器端处理程序”连接到单击事件。由于这些处理程序是服务器端处理程序,VS查看了映射到aspx页面的.vb文件,没有找到名为
TryClose()
的方法

TryClose()
这里是一个客户端函数;为了将其用作“在客户端”上单击事件的处理程序,您需要使用
OnClientClick
属性将其连接起来。 希望这有帮助

试试这个:

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

用于服务器端单击事件的OnClick