Ruwan Wickramanayake

Ruwan Wickramanayake

  • 1.6k
  • 17
  • 1.6k

How to pass c# variable value into the javascript code

Nov 27 2021 4:48 AM

Pls help me on this below issue.

I am trying to develop some c# windows form application using CEF browser. In the main form, there are two sections, where one for the browser window and the remaining section for the general windows forms objects like text boxes and buttons.

I would need to fill the 'username' and 'password' fileds in the loaded web page, using the values inside two text boxes in the windows form.

I used the format <%=variable%> inside the java string, but seems like it doesnot take the value from the c# variable.

Pls see the below code section:

string username = TxtUserName.Text;
CurBrowser.ExecuteScriptAsync("document.getElementsByTagName('input')[0].setAttribute('value',<%= username %>);");

 

Basically I need the c# variable value to be taken inside the javascript to automatically fill the username field in the browser .

Greatly appreciate your valuable input.


Answers (1)