当我从页面访问用户控件时,无法在用户控件中看到DB的控件值

时间:2022-10-19 23:00:46

I have got one user control, I am loading this user control from a parent page when the button clicked ..

我有一个用户控件,当点击按钮时,我从父页面加载此用户控件。

In user control I have got one drop downlist and grid view , both data is loading form DB in page load method ......

在用户控件中我有一个下拉列表和网格视图,这两个数据都是在页面加载方法中加载表格DB ......

but in parent page when I click on the button to load the user control, I am able to see only one drop down with no loaded values in it(normally it is loaded with values ) and not able to see the grid view as well ....

但是在父页面中,当我点击按钮加载用户控件时,我只能看到一个没有加载值的下拉列表(通常它加载了值),也无法看到网格视图。 ...

and this is my code ..on parent page

这是我的代码..在父页面

 <%@ Page Language="C#" MasterPageFile="~/MasterPages/template.master" AutoEventWireup="true"            CodeFile="ViewCertificateMaster.aspx.cs" Inherits="Pages_ViewCertificateMaster" %>

  <%@ Register Src="../Controls/one.ascx" TagPrefix="uc1" TagName="one" %>

and in code behind file

并在代码后面的文件

protected void btnShow_OnClick(object sender, EventArgs e)
{
    int selectedItem = ddlProductType.SelectedIndex;

    switch (selectedItem)
    {
        case 0:

            UserControl myUsrControl = (UserControl)Page.LoadControl("../Controls/one.ascx");
            divViewMyCerts.Controls.Add(myUsrControl);
            divViewMyCerts.Visible = true;

            break;
     ....................
         ..................
      ..................
       code 

in one.ascx code behind file ...

在one.ascx代码后面的文件...

protected void Page_Load(object sender, EventArgs e)
{
    string remoteUser = ((UserInfo)Session["USER_INFO"]).GetUserEmail();
    intAcctId = ((UserInfo)Session["USER_INFO"]).GetUserAcctId();
    objCert = new Certificate();

    if (!IsPostBack)
    {
         .............
         here I am binding the grid view and drop down list values from DB
         ...............
         ...............

Would any one please help on this why I am getting empty dropdown list and not able to see the grid view as well ....

请问任何人请帮助我为什么我得到空的下拉列表,也不能看到网格视图....

many thanks in advance

提前谢谢了

1 个解决方案

#1


0  

Because IsPostBack will be true in Page_Load of the one.ascx. Since the control is being added at btnShow_OnClick event at the page and the IsPostBack is true here. Check the value of IsPostBack in one.ascx in your code.

因为IsPostBack在one.ascx的Page_Load中是真的。由于控件是在页面的btnShow_OnClick事件中添加的,因此IsPostBack为true。检查代码中one.ascx中IsPostBack的值。

See the definition of IsPostBack of a user control. Which is

请参阅用户控件的IsPostBack的定义。这是

"Summary: Gets a value indicating whether the user control is being loaded in response to a client postback, or if it is being loaded and accessed for the first time.

“摘要:获取一个值,该值指示是否正在加载用户控件以响应客户端回发,或者是否第一次加载和访问它。

Returns: true if the user control is being loaded in response to a client postback; otherwise, false."

返回:如果正在加载用户控件以响应客户端回发,则返回true;否则,是假的。“

#1


0  

Because IsPostBack will be true in Page_Load of the one.ascx. Since the control is being added at btnShow_OnClick event at the page and the IsPostBack is true here. Check the value of IsPostBack in one.ascx in your code.

因为IsPostBack在one.ascx的Page_Load中是真的。由于控件是在页面的btnShow_OnClick事件中添加的,因此IsPostBack为true。检查代码中one.ascx中IsPostBack的值。

See the definition of IsPostBack of a user control. Which is

请参阅用户控件的IsPostBack的定义。这是

"Summary: Gets a value indicating whether the user control is being loaded in response to a client postback, or if it is being loaded and accessed for the first time.

“摘要:获取一个值,该值指示是否正在加载用户控件以响应客户端回发,或者是否第一次加载和访问它。

Returns: true if the user control is being loaded in response to a client postback; otherwise, false."

返回:如果正在加载用户控件以响应客户端回发,则返回true;否则,是假的。“