?
Solved

variable scope

Posted on 2009-04-02
6
Medium Priority
?
211 Views
Last Modified: 2013-12-17
Been using the GlobalVars variable structure fine within WinForm Application (any class etc.)

I have a WinForm that utilises the web browser control, and call an aspx page.

This aspx page, I wanted it to have access to the same variables (and current values) as the desktop application -- basically be seamless between desktop app and web-page app

I registered the Desktop app in the web references ok,  the code-behind scripting sees the GlobalVars class setup in Desktop application fine .. just that when running, the web-page does not work -- cannot load/create object error message.

I am making sure I have the desktop application active/running first -- I then call the WinForm to open which in turn calls the web-page to be loaded (That is hosted on web server).

Knowing this web page compiles fine and intellisence accepts this structure -- why does the page refuse to work?

Many thanks.
ASPX 
 
<body>
    <form id="form1" runat="server">
    <div>
         Agent ID ::
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </div>
    </form>
</body>
 
ASPX Code Behind
 
Using Desktop-Application;
 
protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = GlobalVars._fortuneAgent_ID.ToString();
        }
 
____________________________
 
Desktop Application:
 
public static class GlobalVars
    {
public static int _fortuneAgent_ID
        {
            get { return fortuneAgent_ID; }
            set { fortuneAgent_ID = value; }
        }
}

Open in new window

0
Comment
Question by:amillyard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 6

Expert Comment

by:HarryNS
ID: 24050413
Basically, if you need to access web browser values, you will be able to access HTML Document.
For ex, Following code will read a text box value from aspx page,

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlDocument doc = null;

            doc = webBrowser1.Document;
            HtmlElement text = doc.GetElementById("Text1");
            MessageBox.Show(text.InnerText);
        }
0
 

Author Comment

by:amillyard
ID: 24050593
I see - thats interesting :-)

Can that work both ways? inject a value from WinForm to text label in WebForm?
0
 
LVL 6

Accepted Solution

by:
HarryNS earned 2000 total points
ID: 24050914
Yes.
text.InnerText = "Test";
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:amillyard
ID: 24051039
"text.InnerText = "Test";

when would that value be available?  instantly -- or would a page refresh be required?

assuming setup a hidden txt field to tmp store value -- move that value to an internal aspx variable and then clear down (empty) the hidden txt field value in order to preserve security of that value (in case user tries to view source code etc).

is this the process?
0
 

Author Comment

by:amillyard
ID: 24051146
"text.InnerText = "Test";

how do I script this fully?

HtmlDocument doc = null;

doc = webBrowser_ClientCase.Document;
//HtmlElement text = doc.GetElementById("Label1");
//MessageBox.Show(text.InnerText);

text.InnerText = "Test";
0
 

Author Closing Comment

by:amillyard
ID: 31565778
got to work 100% -- many thanks :-)
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question