afetr点击asp按钮页面正在加载,但事件没有加注 [英] afetr click on asp button the page is loading but the event is not raise
本文介绍了afetr点击asp按钮页面正在加载,但事件没有加注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
源代码:
< 表格 id = contact-form <% - < span class =code-attribute> action = http://inthe7heaven.com/homeshop- html / php / contact.php - % > >
< label > ; 名称(必填)< / label >
<% - <输入名称= contact-name type = text> - %>
< asp:TextBox ID = txtname runat < span class =code-keyword> = server > < / asp:TextBox >
< label > 电子邮件(必填)< / label >
<% - <输入名称= contact-email type = text> - %>
< asp:TextBox ID = < span class =code-keyword> txtemail runat = server > < / asp:TextBox >
< label > 主题< / label >
<% - <输入名称= contact-subject type = text> - %>
< asp:TextBox ID = txtsubject runat = 服务器 > < / asp:TextBox >
< span class =code-keyword>< label > 消息< / label >
< span class =code-pagedirective><% - < textarea name = contact-消息 > < / textarea > - %>
< asp:TextBox ID = txtmessage runat = 服务器 > < / asp:TextBox >
<% - <输入类 = big type = submit value = 发送消息> - %> ;
< asp:按钮 ID = btnsubmit runat = server 文本 = 提交
CausesValidation = false onclick = btnsubmit_Click1 / >
<% - < asp:标签ID = Label1 runat = server Text = 标签 > < / asp:标签 > - %>
< / form >
protected void btnsubmit_Click1( object sender,EventArgs e)
{
MailMessage message = new MailMessage();
message.From = new MailAddress( <击> EmailRemoved@gmail.com 击>跨度>);
message.To.Add( new MailAddress(txtemail.Text.ToString()));
message.Subject = txtsubject.Text;
message.IsBodyHtml = true ;
message.Body = txtmessage.Text.Trim();
SmtpClient smtp = new SmtpClient();
smtp.Host = smtp.gmail.com;
smtp.EnableSsl = true ;
NetworkCredential NetworkCred = new NetworkCredential( < strike> EmailRemoved@gmail.com , PasswordRemoved 跨度>);
smtp.UseDefaultCredentials = true ;
smtp.Credentials = NetworkCred;
smtp.Port = 587 ;
smtp.Send(message);
ClientScript.RegisterStartupScript(GetType(), alert, alert('Email sent。');, true ) ;
}
更正了格式和语法问题。
已添加 pre
标签。
已删除电子邮件和密码。
[/编辑]
解决方案
您好Naramadhu
尝试以下步骤并运行您的申请:
1.在表格标签中添加runat =server。
2.删除操作<% - action =http://inthe7heaven.com/homeshop- HTML / PHP / contact.php - %> 中来自表格标签。
3.如果您想在发送邮件后重定向到Contact.php页面,请在结尾处写下response.redirect(../ contact.php)。 btn提交点击功能。
希望这样可行。
尝试修复表格标签上的操作
< form id =contact-form<% - action =http://inthe7heaven.com/homeshop-html/php/contact.php - %>> ;
to
< form runat =serverid =frmDefault>
除非你想改变代码背后的形式,否则我认为你的名字或设置表格标签的ID并不重要。
source code:
<form id="contact-form"<%-- action="http://inthe7heaven.com/homeshop-html/php/contact.php"--%>>
<label>Name(required)</label>
<%--<input name="contact-name" type="text">--%>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
<label>Email(required)</label>
<%--<input name="contact-email" type="text">--%>
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
<label>Subject</label>
<%--<input name="contact-subject" type="text">--%>
<asp:TextBox ID="txtsubject" runat="server"></asp:TextBox>
<label>Message</label>
<%--<textarea name="contact-message"></textarea>--%>
<asp:TextBox ID="txtmessage" runat="server"></asp:TextBox>
<%--<input class="big" type="submit" value="Send Message">--%>
<asp:Button ID="btnsubmit" runat="server" Text="SUBMIT"
CausesValidation="false" onclick="btnsubmit_Click1" />
<%-- <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>--%>
</form>
protected void btnsubmit_Click1(object sender, EventArgs e)
{
MailMessage message = new MailMessage();
message.From = new MailAddress("EmailRemoved@gmail.com");
message.To.Add(new MailAddress(txtemail.Text.ToString()));
message.Subject = txtsubject.Text;
message.IsBodyHtml = true;
message.Body = txtmessage.Text.Trim();
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("EmailRemoved@gmail.com", "PasswordRemoved");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(message);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
[Edit member="Tadit"]
Corrected formatting and grammatical issues.
Added pre
tags.
Email and Password Removed.
[/Edit]
解决方案
Hi Naramadhu
Try the below steps and run your application:
1.Add runat="server" in form tag.
2.Remove the action "<%-- action="http://inthe7heaven.com/homeshop-html/php/contact.php"--%>" from the form tag.
3.If you want to redirect to "Contact.php" page after sending the mail, write response.redirect("../contact.php") at the end of btnSubmit click fuction.
Hope this will work.
Try fixing the action on your form tag
<form id="contact-form"<%-- action="http://inthe7heaven.com/homeshop-html/php/contact.php"--%>>
to
<form runat="server" id="frmDefault">
I don't think it matters much what you name or set the ID of the form tag to unless you want to alter the form in code behind.
这篇关于afetr点击asp按钮页面正在加载,但事件没有加注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文