0
<script type="text/javascript">
    $(document).ready(function () {
        $('input[name="time"]').ptTimeSelect();
    });
</script>

the above script is working on this:

<input name="time" value="" /></td>

But not working on this...

<asp:TextBox ID="time" name='time' runat="server"></asp:TextBox>

3
  • ASP.net controls translate to a HTML control, so look at the HTML source code to see what's off. (My guess is it's because you're only using the id of "time" and not the name) Commented Feb 22, 2013 at 11:40
  • i tried it with name also it still did not work Commented Feb 22, 2013 at 11:41
  • 1
    This answer is most probably the solution to your question too: stackoverflow.com/a/6345700/79485 You need to use the ClientID property. Commented Feb 22, 2013 at 11:42

3 Answers 3

0

Please use following code

<script type="text/javascript">
$(document).ready(function () {
var id='<%=time.clientid%>'
    $('#'+id).ptTimeSelect();
});
 </script>

and let me know if this does not work.

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

7 Comments

var id = '<%=time.clientid%>' CS1061: 'System.Web.UI.WebControls.TextBox' does not contain a definition for 'clientid' and no extension method 'clientid' accepting a first argument of type 'System.Web.UI.WebControls.TextBox' could be found (are you missing a using directive or an assembly reference?)
seems you are using c# in your server side code. please replace clientid with ClientID as it is case sensitive.
it worked, but can you explain the code a little, i know nothing about javascripts or jquery, also if i have more than one textboxes do i have to copy paste <script> part for every textbox?
ASP.net dynamically generates IDs according to the name of parent control so id which appears in aspx is not always same as generated in browser. you can use control.ClientID to find out ID which will generated by framework. to find this element using jquery we need to add # sign before generated id.
you can use classname if want to implement same jquery functionality with may textboxes like $(document).ready(function () { $('yourclassname').ptTimeSelect(); }); </script> you need to set the same classname to each textbox for which you want to call jquery function.
|
0

From what I remember of ASP.NET is that it modifies the ID and name of an element to ensure it's always unique. The end result of the <asp:TextBox> may be something like:

<input name="ctr_0102_time" />

The best bet is to check the element's source on the live page to determine what attributes it has. If it does have a random identifier then you should probably base it on a specific class:

<input class="time" />
<asp:TextBox CssClass="time"></asp:TextBox>

$('input.time') ...

The other thing that may cause this to break are post backs. Post backs in ASP.NET do not re-ready the document, they simply reload the page. Instead of using $(document).ready() use:

function pageLoad() { ... }

Comments

0

try this:

<script type="text/javascript">
    $(document).ready(function () {
        $('[id$=time]').ptTimeSelect();
    });
</script>

2 Comments

CS1061: 'System.Web.UI.WebControls.TextBox' does not contain a definition for 'clientid' and no extension method 'clientid' accepting a first argument of type 'System.Web.UI.WebControls.TextBox' could be found (are you missing a using directive or an assembly reference?)
My solution is not using clientid, you may have other errors in your code.

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.