Solved

variable scope

Posted on 2009-04-02
6
190 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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