0

I'm having difficulty in using a variable derived from Javascript into an ASP tag .

<script language="javascript"> 
    if (arg) 
    {
        var text_box_to_fill = arg.sendValue_Code;                  
        document.getElementById( document.getElementById("<%= "+text_box_to_fill+".clientID %>").value = selected_libelle_value;
    }
</script>

Any suggestions?

1
  • You can only render something on the server into the client, but can't go in the reverse. Commented Feb 25, 2013 at 19:07

2 Answers 2

1

Not sure why there are duplicate "document.getElementById" code references, but you can only go from server to client in this fashion. So it would be:

<script language="javascript"> 
    if (arg) 
    {
        var text_box_to_fill = arg.sendValue_Code;                  
        document.getElementById("<%= text_box_to_fill.ClientID %>").value = selected_libelle_value;
    }
</script>

EDIT: Note that you have to have the script in the same page or control as the origin of "text_box_to_fill". If you have this script in a page, and the textbox is in the user control, that won't work.

Sign up to request clarification or add additional context in comments.

5 Comments

Compiler Error Message: BC30451: Name 'text_box_to_fill' is not declared.
this is the message my compiler is sending back to me
You have to use the server-side control's ID. What is the ID of the textbox? Also edited response above.
I finally found a way. This is the ID of the textbox that I have in "var text_box_to_fill" so I use it directly in javascript like this :document.getElementById(text_box_to_fill).value = selected_libelle_value; and it Works. thank for your help
I was obsessed by using server tag ! now it's Ok. Smile.
0

text_box_to_fill is defined client side in the browser, whereas the <% %> tags are evaluated on the server. It's not possible to reference javascript variables from the server code.

1 Comment

I've noticed that @andy Magee ! but are not there any others ways to fix it ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.