2 つのプロジェクトを含むソリューションがあります。1 つのプロジェクト ( TestControl ) には aspx ファイルが含まれています。次に、ユーザーコントロールのその他(Controls)。プロジェクト内のコントロールを参照し、ファイルをTestControlプロジェクトにコピーすることで、aspx がユーザー コントロールを表示できるようにしました。しかし、サブは機能していないようで、単純な 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: