button控件的onclick事件为何不执行它的事件过程,而是仅仅刷新页面?

xinyuself 2008-05-23 11:19:15
我做了个管理员添加用户的页面。由button控件的onclick事件执行添加用户到数据库,并有添加其必修课程。现在每次点击按钮,都只是再次加载页面,而不执行button1_click事件?这是为什么?附上完整源码,大家帮我看看,谢谢。(button1_click的内容不用管)

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Dim n%
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) '页面初始事件里往表格加入行
n = Val(InputBox("请输入要添加职员数:" & "注:一次最多为10人,如果大于10人请多次添加:", "添加职员数", "5"))
Dim j%, i%
'下面往表格Table1添加n行,每行三列,分别是文本框、文本框、下拉列表框
'供管理员输入用户的账号、姓名、工作岗位
For j = 1 To n
Dim tr As TableRow
Dim cells(0 To 2) As TableCell
tr = New TableRow
Dim txtbox1 As TextBox, txtbox2 As TextBox 'txtbox1,txtbox2分别是放在每行第一、二列
txtbox1 = New TextBox
txtbox2 = New TextBox
For i = 0 To 2
cells(i) = New TableCell
Next
txtbox1.ID = "txtUserID" & j.ToString
txtbox2.ID = "txtUserName" & j.ToString
txtbox1.Text = ""
txtbox2.Text = ""
cells(0).Controls.Add(txtbox1)
tr.Cells.Add(cells(0))
cells(1).Controls.Add(txtbox2)
tr.Cells.Add(cells(1))

Dim droplist1 As DropDownList 'droplist1放在第三列,列出全部岗位供管理员选择
droplist1 = New DropDownList
With droplist1
.ID = "droplists" & j.ToString
.DataSourceID = "SqlDataSource1"
.DataTextField = "PostName"
.DataValueField = "PostID"
.Visible = True
End With
cells(2).Controls.Add(droplist1)
tr.Cells.Add(cells(2))
Table1.Rows.Add(tr)
Next j

'PlaceHolder1.Controls.Add(tb)
End Sub



Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) '利用该事件把用户添加进数据库
Dim i%, j%, m%, courseNum% 'i,j循环变量,m密码位数,courseNum某岗位的必修课程数
Dim userid$, pwd$, username$, userpost$ '用户的各字段的值
'后面的代码太长,我省略了。
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 700px; height: 575px">
<tr style="width :700px">
<td colspan="3" style="height: 300px; text-align: left;">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="PostName"
DataValueField="PostID" Visible =false >
</asp:DropDownList>
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ELConnectionString %>" SelectCommand="SELECT * FROM [e_post]">
</asp:SqlDataSource>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="700px" style="height: 173px">
<param name="movie" value="pic/top.swf" />
<param name="quality" value="high" />
<embed src="pic/top.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" width="700px" height="300px"></embed></object></td>
</tr>
<tr>
<td colspan="3" style="height: 13px" >
<div style="text-align: left">
<table border="0" style="width: 700px; background-color: #cc99cc; height: 24px; " >
<tr>
<td style="height: 13px" ><a href =default.aspx>
<img src="pic/Home.ico" height="20" width="20" />首页</a></td>
<td style="height: 13px" >
添加用户</td>
<td style="height: 13px" >删除用户</td>
<td style="height: 13px" >
 修改用户</td>
<td style="height: 13px" >
添加课程</td>
<td style="height: 13px" >
删除课程</td>
<td style="height: 13px" >修改课程</td>
<td style="width: 59px; height: 13px;" >
     退出
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td style="width: 700px; height: 44px;" colspan="2">
 <asp:PlaceHolder ID="PlaceHolder1" runat="server">
<asp:Table ID="Table1" runat="server">
<asp:TableheaderRow >
<asp:TableCell >职员帐号</asp:TableCell>
<asp:TableCell >职员姓名</asp:TableCell>
<asp:TableCell >职员岗位</asp:TableCell>
</asp:TableheaderRow>
</asp:Table>
</asp:PlaceHolder>
    
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="添加" Width="94px" /></td>
</tr>
</table>
<%MyGlobals.conn.Close()%>
</div>
</form>
</body>
</html>
...全文
204 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinyuself 2008-05-23
  • 打赏
  • 举报
回复
InputbBox在这里运行时,也弹出了,也可以按所输入的个数生成表的行,好像这个函数没什么问题。
难道InputBox影响了Button1的Click事件?
华芸智森 2008-05-23
  • 打赏
  • 举报
回复
InputBox
不能用在B/S结构上.
xinyuself 2008-05-23
  • 打赏
  • 举报
回复
我把inputbox屏蔽掉,还是不能执行button1_click事件。

到底怎样才能执行?

应该是很简单的问题,怎么总是执行不了。

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧