不能得到的HTML文本框的值 [英] Cannot Get the HTML textbox value

查看:136
本文介绍了不能得到的HTML文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是这样的HTML表单:

I have an html form that goes like this:

 <form id="main-contact-form" name="contact-form" method="post" action="test.aspx">
                            <div class="form-group">
                                <input id="txtname" type="text" class="form-control" placeholder="Name" required>
                            </div>
                            <div class="form-group">
                                <input id="txtemail" type="email" class="form-control" placeholder="Email" required>
                            </div>
                            <div class="form-group">
                                <input id="txtsubject" type="text" class="form-control" placeholder="Subject" required>
                            </div>
                            <div class="form-group">
                                <textarea id="txtmessage" class="form-control" rows="8" placeholder="Message" required></textarea>
                            </div>
                            <button type="submit" class="btn btn-default">Send Message</button>
                        </form>

现在,我想做的是让用户输入文本框一旦按下发送键。对于现在的我已经集成到这个标记一个aspx,因此它可以发送到电子邮件。在这里,它是:

Now, What I wanted to do is to get the user's input into the textboxes once they push the send button.. For now I have an aspx integrated to this markup so it can send to an email. Here it is :

MailMessage mail = new MailMessage ();
        mail.From = new System.Net.Mail.MailAddress ("username@domain.com");
        // The important part -- configuring the SMTP client
        SmtpClient smtp = new SmtpClient ();
        smtp.Port = 587;   // [1] You can try with 465 also, I always used 587 and got success
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
        smtp.UseDefaultCredentials = false; // [3] Changed this
        smtp.Credentials = new NetworkCredential ("username@domain.com", "password");  // [4] Added this. Note, first parameter is Email Address of the sender and the next parameter is the password.
        smtp.Host = "smtp.gmail.com";

        //recipient address 
        mail.To.Add (new MailAddress ("user1@gmail.com"));
        mail.To.Add (new MailAddress ("user2@gmail.com"));

        //Formatted mail body 
        mail.IsBodyHtml = true;
        mail.Body = Request.Form ["txtmessage"];
        mail.Subject = Request.Form ["txtsubject"];
        string st = "This is a Test  Message" ;

        mail.Body = st;
        smtp.Send (mail);

有关的记录,它已经是曾经在HTML中的按钮被按下,但它只发送硬codeD串在我的C#code和它没有得到其他文本框的值发送电子邮件。

For the record, it is already sending the email once the button in the html is pushed but it only sends the hard coded string in my c# code and it doesnt get the value of the other textboxes.

您能帮我吗?

推荐答案

通过名字来得到它。

<input id="txtname" name="txtname" type="text" class="form-control" placeholder="Name" required>

这篇关于不能得到的HTML文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆