English 中文(简体)
页: 1
原标题:asp.net multiple updatepanel usercontrol

So, I have a usercontrol with an update panel. I also put a button for updating the panel on my control. I include this control 2 times (or more) in a page. I want update only one of them but when I use the button, both panel is updated.

control ascx

    <script type="text/javascript">
  function bt_click()
  {        
     __doPostBack( UpdatePanel1 ,  post );
     return false;
  }
  </script>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:HiddenField runat="server" ID="HiddenField1" Value="false" />
            <div>
                <asp:Label ID="Label1" runat="server" Text="Val"></asp:Label>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

控制.vb

protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            Label1.Text = DateTime.Now.Ticks.ToString();
        }
    }

网络格式.aspx

<form id="form1" runat="server">
<div>
    <asp:Button runat="server" ID="bt" OnClientClick="bt_click" />
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    &nbsp;
    <asp:Label ID="Label1" runat="server" Text="Val"></asp:Label>
    <div>
        <My:MyControl ID="MyControl1" runat="server" />
    </div>
    <br />
    <div>
        <My:MyControl ID="MyControl2" runat="server" />
    </div>
</div>
</form>

网址:vb

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Label1.Text = DateTime.Now.Ticks.ToString();
    }
最佳回答

这里的错误是:您的<代码>Button1不在更新小组的范围之内,从而张贴了你的网页和所有控制。 因此,两者都得到了更新。 你可以在<代码>Triggers部分的控制中添加纽芬兰语,因为显然控制并不了解它。 因此,你必须做的是将纽伦堡列为亚丁斯邮政局。 在此,我做了以下工作:

TestControl.ascx:

Note: I had to add UpdateMode="Conditional" to the UpdatePanel, which yours did not have. By default, UpdateMode is set to Always, and that would cause us further issues.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestControl.ascx.cs" Inherits="Controls_TestControl" %>

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:HiddenField runat="server" ID="HiddenField1" Value="false" />
        <div>
            <asp:Label ID="Label1" runat="server" Text="Val"></asp:Label>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

TestControl.ascx.cs:

说明:我补充说,更新纸浆,作为需要使用<_doPostBack (的财产。 j门和我可以轻易从点击事件手里的上级网页上接通。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Controls_TestControl : System.Web.UI.UserControl
{

    public UpdatePanel UpdatePanel() { return UpdatePanel1; } 

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            Label1.Text = DateTime.Now.Ticks.ToString();
        }
    }
}

www.un.org/ga

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<%@ Register TagPrefix="uc" TagName="TestControl" Src="~/Controls/TestControl.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Fire UpdatePanel1" />
        <asp:Label ID="Label1" runat="server" Text="Val"></asp:Label>
        <br /><br />
        <uc:TestControl ID="TestControl1" runat="server" />
        <br />
        <uc:TestControl ID="TestControl2" runat="server" />
    </form>
</body>
</html>

<> 试验:

<>说明: 在这里,我登记了<代码>Button1,载于Page_Load,Manager1.RegisterAsyncPostBackControl(Button1);

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptManager1.RegisterAsyncPostBackControl(Button1);

        if (!IsPostBack)
        {
            Label1.Text = DateTime.Now.Ticks.ToString();
        }
    }

    protected void Button1_Click(object sender, EventArgs e) 
    {
        TestControl1.UpdatePanel().Update();
    }

}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签