?
Solved

How to get javascript result into variable

Posted on 2003-03-14
14
Medium Priority
?
285 Views
Last Modified: 2010-05-18
Hy!

I am new here and I saw few great ideas. I am programming in Visual Basic .NET and I have a problem. In HTML tag I wrote one javascript function which reads username from file setttings.ini on client.

     function ReadUserFromFile()     {
          var filename = "c:/Runtime/settings.ini";
          var fso = new ActiveXObject("Scripting.FileSystemObject");
          if (fso.FileExists(filename)) {
               var a, file, ForReading;
               ForReading = 1;
               file = fso.OpenTextFile(filename, ForReading, false);
               var vrstica = file.readline();
               var parts = vrstica.split("*");
               return parts[0];
          }
          file.Close();
     }

I don't know how can get this result (parts[0]) back to server... in Form_Load I must get this username, because after that I read from database only datas filtered on this username.

Regards!

Uros
0
Comment
Question by:urosbe
[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
  • 8
  • 4
14 Comments
 
LVL 10

Expert Comment

by:GoodJun
ID: 8136345
put a textbox on the form:textbox1
edit the html for the form:document.form1.textbox1.text=ReadUserFromFile();

your server side code can access textbox1 the normal way.
0
 

Author Comment

by:urosbe
ID: 8174029
Thanks for you answer. But I didn't understand where must I put that code. Can you give me quick example please?

Many thanks!

Regards

Uros
0
 
LVL 10

Expert Comment

by:GoodJun
ID: 8177502
put after your HTML code creat the textbox1.
<script language="javascript">
document.form1.textbox1.text=ReadUserFromFile();
</script>
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:urosbe
ID: 8179966
Thanks again! It works! But I have another problem now. If I create a textbox, it must be a HTML -> Textbox -> if I create Web forms -> Textbox it is not visible like that
document.form1.textbox1...... in javascript

Ok, I created html textbox. And now i get value in this textbox but I can't access to this textbox from VB .NET code. Control is not visible because it is a HTML one.

Do you have any suggestion?

Regards!

Uros
0
 

Author Comment

by:urosbe
ID: 8283273
Hy!

I still have the same problem, can anybody help me please. I have HTML control textbox and it is not visible in code. I must read a value from this textbox in form_main.

Any suggestion?

Best regards!

Uros
0
 

Author Comment

by:urosbe
ID: 8283533
Hy!

I still have the same problem, can anybody help me please. I have HTML control textbox and it is not visible in code. I must read a value from this textbox in form_main.

Any suggestion?

Best regards!

Uros
0
 
LVL 10

Expert Comment

by:GoodJun
ID: 8284212
The webform solution works.
For the textbox you need assign a id="myID"
and then refer to the textbox use the id.
document.forms[0].myID
0
 

Author Comment

by:urosbe
ID: 8290280
Thanks for quick answer, but I already know that. In HTML code I have:

document.Form1.txtUser.value="User: " + ReadUserFromFile();

And everything works perfect, but on the other side, I want to read value from this HTML control with id = txtUser from VB.NET code (in form_load), i was looking how can I access to the control, but it's not visible anywhere in VB.NET code.

Or if it can't work, I can have contrast situation too, that I make a WEB Control (not a HTML one) and I must write a value in HTML code to that WEB Control.

Do you understand what is my problem?

Best regards and thanks again!

Uros
0
 

Author Comment

by:urosbe
ID: 8290313
Thanks for quick answer, but I already know that. In HTML code I have:

document.Form1.txtUser.value="User: " + ReadUserFromFile();

And everything works perfect, but on the other side, I want to read value from this HTML control with id = txtUser from VB.NET code (in form_load), i was looking how can I access to the control, but it's not visible anywhere in VB.NET code.

Or if it can't work, I can have contrast situation too, that I make a WEB Control (not a HTML one) and I must write a value in HTML code to that WEB Control.

Do you understand what is my problem?

Best regards and thanks again!

Uros
0
 
LVL 10

Accepted Solution

by:
GoodJun earned 200 total points
ID: 8291479
.net code is server side, if you are trying to read a value on client side, you have to create code to pass the value.
0
 

Author Comment

by:urosbe
ID: 8298053
I would like to say thank you for help. I made it, finally!
Now, I just have one little problem more, how to run my javascript function (which writes a value in textbox control) before form_load (if this is possbile). Because form_load is reading from that textbox (but if javascript starts after form_load code, in textbox there is no value).

//document.Form1.txtUporabnik.value = "Uporabnik: " + ReadUserFromFile();

function ReadUserFromFile()     {
  var filename = "c:/Runtime/settings.ini";
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  if (fso.FileExists(filename)) {
    var a, file, ForReading;
    ForReading = 1;
    file = fso.OpenTextFile(filename, ForReading, false);
    var vrstica = file.readline();
    var parts = vrstica.split("*");
    file.Close();
    return parts[0];
  }
}

Best regards!

Uros
0
 

Author Comment

by:urosbe
ID: 8411842
Hy!

I still have the same problem, I can't fix it.
Is there any chance to do that?

Uros
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9671557
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by GoodJun

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 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