Click here to Skip to main content
15,891,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a grid view and in one template control i have a div like this

C#
<asp:TextBox ID="txt_answer" runat="server" Height="74px" TextMode="MultiLine"
           Width="296px"></asp:TextBox>
       <br />
       <input id="Button1" type="button" value="Submit" onclick="PostAnswer('div_answer')" />
       <input id="Button2" type="button" value="Cancel" onclick="hideanswer('div_answer')" />



and my script block like this

C#
<script type="text/javascript">
        function showanswer(sender, divid) {


            $("#" + divid).slideDown(400);
        }
        function hideanswer(divid) {
            $("#" + divid).slideUp(300);
        }
        $(document).ready(function () {
            $(".answer").hide();
        });

        function PostAnswer(divid) {
            //$("#" + divid).slideUp(200);
            var v = $("#answer_div").find("#txt_answer").val();

            alert(v);
            //alert($("#" + divid).find("#txt_answer").va());
        }
    </script>




but when i call a function showanswer by clicking on img , then the client id is not going
Posted
Updated 23-Jan-12 1:41am
v2
Comments
Kethu Sasikanth 22-Jan-12 7:09am    
To better understand the problem i would like to see the img tag and how you are calling showanswer.

1 solution

when a control has runat="server" the client id is composed with all the container controls that he has.

example
my id "linkSelection" becomes "ctl00_ctl00_MasterContainer_menu_linkSelection"


you can match the final part of the id

JavaScript
<script type="text/javascript">
        function showanswer(sender, divid) { $("[id$='"+ divid +"']").slideDown(400); }
        function hideanswer(divid) {$("[id$='"+ divid +"']").slideUp(300);}
    </script></script>


or you can use


XML
<asp:TextBox ID="txt_answer" runat="server" Height="74px" TextMode="MultiLine"
            Width="296px"></asp:TextBox>
        <br />
        <input id="Button1" type="button" value="Submit" onclick="PostAnswer('<%= div_answer.ClientID %>')" />
        <input id="Button2" type="button" value="Cancel" onclick="hideanswer('<%= div_answer.ClientID %>')" />



 
Share this answer
 
Comments
Surendra Tarai 30-Jan-12 2:34am    
still it is error, error is not getting refernce

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900