views:

222

answers:

2
 <script language="javascript" type="text/javascript">

        $(document).ready(function() {
            $("#TextBox1").click(function() { alert("bla bla bla bla bla") });
        });

    </script>

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <asp:TabContainer runat="server" ActiveTabIndex="0">
            <asp:TabPanel runat="server" HeaderText="Easd">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </ContentTemplate>
            </asp:TabPanel>
            <asp:TabPanel runat="server" HeaderText="asdasd">
                <ContentTemplate>
                    asd</ContentTemplate>
            </asp:TabPanel>
        </asp:TabContainer>

i need TextBox1 access

+1  A: 

I'm not sure what you mean by "I need access", but I'm assuming you mean your jQuery code isn't working.

The generated clientside ID for serverside controls is different than your designed markup. You need to update your jQuery code:

$("#<%#TextBox1.ClientID %>").click(function() { alert("bla bla bla bla bla"); });

This will dynamically insert the Client ID for the textbox, such that your jQuery selector will work.

Edit:

If you need value as you commented:

$("#<%#TextBox1.ClientID %>").click(function() { alert( $(this).val() ); });

I'm only calling the javascript function alertand jquery event click based on your example code. As another example, if you wanted to alert/popup the value of the textbox when the user focuses away from it:

$("#<%#TextBox1.ClientID %>").blur(function() { alert( $(this).val() ); });

Hope this helps...

KP
i need TextBox1 value "KP"
Oraclee
Not Work "KP"$("#<%#TextBox1.ClientID %>").click(function() { alert( $(this).val() ); });
Oraclee
A: 

Try This:

<script type="text/javascript">
       $(document).ready(function(){
          alert($("#<%#TextBox1.ClientID %>").val());
        }); 
</script>

Link

Jon
$(document).ready(function() { alert($("#<%=TextBox1.ClientID %>").val()); }); <asp:TabPanel runat="server" HeaderText="Entry Quato"> <ContentTemplate> <asp:TextBox ID="TextBox1" Text="ASD" runat="server"></asp:TextBox> </ContentTemplate> </asp:TabPanel>Error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). Please Help me :(
Oraclee
Did you put the document.ready in a script block?
Jon
yes script block<script language="javascript" type="text/javascript"> $(document).ready(function() { alert($("#<%=TextBox1.ClientID %>").val()); }); </script>
Oraclee
Instead of <%= in the script block, try <%#. I updated my code above and provided a link to an article about it.
Jon
<script type="text/javascript"> $(document).ready(function(){ alert($("#<%=TextBox1.ClientID %>").val()); }); </script>Dont Work Jon help me :(
Oraclee
Try to use <%# instead of <%=, I updated the code above and provided a link to an article with someone having the same issue.
Jon
Dont work Jon :S :($(document).ready(function() { alert("asd"); alert($("#<%#TextBox1.ClientID %>").val()); }); <asp:TabContainer runat="server" ActiveTabIndex="0"> <asp:TabPanel runat="server" HeaderText="Easd"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </ContentTemplate> </asp:TabPanel> <asp:TabPanel runat="server" HeaderText=" </asp:TabPanel> </asp:TabContainer>
Oraclee
Does it produce the same error: Error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)?
Jon
Yes Error Jon :S
Oraclee
Sorry :-( I think I'm out of ideas, I wish I could be more of a help! I'll keep thinking though
Jon
Thank You Jon ;)
Oraclee