我要用asp.net编一个简单的程序。网页上有一个textbox,我想点一下textbox然后就弹出一个listbox. 我试着写javascript,我的原码如下:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Infologi_v6.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <script language="javascript">
        function showlistBox() ////在此处处错,说找不到关键字function
            {document.getElementById('listBox2').style.visibility = 'visible';}
        function hidelistBox()
            {document.getElementById('listBox2').style.visibility = 'hidden';}
    </script>

    <body MS_POSITIONING="GridLayout" onclick = "hidelistBox()">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="cityBox" style="Z-INDEX: 101; LEFT: 184px; POSITION: absolute; TOP: 73px" onclick="showlistBox"  runat="server" Width="158px"></asp:TextBox>
<asp:ListBox id="ListBox1" style="Z-INDEX: 102; LEFT: 184px; POSITION: absolute; TOP: 94px" runat="server" Width="157px"></asp:ListBox>
         <asp:TextBox id="countryBox" style="Z-INDEX: 103; LEFT: 426px; POSITION: absolute; TOP: 73px" runat="server"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 104; LEFT: 191px; POSITION: absolute; TOP: 239px" runat="server" Text="confirm"></asp:Button>
<asp:ListBox id="ListBox2" style="Z-INDEX: 105; LEFT: 425px; POSITION: absolute; TOP: 97px" runat="server" Width="155px"></asp:ListBox>
</form>
    </body>
</HTML>但是编译出错错误信息是Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0246: The type or namespace name 'function' could not be found (are you missing a using directive or an assembly reference?)谁能帮我看看是怎么回事呀?多谢多谢

解决方案 »

  1.   

    加一段:
    <script runat="server">
    void Page_Load(Object sender , EventArgs e) 
    {
       cityBox.Attributes.Add("onClick","showlistBox()");
    }
    </script>因为服务端控件的onClick事件无法直接调用客户端javascript函数
      

  2.   

    另外问一下,单击textbox的响应是客户端事件。我用onclick对不对呀。是不是要在.cs里面写
    citybox.Attributes.Add("onekeydown",".....")之类的话呀?我对程序结构特别不清楚,谁能指点一下呀,多谢
      

  3.   

    要用 cityBox.Attributes.Add("onClick","showlistBox()");
      

  4.   

    是呀我觉得也不应该有问题呀,怎么能找不到关键字function呢,真是急死我了,谁救我?
      

  5.   

    刚才的问题解决了,原来是js里的程序行用//注掉也不行,还是有影响,删掉就好了。但是现在我还有东西不知道怎么做。我再javascript中编了一个函数取代showlistBox()和hidelistBox().并用onclick调用他。
    function togglelistBox(txt) 
    {
         var thelistBox = document.getElementById (txt);
         if(thelistBox.style.visibility == 'hidden')
         {
             thelistBox.style.visibility = 'visible';
         }
         else
         {
             thelistBox.style.visibility = 'hidden';
         }
    }现在可以实现单击textbox,listBox出现,在消失。但是我想给listBox梆定值。就类似下面的语句:
    ArrayList values = new ArrayList();
    values.Add ("IN");
    values.Add ("KS");
    values.Add ("MD");
    values.Add ("MI");
    values.Add ("OR");
    values.Add ("TN");
    ListBox2.DataSource = values;
    ListBox2.DataBind();
    我想在客户端梆定,但是不知道这些语句应该放在什么位置。而且实际上我想从后台数据库得到要梆定的值,再把参数传回来,不知怎么办。我asp.net的基础很差,希望谁能帮帮我
      

  6.   

    还有在哪里设置刚开始listBox是unvisible,点一下textbox,listBox就变成visible.我放在.cs的page_load中设置,或者放在form 的listBox里设置都不行,这样的话开始listBox但是怎么点textbox都出不来了。大家帮帮我,真的是很急呀