Answered by:
Dynamically Changing the content of ModalPopupExtender Panel

Question
-
User-786564416 posted
I have a button, "DeleteRequest". When clicking this button, I want to show modal popup panel "Panel2". Panel2 has a label "DeleteRequestMessage". I want to change the label text dynamically from code-behind, plus running some code.
The problem I have is that the Panel2 is shown before the: label text changes, and the running of the code.
The aspx page is as following:
<%@ Page Language="VB" MasterPageFile="~/MasterPages/MyMasterPage.master" AutoEventWireup="false" CodeFile="ShowPostingDetails.aspx.vb" Inherits="Pending_ShowPostingDetails" MaintainScrollPositionOnPostback="true" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <style type="text/css"> . . . </style> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="CpMainContent" Runat="Server"> <!-- Required jQuery Reference --> <script type="text/javascript" src="<%= ResolveUrl("~/jquery/js/jquery-1.8.2.min.js")%>"></script> <!-- Idle Timer Plugin Reference --> <script type="text/javascript" src="<%= ResolveUrl("~/jquery/js/idle-timer.min.js")%>"></script> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true"> </asp:ToolkitScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> . . . <asp:ImageButton ID="DeleteRequest" runat="server" Width="50px" CssClass="CommentButton" ImageUrl="~/Images/DeleteComment.png" ToolTip="حذف طلب تمديد مهلة الإجابة" /> . . . <asp:panel id="Panel2" runat="server" CssClass="auto-style13" Height="131px" Width="520px" Style="display:none"> <table width="100%" class="auto-style12"> <tr> <td align="center" colspan="4" class="auto-style16"> <asp:Label ID="DeleteRequestMessage" runat="server" CssClass="auto-style17" Height="45px" Text="Label" Width="450px"></asp:Label> </td> </tr> <tr> <td colspan="4" align="center"> <asp:Button ID="ClosePanel2" runat="server" BackColor="#6262FF" CausesValidation="False" ForeColor="White" Height="40px" onMouseOut="this.className='Buttonout'" onMouseOver="this.className='Buttonhover'" style="text-align: center; font-size: 28px; font-family: sc_AMEEN; margin-left: 0px; -moz-border-radius: 15px;-webkit-border-radius: 15px;border-radius: 15px;" Text="استمرار" UseSubmitBehavior="False" Width="167px" /> </td> </tr> </table> </asp:panel> <asp:ModalPopupExtender ID="ModalPopupExtender2" runat="server" OkControlID="ClosePanel2" PopupControlID="Panel2" DropShadow="true" TargetControlID="DeleteRequest" BackgroundCssClass="modalBackground"> </asp:ModalPopupExtender> </ContentTemplate> </asp:UpdatePanel>
The event code that I want to run before showing the Panel2 and its content that I want to change dynamically according to the variable value "DeletingRequestMessage", is as following:
Protected Sub DeleteRequest_Click(sender As Object, e As ImageClickEventArgs) Handles DeleteRequest.Click Dim DeletingRequestMessage As String If Session("RequestStatus") <> "بالانتظار" Then DeletingRequestMessage = "لا يمكن حذف الطلب لأنه تم اتخاذ الإجراء بشأنه" DeleteRequestMessage.Text = DeletingRequestMessage GoTo DeleteRequestSkip End If If CInt(Session("RequestingUserIndx")) = TDClass.GetLoggingUserIndxValue(Session("username")) Or TDClass.CheckDataEntryRight(Session("username"), Session("RequestingUnitIndx")) Then DeletingRequestMessage = "حذف طلب تمديد مهلة الإجابة" DeleteRequestMessage.Text = DeletingRequestMessage PerformRequestDeletion() Else DeletingRequestMessage = "صلاحية حذف طلب تمديد مهلة الإجابة غير متوفرة" DeleteRequestMessage.Text = DeletingRequestMessage End If DeleteRequestSkip: ModalPopupExtender2.Show() End Sub
So how to solve this problem, so I can first run the PerformRequestDeletion() procedure and then show the Panel2 with the label message with variable value DeletingRequestMessage ?
Please help with great thanks
Saturday, September 8, 2018 11:10 AM
Answers
-
User839733648 posted
Hi alihusain_77,
According to your description and code, I suggest that you could add another label and then set the TargetControlD as its id.
This is because that if you set the TargetControIID property of ModalPopupExtender to a button control then its server side click event code do not get executed.
It is unreasonable to delete the attribute TargetControIID since Ajax ModalPopu Extende needs a TargetControlID when you add that control.
So you should create another control and set the TargetControlD as its id.
Besides, you could change the label’s value by finding its ID then modify the Text.
For more details, you could refer to the code below.
.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery-3.3.1.min.js")%>"></script> <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/idle-timer.min.js")%>"></script> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:ImageButton ID="DeleteRequest" runat="server" Width="50px" CssClass="CommentButton" ImageUrl="~/Images/delete.png" ToolTip="حذف طلب تمديد مهلة الإجابة" OnClick="DeleteRequest_Click" /> <asp:Label ID="Label1" runat="server" Text=" " ></asp:Label> <asp:Panel ID="Panel2" runat="server" CssClass="auto-style13" Height="131px" Width="520px" Style="display: none"> <table width="100%" class="auto-style12"> <tr> <td align="center" colspan="4" class="auto-style16"> <asp:Label ID="DeleteRequestMessage" runat="server" CssClass="auto-style17" Height="45px" Text="Label" Width="450px"></asp:Label> </td> </tr> <tr> <td colspan="4" align="center"> <asp:Button ID="ClosePanel2" runat="server" BackColor="#6262FF" CausesValidation="False" ForeColor="White" Height="40px" onMouseOut="this.className='Buttonout'" onMouseOver="this.className='Buttonhover'" Style="text-align: center; font-size: 28px; font-family: sc_AMEEN; margin-left: 0px; -moz-border-radius: 15px; -webkit-border-radius: 15px; border-radius: 15px;" Text="استمرار" UseSubmitBehavior="False" Width="167px" /> </td> </tr> </table> </asp:Panel> <asp:ModalPopupExtender ID="ModalPopupExtender2" runat="server" OkControlID="ClosePanel2" PopupControlID="Panel2" DropShadow="true" TargetControlID="Label1" BackgroundCssClass="modalBackground" > </asp:ModalPopupExtender> </ContentTemplate> </asp:UpdatePanel> </asp:Content>
code behind.
Protected Sub DeleteRequest_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs) Dim tb As Label = CType(Panel2.FindControl("DeleteRequestMessage"), Label) tb.Text = "the text that you want to show" ModalPopupExtender2.Show() End Sub
result:
Best Regards,
Jenifer
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, September 10, 2018 10:19 AM