Solved

variable scope

Posted on 2009-04-02
6
173 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
  • 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now