我有一个包含 2 个项目的解决方案。一个项目 ( TestControl ) 包含 aspx 文件。然后是用户控件的另一个(控件)。我已经使 aspx 可以通过引用项目中的控件并将文件复制到TestControl项目来显示用户控件。但是 Sub 似乎不起作用,即使在简单的 response.redirect 代码中,它也会发送错误“对象引用未设置为对象的实例”。我尝试了一个 msgbox,它可以工作,并将代码放在 page_load 中。但是在潜艇内部它不起作用。任何想法为什么?和修复?
uc3.ascx 文件中的简单代码
Public Sub Redirect()
Response.Redirect("http://www.google.com")
End Sub
这是错误异常
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=System.Web
StackTrace:
at System.Web.UI.UserControl.get_Response()
at Controls.uc3.Redirect() in C:\Users\Nelbin\Documents\Visual Studio 2010\Projects\TestApp\Controls\uc3.ascx.vb:line 9
at Controls.uc1.btnUserControl3_Click(Object sender, EventArgs e) in C:\Users\Nelbin\Documents\Visual Studio 2010\Projects\TestApp\Controls\uc1.ascx.vb:line 16
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: