locked
how to ie automation in asp.net c# RRS feed

Answers

  • User-718146471 posted

    Oh, you want a simple contact form.  Ok, there are many examples all over the Internet.  I reference a previous posting that has the complete code:

    Here is the complete code. http://forums.asp.net/t/1915773.aspx?how+to+create+simple+contact+us+form+and+save+those+values+as+well+

    email.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Email.aspx.cs" Inherits="Email" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style type="text/css">
            .auto-style1 {
                width: 362px;
            }
            .auto-style2 {
                width: 123px;
                vertical-align:top;
            }
            .auto-style3 {
                width: 193px;
            }
            .auto-style4 {
                width: 75px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <table style="vertical-align:top;">
            <tr><td class="auto-style2">First Name:</td><td class="auto-style3">
                <asp:TextBox ID="fname" runat="server" Width="174px"></asp:TextBox>
                </td><td class="auto-style4">Last Name:</td><td class="auto-style1">
                <asp:TextBox ID="lname" runat="server" Width="346px"></asp:TextBox>
                </td></tr>
            <tr><td class="auto-style2">Email:</td><td class="auto-style1" colspan="3">
                <asp:TextBox ID="email" runat="server" TextMode="Email" Width="620px"></asp:TextBox>
                </td></tr>
            <tr><td class="auto-style2">Phone:</td><td class="auto-style1" colspan="3">
                <asp:TextBox ID="phone" runat="server" TextMode="Phone"></asp:TextBox>
                </td></tr>
            <tr><td class="auto-style2">Comments:</td><td class="auto-style1" colspan="3">
                <asp:TextBox ID="comments" runat="server" Height="53px" TextMode="MultiLine" Width="623px"></asp:TextBox>
                </td></tr>
            <tr><td class="auto-style2">&nbsp;</td><td class="auto-style1" colspan="3">
                <asp:Button ID="btnSend" runat="server" Text="Send Email" OnClick="SendMail" />
                </td></tr>
        </table>
        </div>
        </form>
    </body>
    </html>

    email.aspx.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Net.Mail;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Configuration;
    
    public partial class Email : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        //Code for the Reset event (will reset form data):
    
        protected void Reset(object s, EventArgs e)
        {
            fname.Text = "";
            lname.Text = "";
            email.Text = "";
            phone.Text = "";
            comments.Text = "";
        }
    
        //Code for the SendMail Event; will send email and write info in email into database:
    
        protected void SendMail(object sender, EventArgs e)
        {
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(email.Text);
            mail.To.Add("EMAIL ADDRESS WHERE YOU'D LIKE THE MESSAGE SENT");
            mail.Subject = "Contact Us";
            mail.IsBodyHtml = true;
            mail.Body += "First Name: " + fname.Text + "<br />";
            mail.Body += "Last Name: " + lname.Text + "<br />";
            mail.Body += "Comments: " + comments.Text + "<br />";
            mail.Body += "Phone Number: " + phone.Text + "<br />";
    
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "NAME OF SMTP RELAY SERVER";
            smtp.Send(mail);
            insertInfo();
        }
    
        protected void insertInfo(object sender, EventArgs e)
        {
            SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["WEB.CONFIG CONNECTION STRING NAME"].ToString());
    
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.CommandText = "INSERT INTO TABLE NAME (fname, lname, email, phone, comment) VALUES (@fname, @lname, @email, @phone, @comments)";
            cmd.Connection = myConnection;
    
            cmd.Parameters.Add("@fname", fname.Text);
            cmd.Parameters.Add("@lname", lname.Text);
            cmd.Parameters.Add("@email", email.Text);
            cmd.Parameters.Add("@phone", phone.Text);
            cmd.Parameters.Add("@comments", comments.Text);
    
            myConnection.Open();
            cmd.ExecuteNonQuery();
            myConnection.Close();
        }
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 19, 2014 2:15 PM
  • User465171450 posted

    You don't do this with asp.net. ASP.Net is not meant to be opening IE, performing automation on it. ASP.Net is a server-side technology meant for generating forms, not using IE to fill out others. This is something you can do in a tradition windows forms development environment and the webbrowser control.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 19, 2014 10:51 PM

All replies

  • User-718146471 posted

    Ok, let's start with the basics, exactly what are you trying to do?  IE Automation of this URL tells me little to nothing about your requirement.

    Thursday, June 19, 2014 1:58 PM
  • User1490241673 posted

    hello sir ..

    have you seen this url http://www.joelrendall.com/webdesign/lake-bays-association-2/. it has leave a reply form including three textbox Like Name,email and website .

    i want fill the value on these textbox to backend code using IE Automation so please tell me how do this in asp.net .

    Thursday, June 19, 2014 2:08 PM
  • User-718146471 posted

    Oh, you want a simple contact form.  Ok, there are many examples all over the Internet.  I reference a previous posting that has the complete code:

    Here is the complete code. http://forums.asp.net/t/1915773.aspx?how+to+create+simple+contact+us+form+and+save+those+values+as+well+

    email.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Email.aspx.cs" Inherits="Email" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style type="text/css">
            .auto-style1 {
                width: 362px;
            }
            .auto-style2 {
                width: 123px;
                vertical-align:top;
            }
            .auto-style3 {
                width: 193px;
            }
            .auto-style4 {
                width: 75px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <table style="vertical-align:top;">
            <tr><td class="auto-style2">First Name:</td><td class="auto-style3">
                <asp:TextBox ID="fname" runat="server" Width="174px"></asp:TextBox>
                </td><td class="auto-style4">Last Name:</td><td class="auto-style1">
                <asp:TextBox ID="lname" runat="server" Width="346px"></asp:TextBox>
                </td></tr>
            <tr><td class="auto-style2">Email:</td><td class="auto-style1" colspan="3">
                <asp:TextBox ID="email" runat="server" TextMode="Email" Width="620px"></asp:TextBox>
                </td></tr>
            <tr><td class="auto-style2">Phone:</td><td class="auto-style1" colspan="3">
                <asp:TextBox ID="phone" runat="server" TextMode="Phone"></asp:TextBox>
                </td></tr>
            <tr><td class="auto-style2">Comments:</td><td class="auto-style1" colspan="3">
                <asp:TextBox ID="comments" runat="server" Height="53px" TextMode="MultiLine" Width="623px"></asp:TextBox>
                </td></tr>
            <tr><td class="auto-style2">&nbsp;</td><td class="auto-style1" colspan="3">
                <asp:Button ID="btnSend" runat="server" Text="Send Email" OnClick="SendMail" />
                </td></tr>
        </table>
        </div>
        </form>
    </body>
    </html>

    email.aspx.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Net.Mail;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Configuration;
    
    public partial class Email : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        //Code for the Reset event (will reset form data):
    
        protected void Reset(object s, EventArgs e)
        {
            fname.Text = "";
            lname.Text = "";
            email.Text = "";
            phone.Text = "";
            comments.Text = "";
        }
    
        //Code for the SendMail Event; will send email and write info in email into database:
    
        protected void SendMail(object sender, EventArgs e)
        {
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(email.Text);
            mail.To.Add("EMAIL ADDRESS WHERE YOU'D LIKE THE MESSAGE SENT");
            mail.Subject = "Contact Us";
            mail.IsBodyHtml = true;
            mail.Body += "First Name: " + fname.Text + "<br />";
            mail.Body += "Last Name: " + lname.Text + "<br />";
            mail.Body += "Comments: " + comments.Text + "<br />";
            mail.Body += "Phone Number: " + phone.Text + "<br />";
    
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "NAME OF SMTP RELAY SERVER";
            smtp.Send(mail);
            insertInfo();
        }
    
        protected void insertInfo(object sender, EventArgs e)
        {
            SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["WEB.CONFIG CONNECTION STRING NAME"].ToString());
    
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.CommandText = "INSERT INTO TABLE NAME (fname, lname, email, phone, comment) VALUES (@fname, @lname, @email, @phone, @comments)";
            cmd.Connection = myConnection;
    
            cmd.Parameters.Add("@fname", fname.Text);
            cmd.Parameters.Add("@lname", lname.Text);
            cmd.Parameters.Add("@email", email.Text);
            cmd.Parameters.Add("@phone", phone.Text);
            cmd.Parameters.Add("@comments", comments.Text);
    
            myConnection.Open();
            cmd.ExecuteNonQuery();
            myConnection.Close();
        }
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 19, 2014 2:15 PM
  • User1490241673 posted

    no sir.

    you dont have understand sir..

    please give your skype id ..

    i will cenvent you on skype ..

    Thursday, June 19, 2014 2:21 PM
  • User-718146471 posted

    Can't do skype from here, sorry.  You pointed out the contact fields in that site which is a contact form.  Specifically, when John Q User clicks submit, what are you wanting this thing to do?  Send an email?  Enter the data into a database? Something else?

     

    Thursday, June 19, 2014 2:37 PM
  • User1490241673 posted

    sir please see this url  http://www.methodsandtools.com/tools/opentwesbst.php .

     http://www.joelrendall.com/webdesign/lake-bays-association-2/. it has leave a reply form including three textbox Like Name,email and website .

    i want to fill tree textbox using htmlelement class ..

    i want fill the value on these textbox to backend code using IE Automation so please tell me how do this in asp.net 

    Thursday, June 19, 2014 3:37 PM
  • User465171450 posted

    You don't do this with asp.net. ASP.Net is not meant to be opening IE, performing automation on it. ASP.Net is a server-side technology meant for generating forms, not using IE to fill out others. This is something you can do in a tradition windows forms development environment and the webbrowser control.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 19, 2014 10:51 PM