[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 809
  • Last Modified:

Pass information from winform to webform to display info on webform.

Is there a way in visual basic .net to pass information from a windows form to a webform when a user clicks a button on the winform. I need to send the correct data to the webform to display information that pertains to the winform. I appreciate any help in this matter, thanks.

Mike
0
xrosem
Asked:
xrosem
  • 4
  • 4
1 Solution
 
ptakjaCommented:
Do you want to populate fields on a web form, or click a button on the WinForm and have the browser open up to a specific page where you can extract data?

IF the latter, you can use QueryStrings to pass the info:

In your WINFORM app when the button is clicked:

Dim URL as string = String.Format("http://www.mywebsite.com/MyPage.aspx?Data1={0}&Data2={1}", 190, "catalog")
Process.Start(URL)  'Kick off default browser to URL listed.

In this example, your default browser would open to the page specified.

Then in your WebForm page named "MyPage.aspx" you would have some code to pull the QueryString data:

Data1 = 190
Data2 = "catalog"

from this then you can fill fields on the form, or perform db lookups, etc...
0
 
xrosemAuthor Commented:
I would like the winform to popluate the webform fields.
0
 
xrosemAuthor Commented:
On the later part where you click a button on the winform how does that code give the webform the information.

Dim URL as string = String.Format("http://www.mywebsite.com/MyPage.aspx?Data1={0}&Data2={1}", 190, "catalog")
Process.Start(URL)  'Kick off default browser to URL listed.

Is data1 and data2 string variables and they get passed? Then you reference the variables on the webform when it is open?
 
I appreciate your help.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
xrosemAuthor Commented:
It states that process is not declared. What  do i need to declare it as to get the page to fire? Or what is the process.start?
0
 
ptakjaCommented:
Data1 & Data2 are called "Query Strings". They get passed to the web app via the URL. In my example, URL would look like this after the String.Format is done:

URL ==> "http://www.mywebsite.com/MyPage.aspx?Data1=190&Data2=catalog"


You can use the QueryString method of the Request object to pull the name/value pairs off the URL.

Request.QueryString("<var name>")

All values are returned as strings. So if you have numeric data, you need to covert them to the appropriate type

Using the data from my original example:

Dim intData1 As Integer = Convert.ToInt32(Request.QueryString("Data1"))   'Cast data as integer
Dim strData2 As String = Request.QueryString("Data2")

Data1 & Data2 are arbitrary names. You can name them anything you want. And you can have as many querystring arguments as you like within the limits of the URL length (which I think is 1024 chars). Just make sure each name/value pair is separated from the next by the "&" symbol.
0
 
ptakjaCommented:
Sorry...the Process object is part of System.Diagnostics

So either add "Imports System.Diagnostics" outside your class or explicitly call it out as:

System.Diagnostics.Process.Start(blah blah)
0
 
ptakjaCommented:
The "?" after the page name tells the the URL parser that there are query strings in the URL. That is what populates the Request Object's Querystring collection.
0
 
xrosemAuthor Commented:
ptakja, thanks it worked great. You are truly awsome!!! Thanks a bunch.

Mike
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now