Solved

variable scope

Posted on 2009-04-02
6
186 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

829 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