Solved

variable scope

Posted on 2009-04-02
6
199 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 500 total points
ID: 24050914
Yes.
text.InnerText = "Test";
0
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 

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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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