我有一个函数可以加载联系人列表,并在每个联系人旁边放置一个复选框。任何被勾选的联系人都会收到一封电子邮件。但在我的电子邮件函数中,列表总是返回为零。
列表代码:
<div id="viewMenuDropFollowup" style="top:0px;right:10px; text-align: left; display:none">
<strong>Email to</strong> <a onclick="OpenEmail()" style="float:right;font-weight:bold;cursor:pointer">X</a>
<ul runat="server" id="ulCRMContacts">
</ul>
<asp:TextBox runat="server" ID="txtEmailTo" ></asp:TextBox>
<asp:LinkButton runat="server" ID="btnEmail3" CssClass="btnEmail" OnClick="btnEmail_Click" Text="Email" ToolTip="Email to selected contacts" OnClientClick="return CheckEmail()"></asp:LinkButton>
</div>
<a id="btnOpenEmail" onclick="OpenEmail()" class="EmailClass"><strong>Email</strong></a>
function OpenEmail() {
if (document.getElementById("viewMenuDropFollowup").style.display === "block") {
document.getElementById("viewMenuDropFollowup").style.display = "none";
} else {
document.getElementById("viewMenuDropFollowup").style.display = "block";
}
}加载联系人的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadContacts();
}
}
protected void LoadContacts()
{
Customer c = new Customer(int.Parse(CustomerID));
foreach (Customer.CustomerContact cc in c.Contacts)
{
HtmlGenericControl li = new HtmlGenericControl("li");
CheckBox cb = new CheckBox();
cb.ID = "cbCRMContact_" + cc.ID;
cb.Checked = true;
if (!string.IsNullOrEmpty(cc.Email))
{
cb.Text = cc.Email;
cb.TextAlign = TextAlign.Right;
li.Controls.Add(cb);
ulCRMContacts.Controls.Add(li);
}
}
GetControls(ulCRMContacts.Controls);
}我放入行GetControls(ulCRMContacts.Controls);,看看我是否可以得到控件,它在这里工作得很好。但是,当我再次尝试在电子邮件函数中调用GetControls(ulCRMContacts.Controls);时,它返回零。
protected void btnEmail_Click(object sender, EventArgs e)
{
if (EmailFollowup(new lookupCRMCustomerContact(Company.Current.CompanyID, int.Parse(Request.QueryString["CustID"]))))
{
DisplayMsg("Follow up has been emailed");
}
else
{
DisplayMsg("An Error Occurred sending email. Please contact Support");
}
}
public bool EmailFollowup(lookupCRMCustomerContact q)
{
GetControls(ulCRMContacts.Controls);
}这就像它一离开LoadContacts函数就丢失了ulCRMContacts中的值。
https://stackoverflow.com/questions/38398418
复制相似问题