我有一个string email = "metoo@email.com;abc@email.com;xyz@email.com;";
this.textBox1.text = email.Replace(";", string.Empty);
//to show emails in separate lines then use it in this way
this.textBox1.text = email.TrimEnd(';').Replace(";", Environment.NewLine);
表单,当提交'提交'点击按钮发送电子邮件。这可能需要一些时间,因此我想向用户添加处理模式,知道发生了什么事情。
现在我有模式显示但是只有在电子邮件发送失败后才会显示。我需要在单击按钮后立即显示此模式,然后在电子邮件操作发送或发送失败后关闭。
如果我的页面失败,则当前显示错误消息。
我的HTML
ASP.Net
我的 <div class="form-group">
<div class="col-xs-12">
<div class="pull-right">
<asp:LinkButton ID="pg3button" runat="server" OnClick="pg3button_Click" CssClass="btn btn-primary"><span aria-hidden="true" class="glyphicon glyphicon-ok"></span> Send & complete</asp:LinkButton>
</div>
</div>
</div>
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<asp:UpdatePanel ID="upModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">
<asp:Label ID="lblModalTitle" runat="server" Text="">Processing</asp:Label>
</h4>
</div>
<div class="modal-body">
<asp:Label ID="lblModalBody" runat="server" Text="">
<p class="text-center">IMAGE GOES HERE</p>
</asp:Label>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
提交按钮后面的代码是
onclick
我还尝试将以下代码移到protected void pg3button_Click(object sender, EventArgs e)
{
try
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
upModal.Update();
//Create the msg object to be sent
MailMessage msg = new MailMessage();
//Add your email address to the recipients
msg.To.Add("test@test.co.uk");
//Configure the address we are sending the mail from
MailAddress address = new MailAddress("test@test.co.uk");
msg.From = address;
//Append their name in the beginning of the subject
msg.Subject = "Enquiry";
msg.Body = Label1.Text + " " + Session["pg1input"].ToString()
+ Environment.NewLine.ToString() +
Label2.Text + " " + Session["pg1dd"].ToString()
+ Environment.NewLine.ToString() +
Label3.Text + " " + Session["pg2"].ToString();
//Configure an SmtpClient to send the mail.
SmtpClient client = new SmtpClient("smtp.live.com", 587);
client.EnableSsl = true; //only enable this if your provider requires it
//Setup credentials to login to our sender email address ("UserName", "Password")
NetworkCredential credentials = new NetworkCredential("test@test.co.uk", "Password10");
client.Credentials = credentials;
//MODAL CODE TO GO HERE
//Send the msg
client.Send(msg);
Response.Redirect("/Session/pg4.aspx");
}
catch
{
//If the message failed at some point, let the user know
lblResult.Text = "<div class=\"form-group\">" + "<div class=\"col-xs-12\">" + "There was a problem sending your request. Please try again." + "</div>" + "</div>" + "<div class=\"form-group\">" + "<div class=\"col-xs-12\">" + "If the error persists, please contact us." + "</div>" + "</div>";
}
}
try
我想如果有一种方法我可以拨打我的按钮,然后点击一个功能,其中包含我的电子邮件代码,但我是 ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
upModal.Update();
和ASP.Net
的新手
我所需要的只是在页面重定向(如果成功)或显示错误时单击按钮并显示模式时显示模式
答案 0 :(得分:2)
只需使用JavaScript代替服务器端代码进行模态弹出
当您单击按钮时添加OnClinetClick事件并使用类似
的javascript函数<asp:button id="pg3button" runat="server" OnClick="pg3button_Click" OnClientclick="ShowPopup();"></asp:button>
<script>
function ShowPopup()
{
$('#myModal').modal();
}
<script>
还删除了更新面板,在此上下文中没有用。
答案 1 :(得分:1)
您正在使用reigisterStartupScript函数注册显示模态的脚本。由于它是一个脚本,因此只有在执行c#代码后才会在页面上注册。尝试在按钮的onClientClick事件上将其移动到aspx页面。
$( "#buttonId" ).click(function() {
$('#myModal').modal();
});