从另一个用户控件访问一个用户控件在Asp.NET中返回NULL

时间:2019-06-11 06:19:01

标签: asp.net user-controls

在我的页面中,我有两个用户控件

  1. 负责创建名为(StatuspostingArea.ascx)的帖子
  2. 负责显示名为(StatusupdateArea.ascx)的帖子

enter image description here

现在,StatusupdateArea.ascx负责显示帖子,因此我将继续 Telerik的Listview控件。

现在,我在Google上搜索并找到了一篇文章,该文章展示了这种方法,

StatusUpdateArea.ascx.cs

public partial class StatusUpdateArea : UserControl
    {
        private readonly LanguageConvertion lc = new LanguageConvertion();
        private readonly BEL_UserAccount obj_BEL_UserAccount = new BEL_UserAccount();
        private readonly BL_UserAccount obj_BL_UserAccount = new BL_UserAccount();
        string _imageUrl = "";

        public RadListView ListViewStatus => rlv_StatusPost; // responsible for displaying posts...

和StatuspostingArea.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="StatusPostingArea.ascx.cs" Inherits="e2aPortal.homeUserControl.StatusPostingArea" %>
<%@ Reference VirtualPath="~/homeUserControl/StatusUpdateArea.ascx" %>

当用户单击“发布”按钮时,

protected void btn_PostSubmit_Click(object sender, EventArgs e)
            {
                radwndw_insertQuestion.VisibleOnPageLoad = false;
                var errormessage = string.Empty;
                obj_BEL_UserAccount.strStatusText = Convert.ToString(txt_status_message.Value);
                obj_BEL_UserAccount.strLangCulture = lc.DetectLanguage(txt_status_message.Value);
                obj_BEL_UserAccount.strUserId = Convert.ToString(Request.Cookies["_userid"].Value);
                var i = obj_BL_UserAccount.InsertStatusPost(obj_BEL_UserAccount, out errormessage);
                if (i <= 0)
                {
                    Toastr.Toastr.ShowToast(this.Page,Toastr.Toastr.ToastType.Error, "Error posting!","Error",Toastr.Toastr.ToastPosition.TopRight);
                }
                //((StatusUpdateArea)Page.FindControl("StatusUpdateArea")).ListViewStatus.Rebind(); // throwing Null reference exception ..StatusUpdateArea is NULL..
   // StatusUpdateArea-> ID of that user control
}

有什么办法解决这个问题吗?或者还有其他方法可以使用吗?预先感谢

0 个答案:

没有答案
相关问题