在vb.net中动态创建表时出错 [英] Error in creating a table dynamically in vb.net

查看:62
本文介绍了在vb.net中动态创建表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AutoEventWireup =" true"创建了一个简单的表格。 表单有一个面板和一个按钮。


<%@ Page Title =" Home Page"语言= QUOT; VB"&NBSP; AutoEventWireup = QUOT;真"代码隐藏= QUOT; Default.aspx.vb"继承= QUOT; WebApplication1._Default" %>



<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

< script runat =" server">

   受保护的子Page_Init(ByVal发件人为对象,ByVal e As EventArgs)

        ViewData()

   结束点

< / script>

< html xmlns =" http://www.w3.org/1999/xhtml">

< head id =" Head1" runat =" server">

    < title>< / title>

< / head>

< body>

    < form id =" form1" runat =" server">

        < table align =" center" width =" 88%">

         < tr>&
             < td align =" center">&
                < asp:panel ID =" Panel2" RUNAT = QUOT;服务器" > &NBSP;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < asp:Button ID =" Button2" RUNAT = QUOT;服务器"文本= QUOT;返回"高度= QUOT; 40像素"&NBSP; onclick =" Button2_Click"                  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;宽度= QUOT; 60像素"&NBSP;字体尺寸=英寸×-小型及QUOT;边框= QUOT;固体"&NBSP;
visible =" true"

                 &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;边框宽度= QUOT; 3PX" BORDERCOLOR ="#CC3300" />&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
 

               < / ASP:面板>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
 

             < / td>

        < / tr>

      < / table>

    < / form>

< / body>

< / html>


背后的代码看起来像这个:


Public Class _Default

   继承System.Web.UI.Page



   受保护的子Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)Handles Me.Load

   结束点¥


   受保护的子ViewData()

        Dim tb3 As New Table()

        Dim tc1 As New TableCell

        tc1.Text =" test this"

        Dim tc2 As New TableCell

        tc2.Text =" Gentlemen"

        Dim tr1 As New TableRow

        tr1.Controls.Add(tc1)

        tr1.Controls.Add(tc2)

        tb3.Rows.Add(tr1)

        Panel2.Controls.Add(tb3)

        Button2.Visible = True

   结束点¥


   受保护的Sub Button2_Click(ByVal sender As Object,ByVal e As EventArgs)处理Button2.Click

        Response.Redirect(" default.aspx")

   结束点<
结束类


我相信所有这些都非常简单明了,但是当我点击按钮时,会立即生成以下错误:


mscorlib.dll中出现'System.Threading.ThreadAbortException'类型的第一次机会异常

方法参数必须括在括号中。

mscorlib.dll中出现'System.Threading.ThreadAbortException'类型的第一次机会异常

方法参数必须括在括号中。


有没有人对这些错误有解释? 我已经设置了所有调试选项,但没有任何反应,页面刷新没有发生任何事故。  错误只出现在即时窗口中。


请根据需要重定向到其他论坛。


谢谢




BLUE GOULDING

解决方案

http://support.microsoft.com/kb/312629


形成此KB,根本原因是 Response.Redirect 方法调用,并且可以将
false 值作为第二个参数传递给Response.Redirect方法,如KB所示。


&NBSP;

I created a simple table with AutoEventWireup="true".  The form has a panel and a button.

<%@ Page Title="Home Page" Language="vb"  AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
        ViewData()
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <table align="center" width="88%">
         <tr>
             <td align="center">
                <asp:panel ID="Panel2" runat="server" >  
                   <asp:Button ID="Button2" runat="server" Text="Return" Height="40px"  onclick="Button2_Click"
                                    Width="60px"  Font-Size="X-Small" BorderStyle="Solid"  visible="true"
                                    BorderWidth="3px" BorderColor="#CC3300" />                
               </asp:panel>                               
             </td>
        </tr>
      </table>
    </form>
</body>
</html>

The code behind looks like this:

Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    Protected Sub ViewData()
        Dim tb3 As New Table()
        Dim tc1 As New TableCell
        tc1.Text = "test this"
        Dim tc2 As New TableCell
        tc2.Text = "Gentlemen"
        Dim tr1 As New TableRow
        tr1.Controls.Add(tc1)
        tr1.Controls.Add(tc2)
        tb3.Rows.Add(tr1)
        Panel2.Controls.Add(tb3)
        Button2.Visible = True
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        Response.Redirect("default.aspx")
    End Sub
End Class

I believe all very simple and straightforward, however when I click the button the following errors are generated in the immediate window:

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
Method arguments must be enclosed in parentheses.
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
Method arguments must be enclosed in parentheses.

Does anyone have an explanation for these errors?  I have set break all on debugging choices but nothing happens and the page refreshes without incident.  The errors only appear in the immediate window.

Please redirect to a different forum as needed.

Thanks


BLUE GOULDING

解决方案

http://support.microsoft.com/kb/312629

Form this KB, the root cause is the Response.Redirect method call in your Button2_Click method, and you can pass the false value as the second parameter to the Response.Redirect method as the KB said.

 


这篇关于在vb.net中动态创建表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆