【问题标题】:formview with ajax modal popup extender带有 ajax 模式弹出扩展器的 formview
【发布时间】:2013-11-09 01:21:45
【问题描述】:

我已经尝试了几种方法,但它们似乎都不适合我。我有一个表单视图,当用户进入编辑模式然后单击更新时,我希望显示一个模式弹出窗口,以便他们可以输入关于他们更改内容的注释。

这是我的代码

<ajaxToolkit:ModalPopupExtender ID="SubmitButton_ModalPopupExtender" 
 runat="server" OkControlID="EditNoteButton" PopupControlID="EditNotePanel" 
 BehaviorID="MPE" BackgroundCssClass="modalBackground"
 TargetControlID="DummyButton">
</ajaxToolkit:ModalPopupExtender>

<asp:Panel ID="EditNotePanel" runat="server" CssClass="style105" Height="23px"            style="display: none">
<asp:TextBox ID="EditNoteBox" runat="server" CssClass="style106" Height="68px" Width="223px">What Did You Change?</asp:TextBox> <br />
<asp:Button ID="EditNoteButton" runat="server" CssClass="style107" Height="29px" Text="Ok" Width="52px" CommandName="update" /> <br />
</asp:Panel>

C#

protected void ClientInformationForm_ItemCommand(Object sender, FormViewCommandEventArgs e)
    {
      //case statements

    if (ClientInformationForm.CurrentMode == FormViewMode.Edit)
    {
        SubmitButton_ModalPopupExtender.TargetControlID = ((Button)ClientInformationForm.FindControl("SubmitButton")).UniqueID;
    }

从我所读到的应该可以。我试过在clientclick上通过javascript显示它。我尝试通过在 itemcommand 中调用 modal.show() 来显示它,但它们都没有显示它。面板或弹出窗口在表单视图内部还是外部是否重要?

 protected void Page_Load(object sender, EventArgs e)
 {

    if (!this.IsPostBack && Session["CurrentAccountId"] != null)
    {
        AddressTypeddl.DataBind();
        ShippingAddressddl.DataBind();
        AddressForm.DataBind();
    }


    if (ClientInformationForm.DataItemCount == 0)
    {
        ClientInformationForm.BackColor = Color.FromArgb(0xd9e2bf);
    }
    else
    {
        ClientInformationForm.BackColor = Color.White;

    }


    if (Session["CurrentAccountId"] == null)
    {    
        NoteBox.Visible = false;
        NewNoteButton.Visible = false;
        NoteTypeddl.Visible = false;
        NoteLabel.Visible = false;
        NoteTypeLabel.Visible = false;
        NewNoteLabel.Visible = false;
        CreditCardView.Visible = false;
        NewAccountButton.Visible = true;
        AddressTypeddl.Visible = false;
        AddressLabel.Visible = false;
        AddressForm.Visible = false;
    }
    else
    {

        NoteBox.Visible = true;
        NewNoteButton.Visible = true;
        NoteTypeddl.Visible = true;
        NoteLabel.Visible = true;
        NoteTypeLabel.Visible = true;
        NewNoteLabel.Visible = true;
        CreditCardView.Visible = true;
        NewAccountButton.Visible = false;
        AddressTypeddl.Visible = true;
        AddressLabel.Visible = true;
        AddressForm.Visible = true;

    }

}

所以我刚刚意识到,如果我希望人们继续发帖,我需要编辑我的原始帖子,而不仅仅是添加注释,所以希望这会有所帮助。无论如何,我仍然无法让它工作,我不知道是什么导致我的弹出窗口不触发?

【问题讨论】:

    标签: c# asp.net ajax modalpopupextender formview


    【解决方案1】:

    经过很多天的反复试验,我终于找到了为什么这不起作用。它归结为虚拟按钮。我将可见设置为 false 以隐藏按钮,并且由于某种原因不起作用。一旦我将其更改为 style= display:none;它发射得很好。奇怪的是没有抛出错误,它只是永远不会弹出。

    【讨论】:

    • 样式与 asp 控件属性不同。 style="display:none" 与 visible="false" 不同。查看渲染时的 HTML 代码。
    【解决方案2】:

    如果您想在用户进行编辑后弹出模式,我不会使用 ItemCommand 事件。

    我没有太多使用FormViews,主要是GridViews。但我假设原理大致相同。

    您是否尝试过在 ItemUpdated 事件中显示模式?

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.itemupdated(v=vs.110).aspx

    我以前没有尝试过,但我想这样的事情可能会起作用:

     protected void ClientInformationForm_ItemUpdated(Object sender, FormViewUpdatedEventArgs e)
     {
          //capture ID of the updated record, and perhaps store it in a HiddenField that's in the modal
           SubmitButton_ModalPopupExtender.Show();
     }
    

    【讨论】:

    • 我也试过了。它执行该代码但仍然只是返回到更新的表单视图而不显示弹出窗口。出于某种原因,无论我做什么,我都无法显示弹出窗口。
    • 您是否在 Page_Load 中做任何会覆盖模式的操作?
    • 我发布了我的页面加载,但我认为这些都不会影响这一点。抱歉,我整个周末都得了流感,没有早点发帖。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    • 1970-01-01
    相关资源
    最近更新 更多