我在过去几个小时内完成了所有文章,试图在ModalPopupExtender中包含的标签中显示动态标签文本,但没有成功。标记代码中的标签文本有效,但我无法从代码隐藏中引入任何内容。建议包括从更新面板到JavaScript的所有内容。也许我只是得出结论,我的ModalPopupExtender被诅咒了;请帮我解除诅咒。代码:
<style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=70);
opacity: 0.7;
}
.modalPopup
{
background-color: #ffffdd;
border-width: 3px;
border-style: solid;
border-color: Gray;
padding: 3px;
width: 250px;
}
</style>
<script type="text/javascript">
function ShowModalPopup() { var modal = $find("<%= mpeNewInviteSuccess.ClientID %>"); modal.show(); }
</script>
<%--success popup items--%>
<div style="display: none;">
<asp:Button ID="btnDummy" OnClick="btnDummy_Click" OnClientClick="ShowModalPopup" UseSubmitBehavior="true" runat="server" /></div>
<div id="divNewInviteSuccess" class="modalPopup" runat="server">
<div>
<asp:Label ID="lblNewInviteSuccess" runat="server" /></div>
<br />
<div><asp:Button ID="btnNewInviteReturn" Text="OK" CssClass="button" OnClientClick="return HideModalPopup()" runat="server" /></div>
</div>
<act:ModalPopupExtender ID="mpeNewInviteSuccess" TargetControlID="btnDummy" BackgroundCssClass="modalBackground"
PopupControlID="divNewInviteSuccess" DropShadow="true" BehaviorID="mpe" runat="server" />
protected void btnDummy_Click(object sender, EventArgs e)
{
mpeNewInviteSuccess.Show();
//create object of button from sender
Button button = sender as Button;
//get command argument
string cmdArgument = button.CommandArgument;
//split command argument based on comma separator and convert to a list
List<string> lstPassedValues = new List<string>(cmdArgument.Split(','));
//ListView lsv = Helpers.FindChild(Page, "lsvNewInvite") as ListView;
//create successful message from list
string SuccessMsg = "Success! Your invitation was sent to " + lstPassedValues[0] + " " + lstPassedValues[1] + " (" + lstPassedValues[2] + ").";
lblNewInviteSuccess.Text = SuccessMsg;
mpeNewInviteSuccess.Show();
}
protected void lsvNewInvite_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
//place cursor in txtFirstName
var lsv = Helpers.FindChild(this, "lsvNewInvite") as ListView;
TextBox txt = Helpers.FindChild(lsv, "txtFriendFirstName") as TextBox;
if (txt != null)
txt.Focus();
//set up parameter values
ListViewItem item = e.Item as ListViewItem;
var userInfoList = UserInfo.UserInfoGetByUserID(UserID);
UserInformation = userInfoList.FirstOrDefault();
var user = UserInformation.UserID;
string firstName = (item.FindControl("txtFriendFirstName") as TextBox).Text.ToString();
string lastName = (item.FindControl("txtFriendLastName") as TextBox).Text.ToString();
string eMail = (item.FindControl("txtFriendEmail") as TextBox).Text.ToString();
try
{
//code to be inserted into DB
srcNewInvite.InsertParameters["FriendID"].DefaultValue = "0";
srcNewInvite.InsertParameters["User"].DefaultValue = user.ToString();
srcNewInvite.InsertParameters["FirstName"].DefaultValue = firstName;
srcNewInvite.InsertParameters["LastName"].DefaultValue = lastName;
srcNewInvite.InsertParameters["Email"].DefaultValue = eMail;
srcNewInvite.InsertParameters["Date"].DefaultValue = DateTime.Now.ToString();
}
catch (Exception ex)
{
throw ex;
}
finally
{
EmailNewInvitee(firstName, lastName, eMail);
//concatenate these values and make it as a comma-separated string
string concatenatedValue = firstName + "," + lastName + "," + eMail;
btnDummy.CommandArgument = concatenatedValue;
//show success message by programatically "clicking" hidden button
//trigger the button click event
btnDummy_Click(this.btnDummy, e);
pnlMain.Visible = false;
}
}
}
答案 0 :(得分:0)
在“品牌X”网站(OK,forums.asp.net)的帮助下,我能够解决问题,如下面的代码所示。主要答案是使用UpdatePanel。我之前没有成功使用过UpdatePanel,所以我不确定这次有什么不同。
<asp:UpdatePanel ID="udpModalSuccess" runat="server">
<ContentTemplate>
<%--success popup items--%>
<div style="display: none;">
<asp:Button ID="btnDummy" UseSubmitBehavior="true" OnClientClick="ShowModalPopup" OnClick="btnDummy_Click" runat="server" />
<%--Dummy Button added to assign the target controlid of PopupExtender--%>
<asp:Button ID="btnDummyButton" UseSubmitBehavior="true" runat="server" Text="DummyButton" Style="display: none;" />
</div>
<asp:Panel ID="pnlNewInviteSuccess" class="modalPopup" runat="server">
<div><asp:Label ID="lblNewInviteSuccess" runat="server" /></div>
<br />
<div><asp:Button ID="btnNewInviteReturn" Text="OK" CssClass="button" runat="server" /></div>
</asp:Panel>
<%--Here I have changed the TargetControlID property--%>
<act:ModalPopupExtender ID="mpeNewInviteSuccess" TargetControlID="btnDummyButton" CancelControlID="btnNewInviteReturn"
BackgroundCssClass="modalBackground" PopupControlID="pnlNewInviteSuccess" DropShadow="true"
BehaviorID="mpe" runat="server">
</act:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
<style type="text/css">
.modalBackground
{background-color: Gray; filter: alpha(opacity=70); opacity: 0.7;}
.modalPopup
{background-color: #ffffdd; border-width: 3px; border-style: solid; border-color: Gray; padding: 3px; width: 450px;}
</style>
protected void lsvNewInvite_ItemCommand(Object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
//place cursor in txtFirstName
var lsv = Helpers.FindChild(this, "lsvNewInvite") as ListView;
TextBox txt = Helpers.FindChild(lsv, "txtFriendFirstName") as TextBox;
if (txt != null)
txt.Focus();
//set up parameter values
ListViewItem item = e.Item as ListViewItem;
var userInfoList = UserInfo.UserInfoGetByUserID(UserID);
UserInformation = userInfoList.FirstOrDefault();
var user = UserInformation.UserID;
string firstName = (item.FindControl("txtFriendFirstName") as TextBox).Text.ToString();
string lastName = (item.FindControl("txtFriendLastName") as TextBox).Text.ToString();
string eMail = (item.FindControl("txtFriendEmail") as TextBox).Text.ToString();
try
{
//code to be inserted into DB
srcNewInvite.InsertParameters["FriendID"].DefaultValue = "0";
srcNewInvite.InsertParameters["User"].DefaultValue = user.ToString();
srcNewInvite.InsertParameters["FirstName"].DefaultValue = firstName;
srcNewInvite.InsertParameters["LastName"].DefaultValue = lastName;
srcNewInvite.InsertParameters["Email"].DefaultValue = eMail;
srcNewInvite.InsertParameters["Date"].DefaultValue = DateTime.Now.ToString();
}
catch (Exception ex)
{
throw ex;
}
finally
{
EmailNewInvitee(firstName, lastName, eMail);
//concatenate these values and make them as a comma-separated string
string concatenatedValue = firstName + "," + lastName + "," + eMail;
btnDummy.CommandArgument = concatenatedValue;
//show success message by programatically "clicking" hidden button
//trigger the button click event
btnDummy_Click(this.btnDummy, e);
pnlMain.Visible = false;
pnlNewInviteSuccess.Visible = true;
}
}
}
protected void btnDummy_Click(Object sender, EventArgs e)
{
//mpeNewInviteSuccess.Show();
//create object of button from sender
Button button = sender as Button;
//get command argument
string cmdArgument = button.CommandArgument;
//split command argument based on comma separator and convert to a list
List<string> lstPassedValues = new List<string>(cmdArgument.Split(','));
ListView lsv = Helpers.FindChild(Page, "lsvNewInvite") as ListView;
//create successful message from list
string SuccessMsg = "Success! Your invitation was sent to:<br><b> " + lstPassedValues[0] + " " + lstPassedValues[1] + " (" + lstPassedValues[2] + "</b>)";
lblNewInviteSuccess.Text = SuccessMsg;
//assign TargetControl id of ModalPopUpExtender to btnDummy
mpeNewInviteSuccess.TargetControlID = "btnDummy";
//show ModalPopup Extender
mpeNewInviteSuccess.Show();
}