ASP.NET遇到问题---空引用异常

来源:互联网 发布:windows 系统修复 编辑:程序博客网 时间:2024/03/29 22:37

Problem2:

 下面的红色部分出错

提示:

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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim i As Integer
        For i = 1 To 6
            Dim newhl As New HyperLink
            Dim newlabel As Label
            newlabel.Text = " "
            newhl.Font.Size = 12
            newhl.Font.Bold = True
            newhl.Text = CStr(i)
            newhl.NavigateUrl = "?n=" + CStr(i)
            newhl.ID = "h1" + CStr(i)
            DIV1.Controls.Add(newhl)
            DIV1.Controls.Add(newlabel)
        Next
        If Request("n") = " " Then
            Image1.ImageUrl = "~/images/01.jpg"
        Else
            Image1.ImageUrl = "~/images/0" + Request("n") + ".jpg"
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>图象浏览</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="DIV1" runat="server" style="width: 345px; height: 27px">
        </div>
        <br />
        <br />
        <asp:Image ID="Image1" runat="server" Height="200px" /></div>
    </form>
</body>
</html>
 

原创粉丝点击