Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

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
0
urosbe
Asked:
urosbe
  • 8
  • 4
1 Solution
 
GoodJunCommented:
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
 
urosbeAuthor Commented:
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
 
GoodJunCommented:
put after your HTML code creat the textbox1.
<script language="javascript">
document.form1.textbox1.text=ReadUserFromFile();
</script>
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
urosbeAuthor Commented:
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
 
urosbeAuthor Commented:
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
 
urosbeAuthor Commented:
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
 
GoodJunCommented:
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
 
urosbeAuthor Commented:
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
 
urosbeAuthor Commented:
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
 
GoodJunCommented:
.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
 
urosbeAuthor Commented:
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
 
urosbeAuthor Commented:
Hy!

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

Uros
0
 
Bob LearnedCommented:
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now