【问题标题】:Can I edit inside of a modal popup?我可以在模式弹出窗口内编辑吗?
【发布时间】:2011-10-27 14:43:37
【问题描述】:

我只发现使用网格视图和模式弹出窗口的人需要帮助进行编辑的帖子。但是,我没有使用网格视图,因此编辑并不像在网格视图中进行编辑那么简单。当我单击编辑按钮时,模式弹出窗口消失。这是我到目前为止所拥有的,但在代码隐藏中我收到一条错误消息,指出我的模态未声明。

在下图中,关闭按钮旁边的小铅笔图像是我单击以编辑描述的地方。当我点击它时,模式消失了,所以我无法编辑文本。

<!-- Descriptions -->
<asp:TabPanel ID="tab2"  runat="server" HeaderText="Descriptions">
<HeaderTemplate>Descriptions</HeaderTemplate>
    <ContentTemplate>
        <ul class="info">
        <asp:ListView ID="lvDescriptions" runat="server" 
        DataSourceID="dsAdminMarketingDescriptions" DataKeyNames="MarketingID">
        <ItemTemplate>
            <li class="item">
                <asp:LinkButton ID="ViewDescriptionButton" runat="server"><%# 
                Eval("Title")%>
                </asp:LinkButton>
                <asp:ImageButton ID="DeleteDescriptionButton" runat="server" 
                Style="float:right;" AlternateText="" 
                ImageUrl="../../images/delete.png" CommandName="Delete" 
                OnClientClick="return confirm('Are you sure you want to delete this 
                description?')" />
                <asp:Panel ID="ViewDescriptionPanel" runat="server" 
               CssClass="DescModalPopup">
      <div class="PopupHeader">View Description -- <%#Eval("Title") %>
                    <asp:ImageButton ID="CancelDescriptionButton" runat="server" 
                     ImageUrl="../../images/cancel.png" AlternateText="" 
                     Style="float:right;"/>
                    <asp:ImageButton ID="EditDescriptionButton" runat="server" 
                     ImageUrl="../../images/edit.png" AlternateText="" 
                     Style="float:right;" CommandName="edit" AutoPostBack="false" />
                </div>
                <asp:Label ID="Description" runat="server" style="padding:2px;">
                <%# Eval("Data")%>
                </asp:Label>
                </asp:Panel> 
                <asp:ModalPopupExtender ID="ViewDescriptionModal" runat="server" 
                 BackgroundCssClass="modalBackground" DropShadow="false" 
                 DynamicServicePath="" Enabled="true" 
                 PopupControlID="ViewDescriptionPanel" 
                 TargetControlID="ViewDescriptionButton" 
                 CancelControlID="CancelDescriptionButton">
                </asp:ModalPopupExtender>              
            </li>
        </ItemTemplate>


Protected Sub EditDescriptionButton_Click(ByVal sender As Object, ByVal e As 
  System.EventArgs)
    ViewDescriptionModal.Show()
End Sub

更新:我更改了代码隐藏,但我仍然收到一条错误消息,提示 ViewDescriptionModal 未声明。

Protected Sub EditDescriptionButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim myControl As Control = FindControl("ViewDescriptionModal")
    If (Not myControl Is Nothing) Then
        ViewDescriptionModal.Show()
    Else
        'Control not found
    End If
End Sub

更新:我为编辑创建了第二个模式弹出窗口,并将标签更改为文本框以从数据库中提取信息进行编辑。我添加了一个提交按钮,但是当我单击它时,我收到一条错误消息,说明它存在潜在危险。

有没有人有A potentially dangerous Request.Form value was detected from the client的经验

【问题讨论】:

  • 我不确定您页面的其余部分是什么样的。从这里很难看出你在做什么。
  • @MitchelSellers 我添加了一张图片和更多代码。我希望这有助于更好地解释。
  • 我已经读到使用 UpdatePanel 将有助于防止模式刷新,但是当我尝试包含它时,我收到一个错误,提示面板不能在 UpdatePanel

标签: vb.net edit modalpopupextender


【解决方案1】:

我没有对此进行测试,但是如果您使用两个 modalpopupextenders 和两个面板,一个用于查看,一个用于编辑,您可能会很幸运。

<asp:ModalPopupExtender ID="ViewDescriptionModal" runat="server" 
BackgroundCssClass="modalBackground" DropShadow="false" 
DynamicServicePath="" Enabled="true" 
PopupControlID="ViewDescriptionPanel" 
TargetControlID="ViewDescriptionButton" 
CancelControlID="CancelDescriptionButton">
</asp:ModalPopupExtender> 

<asp:ModalPopupExtender ID="EditDescriptionModal" runat="server" 
BackgroundCssClass="modalBackground" DropShadow="false" 
DynamicServicePath="" Enabled="true" 
PopupControlID="EditDescriptionPanel" 
TargetControlID="EditDescriptionButton">
</asp:ModalPopupExtender> 


<asp:Panel ID="ViewDescriptionPanel" runat="server" ... </asp:panel>              
<asp:Panel ID="EditDescriptionPanel" runat="server" ... </asp:Panel><code>

【讨论】:

  • 听起来很有道理。我想我只是将编辑按钮保留在视图模式中。我创建了一个editmodal,但是当我点击编辑按钮时,它不应该打开editmodal吗?再一次,我收到一条错误消息,提示未声明模式。
  • 我做了一个快速测试,它对我有用,虽然我的第二个模态只是有一个测试字符串。您还在使用 EditDescriptionButton Click 事件吗?由于它被设置为 TargetControlID,因此您不需要在后面的代码中处理它。
  • 是的,我摆脱了背后的代码,当我单击模态中的小铅笔图像时,它只会刷新页面并且模态消失。您如何才能显示编辑模式?
  • 好吧,没关系,一定有错字。第二个模态确实出现了。添加一个额外的来编辑我的信息的好主意!现在我需要弄清楚如何使文本可编辑,我已经准备好了!
【解决方案2】:

试试你的图片按钮
autopostback="false"

【讨论】:

  • 我试过了,当我点击按钮时,模式仍然消失。
  • ViewDescriptionModal.visble() = 'true' 在您的按钮点击事件中可能会对您有所帮助。
  • 我仍然收到一条错误消息,指出未声明 ViewDescriptionModal。这对我来说没有意义,因为那是 aspx 页面上的 ID。有什么我看不到的问题吗?
  • 使用findcontrol方法。
  • 我使用findcontrol 方法使用的代码编辑了原始帖子,但仍然遇到同样的错误。
猜你喜欢
  • 1970-01-01
  • 2015-07-16
  • 2013-07-21
  • 2014-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多