Search KB Filter article types
Parameters CodeSample - Posting variables to a form and receiving on the target form
Categories: Application Parameters
Tags: Developers, Navigation, 1. Beginner, 2. Intermediate, Navigation, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
Revision: 1
Posted: 22/Nov/2009
Updated: 23/July/2010
Status: Publish
Types: Code

This article will have a few sections added to it soon, based on the following article type skeleton: CodeSample
Overview

This CodeSample shows an example of how to post variables to a Form in another domain, and how to receive in the target domain's Form.

The code is split into the "Sending" Form's code, and the "Receiving" Form's code. Those two are seperate forms, belonging to different applications, each in it's own project.

Link to downloading the sample application is supplied near the bottom of this article.

C# Code"Sending" Form
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        protected void mobjSubmitButton_Click(object sender, EventArgs e)
        {
            LinkParameters objLinkParameters = new LinkParameters();
            objLinkParameters.Target = "ReceivingFrame";
            objLinkParameters.Location = new Point(0, 0);
            objLinkParameters.Size = new Size(640, 480);
 
            string strArgs = this.mobjSearchTextBox.Text;
            if (!String.IsNullOrEmpty(strArgs))
            {
                strArgs.Replace((char)9, (char)32); // Replace Tab with space
                strArgs = this.RemoveDuplicateSpaces(strArgs);
 
                string[] arrArgs = strArgs.Split(new char[] { (char)9, (char)10, (char)13, (char)32 });
                for (byte bytIndex = 0; bytIndex < arrArgs.Length; bytIndex++)
                {
                    objLinkParameters.Form["prm" + bytIndex.ToString()] = arrArgs[bytIndex];
                }
            }
 
            Link.Open("http://localhost:1490/Post.Form1.wgx", objLinkParameters);
        }
 
        protected virtual string RemoveDuplicateSpaces(string strString)
        {
            while(strString.Contains("  "))
            {
                strString = strString.Replace("  ", String.Empty);
            }
            return strString;
        }
    }

"Receiving" Form
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            StringBuilder objStringBuilder = new StringBuilder();
            byte bytIndex = 0;
 
            foreach (string objArgument in this.Context.Arguments)
            {
                objStringBuilder.Append("Argument #" + bytIndex.ToString() + ":    ");
                objStringBuilder.Append("Key: " + objArgument + "    ");
                objStringBuilder.Append("Value: " + this.Context.Arguments[objArgument]);
                objStringBuilder.Append("\n");
 
                bytIndex++;
            }
            this.mobjArgumentsTextBox.Text = objStringBuilder.ToString();
        }
    }

VB.NET Code"Sending" Form
Public Class Form1
 
    Private Sub mobjSubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles mobjSubmitButton.Click
        Dim objLinkParameters As New LinkParameters()
        objLinkParameters.Target = "ReceivingFrame"
        objLinkParameters.Location = New Point(0, 0)
        objLinkParameters.Size = New Size(640, 480)
 
        Dim strArgs As String = Me.mobjSearchTextBox.Text
        If Not [String].IsNullOrEmpty(strArgs) Then
            strArgs.Replace(Chr(9), Chr(32))
            ' Replace Tab with space
            strArgs = Me.RemoveDuplicateSpaces(strArgs)
 
            Dim arrArgs As String() = strArgs.Split(New Char() {Chr(9), Chr(10), Chr(13), Chr(32)})
            For bytIndex As Byte = 0 To arrArgs.Length - 1
                objLinkParameters.Form("prm" & bytIndex.ToString()) = arrArgs(bytIndex)
            Next
        End If
 
        Link.Open("http://localhost:1490/Post.Form1.wgx", objLinkParameters)
    End Sub
 
    Public Overridable Function RemoveDuplicateSpaces(ByVal strString As String) As String
        While strString.Contains("  ")
            strString = strString.Replace("  ", [String].Empty)
        End While
        Return strString
    End Function
 
End Class

"Receiving" Form
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        Dim objStringBuilder As New StringBuilder()
        Dim bytIndex As Byte = 0
 
        For Each objArgument As String In Me.Context.Arguments
            objStringBuilder.Append("Argument #" & bytIndex.ToString() & ":    ")
            objStringBuilder.Append("Key: " & objArgument & "    ")
            objStringBuilder.Append("Value: " & Me.Context.Arguments(objArgument))
            objStringBuilder.Append(vbLf)
 
            bytIndex += 1
        Next
        Me.mobjArgumentsTextBox.Text = objStringBuilder.ToString()
    End Sub
 
End Class

The demo application

The demo application is supplied in both C# and VB.NET code for Visual Studio 2005 and 2008 and can be downloaded from here.

Each solution contains 2 projects, one for the "Sending" form, and one for the "Receiving" form. Each solution is set to load both projects when debugged, and for the "Receiving" Form's project, the specific port is relevant, as you can see in the code.

See alsoReferences
Forum threads

About the author

Related Articles

Application Parameters  
Title Update Author
Tags: Developers, Navigation, Windows & Dialogs, 1. Beginner, 2. Intermediate, Navigation, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
04/Jan/2008    2008/01/04
Tags: Architects, Developers, Navigation, 1. Beginner, 2. Intermediate, 3. Advanced, Navigation, Pre v6.3, v6.3, v6.4 and Later
30/June/2010    2010/06/30
.NET HTML5 Web, Cloud and Mobile application delivery | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2012 Visual WebGui®       Visual WebGui weblog on ASP.NET Gizmox Blog Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS