0

I am creating a folder by generating a random string and I need to get that string value to the textbox using javascript.

Here is my javascript Code:

<script type="text/javascript">
 var tempDir = randomString(8);
                document.getElementById("currentDirectory").value = tempDir;
                alert(tempDir);
</script>

This is the textbox where I need to display

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
1
  • My answer worked for you now ? Commented Oct 13, 2011 at 18:54

3 Answers 3

2

That's It,

document.getElementById('<%= TextBox1.ClientID  %>').value = tempdir;

In asp.net the id of elements changes when rendered in browser so you need to take the.Id from control's ClientID property.

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

2 Comments

Sorry Harsh it's not working as It's showing me error at the control ID property.So I am trying to make it work.
So you can update the question with new implementation of your javascript code and the control syntax. It would be more clear then.
1

I resolved it by simply declaring the control this way inside the body tag.

('<%= TextBox1.ClientID %>')

1 Comment

I don't think my answer is indifferent then the one you posted. You should have considered accepting my answer but alas choice is yours. :(
0

You can also try JQuery

 $("#ControlID").val(tempDir);

You'll want to check how the control is rendered in the HTML though since it's an ASP.Net control. Sometimes the ID changes a bit and you'll want the command to use that in place of ControlID above.

Comments

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.