“无法取消注册 ID 为‘xxx’的 UpdatePanel,因为它没有在 ScriptManager 中注册……"编辑记录时在 RadGrid 中 [英] "Cannot unregister UpdatePanel with ID 'xxx' since it was not registered with the ScriptManager... " in RadGrid while editing record

查看:14
本文介绍了“无法取消注册 ID 为‘xxx’的 UpdatePanel,因为它没有在 ScriptManager 中注册……"编辑记录时在 RadGrid 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我切入正题.我的场景如下:我有自定义添加的字段来过滤 RadGrid,并且过滤效果很好.当我想在 RadGrid 中使用 EditForm 编辑记录时,问题就来了.它曾经工作正常,但后来我在选择正确的行时遇到了一些问题(我总是选择错误的行)所以这就是我修复它的方法.

Let me cut to the chase. My scenario is as follows: I have custom added fields to filter the RadGrid and filtering works perfectly. The problem comes when I want to edit record using EditForm inside RadGrid. It used to work fine, but then I had some problems with selecting the right row (I was always getting the wrong row selected) so this is what I did to fix it.

所以,我的带有过滤器的 RadGrid 看起来像这样:

So, my RadGrid with filters looks like this:

我所做的是使用 Session 来帮助我们确定过滤后的 RadGrid DataSource 是已启动还是默认的.

What I did is to use the Session which will help us to determine later if the filtered RadGrid DataSource was initiated or it was the default one.

protected void btnSearch_Click(object sender, EventArgs e)
{
    Session["SearchKontakti"] = "1";
}

之后我必须使用 if 循环设置 PreRender 以检查前面提到的 Session.

After that I had to set PreRender with if loop to check for previously mentioned Session.

protected void gvKontakti_PreRender(object sender, EventArgs e)
{
    int idKontakt = Convert.ToInt32(Request.QueryString["idk"]);

    if (Session["SearchKontakti"] == "1")
    {
        var kontakti = from k in db.Kontakt
                       select k;

        int idTipUsera = Convert.ToInt32(rcbTipUsera.SelectedValue);
        int idTvrtka = Convert.ToInt32(rcbTvrtka.SelectedValue);

        if (rcbTvrtka.SelectedValue != "0")
        {
            kontakti = kontakti.Where(k => k.idFirma == idTvrtka);
        }

        if (rcbTipUsera.SelectedValue != "0")
        {
            kontakti = kontakti.Where(k => k.idOvlasti == idTipUsera);
        }

        if (chkAktivan.Checked == true)
        {
            kontakti = kontakti.Where(k => k.Aktivan == true);
        }
        else
        {
            kontakti = kontakti.Where(k => k.Aktivan == false);
        }

        int idAuthKontakt = Convert.ToInt32(Session["authenticatedUI"]);

        if (idKontakt > 0 && idAuthKontakt == idKontakt)
        {
            gvKontakti.DataSource = from k in kontakti
                                    where k.idKontakt == idKontakt
                                    orderby k.Prezime, k.Ime
                                    select new { Tvrtka = k.Firma.Naziv, k.idKontakt, Naziv = k.Ime + " " + k.Prezime, Funkcija = k.Funkcija, k.Ime, k.Prezime, k.Tel1, k.Tel2, k.Mob1, k.Mob2, k.Email1, k.Email2, k.Fax, k.Adresa1, k.Adresa2, k.Adresa3, k.Grad, k.PostanskiBroj, k.Drzava, k.Biljeske, k.Aktivan, k.Username, k.Password };
        }
        else if (idKontakt > 0 && idAuthKontakt != idKontakt)
        {
            gvKontakti.DataSource = from k in kontakti
                                    where k.idKontakt == idKontakt
                                    orderby k.Prezime, k.Ime
                                    select new { Tvrtka = k.Firma.Naziv, k.idKontakt, Naziv = k.Ime + " " + k.Prezime, Funkcija = k.Funkcija, k.Ime, k.Prezime, k.Tel1, k.Tel2, k.Mob1, k.Mob2, k.Email1, k.Email2, k.Fax, k.Adresa1, k.Adresa2, k.Adresa3, k.Grad, k.PostanskiBroj, k.Drzava, k.Biljeske, k.Aktivan, k.Username, k.Password };
        }
        else
        {
            gvKontakti.DataSource = from k in kontakti
                                    orderby k.Prezime, k.Ime
                                    select new { Tvrtka = k.Firma.Naziv, k.idKontakt, Naziv = k.Ime + " " + k.Prezime, Funkcija = k.Funkcija, k.Ime, k.Prezime, k.Tel1, k.Tel2, k.Mob1, k.Mob2, k.Email1, k.Email2, k.Fax, k.Adresa1, k.Adresa2, k.Adresa3, k.Grad, k.PostanskiBroj, k.Drzava, k.Biljeske, k.Aktivan, k.Username, k.Password };
        }

        gvKontakti.DataBind();
    }
}

所以,这解决了我的主要问题,但又给了我一个问题.我的一些 UserControls 包含 UpdatePanel,对于每个拥有它的 UserControl,每当我尝试从 RadGrid 中单击 Edit 按钮时,我都会收到以下消息:如果从控件树中删除 UpdatePanel 并稍后再次添加,则可能会发生这种情况,这是不受支持的.参数名称:updatePanel"

So, this fixed my primary problem, but gave me another one. Some of my UserControls contain UpdatePanel and for each UserControl that has it whenever I try to clik Edit button from the RadGrid I receive the following message: "Cannot unregister UpdatePanel with ID 'UpdatePanel4' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported. Parameter name: updatePanel"

我想知道如何解决它.

问候,

赫尔沃耶

推荐答案

我不知道为什么,但不知何故 UpdatePanelScriptManger 注销了两次(它也发生在 RadGrid.Rebind() 方法中;我被困的情况),第二次从 ScriptManger 注销时,您会收到无法注销 UpdatePanel ..."错误.

I don't know why, but somehow the UpdatePanel is unregistered from the ScriptManger twice (it happens in RadGrid.Rebind() method too; the situation I was stuck in), and the second time it's unregistered from ScriptManger you get the "Cannot unregister UpdatePanel ..." error.

解决方法是使用反射在两个取消注册事件之间的某处用 ScriptManger 注册 UpdatePanel,如下所示:

The workaround is to register the UpdatePanel with the ScriptManger somewhere between the two unregister events, using reflection, like this:

protected void UpdatePanel_Unload(object sender, EventArgs e) {
    MethodInfo methodInfo = typeof(ScriptManager).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
        .Where(i => i.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")).First();
    methodInfo.Invoke(ScriptManager.GetCurrent(Page),
        new object[] { sender as UpdatePanel });
}

您应该将 UpdatePanel_Unload 添加到 UpdatePanel 的 OnUnload 事件中:

you should add the UpdatePanel_Unload to the OnUnload event of the UpdatePanel:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnUnload="UpdatePanel_Unload">

您可以找到问题的完整详细信息 这里

You can find the complete details of the problem here

这篇关于“无法取消注册 ID 为‘xxx’的 UpdatePanel,因为它没有在 ScriptManager 中注册……"编辑记录时在 RadGrid 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆