简体   繁体   中英

How to pass Textbox id in detailsview to JavaScript

I should pass the clientID of textboxes in detailsview in insert and edit mode (at runtime detailsview mode will change) to javascript like this:

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

How can i do that?Thanks.

Here is ,

$('#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..

There's a .val() method:

If you've got an input with an clientID of textbox you can use the following code to access the value of the text box:

$("#textbox").val()

try this

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

<script>
    $('#<%= textbox1.ClientID%>').datepicker({
        ...
    });
</script>
<InsertItemTemplate> 
     <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("StartDate") %>'></asp:TextBox>
</InsertItemTemplate>

For this you can use like...

$("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(); 

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM