我要用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?)谁能帮我看看是怎么回事呀?多谢多谢
<!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?)谁能帮我看看是怎么回事呀?多谢多谢
<script runat="server">
void Page_Load(Object sender , EventArgs e)
{
cityBox.Attributes.Add("onClick","showlistBox()");
}
</script>因为服务端控件的onClick事件无法直接调用客户端javascript函数
citybox.Attributes.Add("onekeydown",".....")之类的话呀?我对程序结构特别不清楚,谁能指点一下呀,多谢
加
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的基础很差,希望谁能帮帮我