【问题标题】:Modal popup not generating postback to page模态弹出窗口不生成回发到页面
【发布时间】:2011-07-21 13:07:50
【问题描述】:
<ajaxToolkit:ModalPopupExtender  runat="server" 
         id="ModalPopupExtender1"
         cancelcontrolid="btnCancel" okcontrolid="btnOkay" 
         targetcontrolid="Button1" popupcontrolid="Panel1" 
         drag="true" 
         backgroundcssclass="ModalPopupBG"
        />

<asp:Button ID="Button1" runat="server" Text="Test Modal Popup" 
    onclick="Button1_Click" />
    <br />

<asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
        <asp:Button ID="Button2" runat="server" Text="Post Back" 
        onclick="Button2_Click" />
        <asp:Label ID="Label1" runat="server" AutoPostBack="true" Text="Nothing has happened yet..."></asp:Label>

        <asp:Panel ID="Panel1" runat="server" AutoPostBack="true">
            <div class="HellowWorldPopup">
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button ID="btnCancel" runat="server" Text="Canel" 
                    onclick="btnCancel_Click" />
                <asp:Button ID="btnOkay" runat="server" Text="Okay" onclick="btnOkay_Click" />
            </div>
        </asp:Panel>

    </ContentTemplate>
</asp:UpdatePanel>

所以我试图让标签包含用户在模式弹出窗口内的文本框中键入的内容。现在btnOkay 无法正常工作。

.cs文件:

protected void btnCancel_Click(object sender, EventArgs e)
{
    TextBox1.Text = "";
}
protected void btnOkay_Click(object sender, EventArgs e)
{
    Label1.Text = TextBox1.Text;
    TextBox1.AutoPostBack = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = "";
    TextBox1.Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
    Label1.Text = "You clicked the button";
}

我根本不希望页面回发,而只是在输入信息后更新页面上的隐藏标签。我该怎么做?

【问题讨论】:

    标签: c# asp.net css asp.net-ajax


    【解决方案1】:

    编辑: 好吧,我认为这应该可以解决问题。

    <ajax:ModalPopupExtender runat="server" id="ModalPopupExtender1" targetcontrolid="Button1"
        popupcontrolid="Panel1" drag="true" backgroundcssclass="ModalPopupBG"  />
    <asp:Button ID="Button1" runat="server" Text="Test Modal Popup" /><br />
    <asp:Panel ID="Panel1" runat="server">
        <div class="HellowWorldPopup">
            <asp:TextBox ID="TextBox1" runat="server" />
            <asp:Button ID="btnCancel" runat="server" Text="Canel" onclick="btnCancel_Click" />
            <asp:Button ID="btnOkay" runat="server" Text="Okay" onclick="btnOkay_Click" />
        </div>
    </asp:Panel>
    
    <asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Nothing has happened yet..." />
        </ContentTemplate>
    </asp:UpdatePanel>
    

    .

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        TextBox1.Text = ""; 
    }
    
    protected void btnOkay_Click(object sender, EventArgs e)
    {
        Label1.Text = TextBox1.Text;
        up.Update();
    }
    

    【讨论】:

    • 不,我希望弹出窗口中的文本框在单击确定按钮时填充页面上的标签。不过感谢您的回复。
    • 并且您希望从 modalpopup 内部填充文本框?
    • 所以在弹出窗口中我希望有一个文本框,用户可以在其中输入他们的姓名等信息。然后在弹出窗口中单击确定,弹出窗口消失。然后页面上的标签显示输入的名称。
    • 在我的回复中编辑了代码。那应该做你想要的。
    • 这很好用,在你第一次进入它时正是我想要的。如果用户犯了错误,我希望他们能够再次单击“测试模式弹出窗口”并输入覆盖旧文本的新文本。这不适用于您的情况。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多