Saturday, March 24, 2012

Passing Variables between applications

I have two applications and both of them are compiled separatly.

Now I need to access the variables of one application from other application.

In other words I need to transfer the value of one variable from one application to another.

How can I do that ??Chapter 6 of ASP.NET Unleashed, "Using Code-Behind", goes into this (if you have the book). It basically discusses the ranges of public functions and variables (vs private, protected..) That is what you will want to reference to.

Basically, if you have a .CS file or, (i think the same is true when you compile)..

You have something like this (this is taken from the book)..

You CS file looks like


using System;

namespace myComponents {

public class AdderProperties {

private int _firstValue;
private int _secondValue;

public int FirstValue {
get {
return _firstValue;
}
set {
_firstValue = value;
}
}

public int SecondValue {
get {
return _secondValue;
}
set {
_secondValue = value;
}
}

int AddValues() {
return _firstValue + _secondValue;
}

}

}

And you ASP.NET page looks like this


<%@. Import Namespace="myComponents" %
<script runat=server>
void Button_Click( object s, EventArgs e )
{
Adder myAdder = new Adder();

myAdder.FirstValue = Int32.Parse(txtVal1.Text);
myAdder.SecondValue = Int32.Parse(txtVal2.Text);
lblOutput.Text = myAdder.AddValues().ToString();
}
</Script
<html>
<head><title>AddValues.aspx</title></head>
<body
<form Runat="Server"
Value 1:
<asp:TextBox
ID="txtVal1"
Runat="Server" /
<p
Value 2:
<asp:TextBox
ID="txtVal2"
Runat="Server" /
<p>
<asp:Button
Text="Add!"
OnClick="Button_Click"
Runat="Server" /
<p>
Output:
<asp:Label
ID="lblOutput"
Runat="Server" /
</form
</body>
</html

Is this what you are looking to do? Separate business(or w/e) logic from presentation? I am pretty sure that one application can pass information to another application using the same method.
You could do a POST (WebRequest/WebResponse objects) to a page in the "receiving" application. You could also put the data in some "shared" space (a database for example).

HTH...

Chris
but I think this example will work if both the applications are part of the same solution. What if both the applications are part of the different solutions.

Thanks,
azamsharp
What is

Adder myadder = new Adder();

should'nt this be :

AdderProperties adder = new AdderProperties()
Haha, yah.. I copied the wrong file :\ your Adder class should look like

using System;

namespace myComponents {
public class Adder {
public int FirstValue;
public int SecondValue;

public int AddValues() {
return FirstValue + SecondValue;
}

}
}

The original one I posted dealt with adding properties, too.
Hello, have u thought of sharing the same database ? then, you can store variables in one database and access it from multiple applications ?

regards

0 comments:

Post a Comment