0

Part of my gridview looks like this:

                    <asp:TemplateField HeaderText="Mortality Rate" SortExpression="Other2">
                <EditItemTemplate >
                    <asp:TextBox ID="txtAppLimit" Text='<%#Bind("Other2")%>' runat="server" width="60px" maxlength="14">
                    </asp:TextBox>
                     <asp:RangeValidator ID="RVAppLimit" Type="Currency" runat="server" ControlToValidate="txtAppLimit"  
                            Display="Dynamic" ErrorMessage="" Font-Size="8pt" 
                            CssClass="msgerror" MinimumValue="0" MaximumValue="200" OnPreRender="GridView1_PreRender" ValidationGroup="group1"> 
                    </asp:RangeValidator>  
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblAppLimit" Runat="server" Text='<%# Bind("Other2") %>' >
                    </asp:Label>
                </ItemTemplate>
                    <ItemStyle HorizontalAlign="Right" Width="10%" />
                </asp:TemplateField>

I'm trying to get the asp TextBox ID and asp Label ID in this way when I click on a asp LinkButton:

        var $arrL = $('#<%=GridView1.ClientID %>').find('span[id$="lblAppLimit"]');
        var $lbl = $arrL[0];
        ($lbl).disabled = true;
        alert (($lbl).disabled);

        var $arrT = $('#<%=GridView1.ClientID %>').find('input:text[id$="txtAppLimit"]').val();
        var $txt = $arrT[0];
        alert (($txt).innerHTML);

I have no problem disabling lblAppLimit, however I'm not able to get the textbox ID to disable it. What is wrong with my code above?

Just to add on another note, when I click on view source on my browser, I'm able to see lblAppLimit, but not txtAppLimit.

6
  • Probably you are not in edit mode , that's why... Commented Jun 7, 2016 at 9:25
  • @Legends What do you mean? Commented Jun 7, 2016 at 9:44
  • 1
    txtAppLimit is in EditItemTemplate so it will only work if the grid is in edit mode Commented Jun 7, 2016 at 10:05
  • too little code to help you, show us the complete grid markup and your serverside grid handling code. Commented Jun 7, 2016 at 11:34
  • @Ansari it's not working even when I'm in edit mode. Commented Jun 7, 2016 at 14:36

2 Answers 2

1

txtAppLimit is in EditItemTemplate so it will only work if the grid is in edit mode

So in edit mode try this script

var $arrT = $('#<%=GridView1.ClientID %>').find('input:text[id*="txtAppLimit"]').val();
        var $txt = $arrT[0];
        alert (($txt).innerHTML);

i don't know why you are using $arrT[0] but this will surely work in edit mode

$('#<%=GridView1.ClientID %>').find('input:text[id*="txtAppLimit"]').val()

Hope this will help you.

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

Comments

1

Make you txtAppLimit as STATIC like this :

1 <asp:TextBox ID="txtAppLimit" Text='<%#Bind("Other2")%>' width="60px" maxlength="14" ClientIDMode="Static" runat="server"></asp:TextBox>

and change the jquery to :

1 $(this).find('input:text[id="txtAppLimit"]').val();

Update: You can also try with adding class to every TextBoxes like txtclass1,txtclass2

alert($(this).parent("td").parent("tr").find(".txtclass1").val()); 
alert($(this).parent("td").parent("tr").find(".txtclass2").val());

1 Comment

I'm on .NET Framework 2.0, I can't get ClientIDMode to work in my application. Do you have any other suggestions?

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.