Link to home
Start Free TrialLog in
Avatar of urosbe
urosbe

asked on

How to get javascript result into variable

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
Avatar of GoodJun
GoodJun

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.
Avatar of urosbe

ASKER

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
put after your HTML code creat the textbox1.
<script language="javascript">
document.form1.textbox1.text=ReadUserFromFile();
</script>
Avatar of urosbe

ASKER

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
Avatar of urosbe

ASKER

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
Avatar of urosbe

ASKER

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
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
Avatar of urosbe

ASKER

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
Avatar of urosbe

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of GoodJun
GoodJun

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of urosbe

ASKER

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
Avatar of urosbe

ASKER

Hy!

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

Uros
Avatar of Bob Learned
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