开发者

How to get the String Value to the textbox using javascript with asp.net

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.


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

('<%= 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜