Accessing javascript var from C#

G

Gaurav

I am using the AxSHDocVw component for previewing XML files in my C# .NET
2003/.NET 1.1 application.

I use javascript's prompt() function to show a prompt and seek the users
input on double click on the preview window. Is there a way to capture what
the user entered on the prompt... either by accessing the javascript variable
populated after the user clicks OK, or by accessing the input field directly
when the user clicks OK - from my C# application?
 
G

Göran Andersson

Gaurav said:
I am using the AxSHDocVw component for previewing XML files in my C# .NET
2003/.NET 1.1 application.

I use javascript's prompt() function to show a prompt and seek the users
input on double click on the preview window. Is there a way to capture what
the user entered on the prompt... either by accessing the javascript variable
populated after the user clicks OK, or by accessing the input field directly
when the user clicks OK - from my C# application?

No. Javascript variables are not sent to the server.

You would have to write Javascript code that causes the value to be sent
to the server in a request, for example putting it in a hidden field in
a form that is posted to the server.
 
G

Gaurav

Thanks.
But this is a windows application... so there isn't a postback.
Is it not possible with the windows app too?
 
S

seani

I am using the AxSHDocVw component for previewing XML files in my C#
.NET 2003/.NET 1.1 application.

I use javascript's prompt() function to show a prompt and seek the users
input on double click on the preview window. Is there a way to capture
what the user entered on the prompt... either by accessing the
javascript variable populated after the user clicks OK, or by accessing
the input field directly when the user clicks OK - from my C#
application?

There are a few routes you can take to get this, it's largely a question
of "taste" and what's suitable for the wider application.

You have two problems:

1) You need to know that the user performed an action in the browser
control and to respond to that event in the C# host

2) You need to read one or more values captured by the JS / prompt in the
hosted browser control.

(2) is fairly easy: in your C# code, you need to examine the value of an
IHTMLElement in the DOM of the hosted document. A bit of googling should
give you some pointers.

(1) is slightly trickier, but there are several ways to achieve it, each
with a varying "ugh" factor.

If it was me (and it *was* me a few times) I'd reliably crack the problem
of reading a hidden INPUT variable or similar from a hosted document in
C#, then move on to the issue of how I know I need to respond ot an event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top