This article uses the program source code to illustrate how to submit a form in a axwebbrowser in asp.net.
<tr bgcolor= #ffffff width= "100%" >
<TD Align=middle colspan=2>
<form id= "Form1" >
<input language=javascript Class=button Id=btton style= "border-top-style:groove;
Border-right-style:groove; Border-left-style:groove; Border-bottom-style:groove "onclick=" if
(typeof (Page_clientvalidate) = = ' function ') Page_clientvalidate (); "Type=submit value=" Start "onclick=" alert (' DD ') "name=btton></td></tr>
</form>
<input type= "button" onclick= "alert (' Test ')" id= "Button1" >
-----------------------------------------------------------------------------------
Form1.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using mshtml;
Namespace WindowSAPplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private AxSHDocVw.AxWebBrowser axWebBrowser1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
Public Form1 ()
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();
//
TODO: Add any constructor code after the InitializeComponent call
//
}
<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}
Code generated #region the Windows forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof
(Form1));
This.axwebbrowser1 = new Axshdocvw.axwebbrowser ();
This.button1 = new System.Windows.Forms.Button ();
This.button2 = new System.Windows.Forms.Button ();
((System.ComponentModel.ISupportInitialize) (This.axwebbrowser1)). BeginInit ();
This. SuspendLayout ();
//
AxWebBrowser1
//
This.axWebBrowser1.Enabled = true;
This.axWebBrowser1.Location = new System.Drawing.Point (80, 184);
This.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)
(Resources. GetObject ("Axwebbrowser1.ocxstate"));
This.axWebBrowser1.Size = new System.Drawing.Size (300, 150);
This.axWebBrowser1.TabIndex = 0;
//
Button1
//
This.button1.Location = new System.Drawing.Point (160, 96);
This.button1.Name = "Button1";
This.button1.Size = new System.Drawing.Size (88, 24);
This.button1.TabIndex = 1;
This.button1.Text = "Button1";
This.button1.Click + = new System.EventHandler (This.button1_click);
//
Button2
//
This.button2.Location = new System.Drawing.Point (304, 96);
This.button2.Name = "Button2";
This.button2.TabIndex = 2;
This.button2.Text = "Button2";
This.button2.Click + = new System.EventHandler (This.button2_click);
//
Form1
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (584, 397);
This. Controls.Add (This.button2);
This. Controls.Add (This.button1);
This. Controls.Add (This.axwebbrowser1);
This. Name = "Form1";
This. Text = "Form1";
((System.ComponentModel.ISupportInitialize) (This.axwebbrowser1)). EndInit ();
This. ResumeLayout (FALSE);
}
#endregion
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
object x = System.Reflection.Missing.Value;
axWebBrowser1.Navigate(@"E:\Documents and Settings\Administrator\桌面\dddd.htm",
ref x, ref x, ref x, ref x);
}
private void button2_Click(object sender, System.EventArgs e)
{
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)axWebBrowser1.Document;
mshtml.IHTMLFormElement f1 =(mshtml.IHTMLFormElement)doc.all.item ("form1",0);
((mshtml.IHTMLFormElement)(f1)).submit();
mshtml.IHTMLElement Element = (mshtml.IHTMLElement)doc.all.item("button1", 0);
Element.click();
}
}
}