更新updatePanel中modalpop面板中的值

时间:2013-01-16 13:06:02

标签: asp.net ajax c#-4.0 modalpopupextender

这里我尝试根据转发器控件内部的Linkbutton的click事件更新Label值。场景是当我点击链接按钮同时模态弹出窗口打开,标签文本也改变。

以下是我的代码。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModalPopupUpdatePanel.aspx.cs"
    Inherits="ModalPopupUpdatePanel" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!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>ModalPopups and UpdatePanels</title>
    <link rel="stylesheet" href="StyleSheet.css" />
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager runat="server" ID="scriptMgr1">
    </asp:ScriptManager>
    <div style="width: 300px; left: 100px">

        <div >
            <asp:Label ID="Label2" runat="server">Update Panel that contains a ModalPopup and its associated PopupPanel inside it</asp:Label>
            <asp:UpdatePanel runat="server" ID="updatePanel2" UpdateMode="Conditional"   ChildrenAsTriggers="false">
                <ContentTemplate>

                <br />
                <asp:Repeater runat="server" ID="btnresr" DataSourceID="SqlDataSource1">
                <ItemTemplate>
                <asp:LinkButton runat="server" ID="text" OnClick="Button5_Click" Text=' <%# DataBinder.Eval(Container.DataItem, "AgentName")%>'  BackColor="Red"></asp:LinkButton>
                </ItemTemplate>
                </asp:Repeater>
                    <asp:Button runat="server" ID="button2" Text="Launch Modal Popup2"  style="display:none"/>
                    <ajaxToolkit:ModalPopupExtender runat="server" ID="modalPopupExtender2" TargetControlID="button2"
                        PopupControlID="modalPanel2" OkControlID="okBtn2" CancelControlID="cancelBtn2"
                        BackgroundCssClass="modalBackground">
                    </ajaxToolkit:ModalPopupExtender>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:PTBWConnectionString %>" 
                        SelectCommand="SELECT [AgentName], [AgentID] FROM [AgentMaster]">
                    </asp:SqlDataSource>

                    <asp:Panel runat="server" ID="modalPanel2" BackColor="AliceBlue" Style="display: none">
                        <asp:UpdatePanel runat="server" ID="updatePanel4" UpdateMode="Conditional" ChildrenAsTriggers="true">
                            <ContentTemplate>
                                <asp:Label runat="server" ID="label5" ></asp:Label>
                                <asp:Button runat="server" ID="postbackBtn" Text="Click to Cause postback" OnClick="postbackBtn_Click" /><br />
                                <asp:Button runat="server" ID="cancelBtn2" Text="OK" />
                                <asp:LinkButton runat="server" ID="okBtn2" Text="Cancel" />
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </asp:Panel>

                </ContentTemplate>
            </asp:UpdatePanel>
        </div>

    </div>
    </form>
</body>
</html>

和背后的代码

using System;
using System.Web.UI.WebControls;

public partial class ModalPopupUpdatePanel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void updateLabel_Click(object sender, EventArgs e)
    {

    }

    protected void postbackBtn_Click(object sender, EventArgs e)
    {
        label5.Text = "After Postback";

    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        LinkButton l = (LinkButton)sender;
        label5.Text = "This is before postback,saroop";
        modalPopupExtender2.Show();
    }
}

我在这里阻止请帮助我..有任何Jquery的方式然后也请在这里我

1 个答案:

答案 0 :(得分:0)

那是因为lable5不可用,它嵌套在RepeaterItem中。

你能试试吗?

LinkButton l = (LinkButton)sender;
RepeaterItem rpt = (RepeaterItem)l.Parent();
Label label5 = (Label)rpt.FindControl("label5");
label5.Text = "This is before postback,saroop";

modalPopupExtender2.Show();