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>
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.
我通过简单地在body标签内以这种方式声明控件来解决它。
('<%= TextBox1.ClientID %>')
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.