如何将详细信息视图中的文本框ID传递给JavaScript

时间:2016-06-20 07:46:41

标签: javascript c# asp.net computer-science detailsview

我应该在插入和编辑模式下将详细信息视图中的文本框的clientID传递给(在运行时详细信息视图模式下会更改)为这样的javascript:

$('#textbox2').datepicker({
    ...
});

我怎么能这样做?谢谢。

4 个答案:

答案 0 :(得分:1)

这是,

$('#detailsview #TextBox2').val() 

For Example...

<div id="demo1">
    <div>
       <input type="text" id="txtOne"/>
    </div>
</div>
<div id="demo2">
    <div>
       <input type="text" id="txttwo"/>
    </div>
</div>

then you can find that  textbox like this..

$("#demo1 div #txtOne");

This is just demo it may help you to get idea that how its to be perform

or if you say that inside control will be change then you can also use by **class** or any **tag name** too..

答案 1 :(得分:0)

有一个.val()方法:

如果您输入的文本框的clientID,则可以使用以下代码访问文本框的值:

$("#textbox").val()

答案 2 :(得分:0)

试试这个

<asp:TextBox runat="server" id="textbox1"/>

<script>
    $('#<%= textbox1.ClientID%>').datepicker({
        ...
    });
</script>

答案 3 :(得分:0)

<InsertItemTemplate> 
     <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("StartDate") %>'></asp:TextBox>
</InsertItemTemplate>

为此您可以使用...

$("InsertItemTemplate #TextBox2").val();    


here, client side you can not get `**[InsertItemTemplate]**` so you can use that 
control render in DIV so in place of InsertItemTemplate you use Div like

$("div #TextBox2").val();