For Microsoft Visual Basic .NET versions of this article, see
311294.
This task content
Summary
ASPX Visual C # .net reference
Summary This step-by-step guide introduces you how to use Visual C # .NET
The WebBrowser ActiveX control performs form data posted.
Visual C # .NET can be used
WebBrowser ActiveX control, by using the HTTP server (such as Microsoft Internet Information Server (IIS))
POST method to send data.
To perform posts, you can use
Webbrowser control
NaviGate or
NaviGate2 method, where only URLs, postData and headers parameters are used.
About other parameters and
For more information on NaviGate2, please visit the following Microsoft Web site:
NaviGate2 method http://msdn.microsoft.com/library/default.asp?url=/workshop/ Browser / WebBrowser / Reference / Methods / NaviGate2.asp is
Navigation and
Posting Form Data is called to the HTTP server, the URL parameter must specify a valid address, the PostData parameter must contain an array, and the headers parameter must contain a string containing the following HTTP headers:
Content-Type: Application / X-WWW-FORM-URLENCODED This header indicates that the data passed is encoded according to the HTML specification.
Note that the Internet Explorer Script object model has one
Window object, and one in this object
Navigate. this
The NaviGate method only accepts the URL and cannot be used to post data to the web server.
Back to top
ASPX To test the following code example, save the following Active Server Pages (.aspx) file to the Navpost.aspx file in a directory on IIS. IIS should regard this directory as a virtual root that has execute permissions for this script.
<%
Cflavor = Request ("Flavor")
CNAME = Request ("FNAME")
%>
Hello, <% = CNAME%>.
One Scoop Of <% = CFLAVOR%> COMING RIGHT UP!
Body>
Html>
Back to top
Visual C # .NET wants to demonstrate in C #
POST method, follow these steps:
Start a Windows application in Visual C # .NET. FORM1 is created by default. Add the following controls to Form1: Object Name Text
-------------------------------------------------- -----------------
Label LBLName First Name
Label LBLFLAVOR FLAVOR
Button cmdsubmit SubmitCombo Box CBOFLAVOR
Text box txtboxname
Click View, and then click Toolbox. Right-click Toolbox to display the Custom Toolbox dialog. On the COM Component tab, click the Select Microsoft Web Browser check box, then click OK. Add a WebBrowser control to the form. AxWebBrowser1 is its default name. Import NameSpace System.Text. The ASCIIEnCoding class provides a way to convert a string into a byte array. Using system.text;
Insert the following code to Form1.cs: Private Void Form1_Load (Object Sender, System.EventArgs E)
{
CBOFLAVOR.Items.Add ("vanilla");
CBOFLAVOR.Items.Add ("chocolate");
CBOFLAVOR.Items.Add ("strawberry");
CBOFLAVOR.SelectedIndex = 0;
}
Private void cmdsubmit_click (Object Sender, System.Eventargs E)
{
Object vPost;
Object vheaders;
String cflavor;
String cparamflavor;
String cparamname;
String cpostdata;
String cseparator;
Object Oempty = ""
Object Ourl = "http://
Cflavor = cboflavor.selectedItem.toString ();
CParamflavor = "flavor =";
Cseparator = "&";
CParamname = "fname =";
CPostData = CParamname TxtBoxName.Text Cseparator CParamflavor CFlavor;
Vheaders = "Content-Type: Application / X-WWW-FORM-URLENCODED" "/ N" "/ r";
vPost = asciiencoding.ascii.getbytes (cpostdata);
AxWebBrowser1.naviGate2 (Ref Orl, Ref Oempty, Ref Oempty, Ref Vpost, Ref Vheaders);
// or you can use the Navigate Method As Follows
//axwebbrowser1.navigate ("http:// } Modify the URL in the call to NaviGate2 as needed. Type your name in the name box, select a Flavor, and then click Submit Command Button. The data in the form will be posted to the HTTP server and the response will appear in the browser window you can see. Back to top Refer to other information, click the article number below to see the article in the Microsoft Knowledge Base: 174923 How To: Use the PostData Parameter In WebBrowser Control WebBrowser controls and methods, properties, and more information about its public events, please visit the following Microsoft Web site: Http://msdn.microsoft.com/workshop/browser/webbrowser/reflist_vb.asp For HTML specification for the form content type, visit the following W3C Web site: Http://www.w3.org/tr/HTML4/INTERACT /FORMS.HTML #H-17.13.4.1 For more information on developing web-based solutions for Microsoft Internet Explorer, please visit the following Microsoft Web site: Http://msdn.microsoft.com/workshop/entry.asphttp://msdn.microsoft.com/iep.asp?fr=0&sd=msdn/Highlights/iep.asp?fr=0&sd=msdn Back to top The information in this article applies to: Microsoft Visual C # .NET (2002) Microsoft Internet Explorer (Programming) 5.5 Microsoft Internet Explorer (programming) 6.0 Recent Updated: 2003-11-4 (2.0) Keywords: Kbhowto KbhowTomaster Kbinfo Kbsample KB313068 KBAUDDEVELOPER