Milnelli Milnelli - 2 months ago 17
jQuery Question

Hiding a dynamically created label using JQuery

I'm creating some textboxes and labels dynamically and am trying to hide/show them via JQuery but can't get the JQuery working. What am I doing wrong?

Here's the code behind:

TableCell td4 = new TableCell();

Label l2 = new Label();

l2.ID = "lbSell" + dp.dSellAutoID.ToString();
l2.Text = Math.Round(Convert.ToDecimal(dp.dSellPrice), 2).ToString();
l2.Visible = false;
td4.Controls.Add(l2);

TextBox tb1 = new TextBox();

tb1.ID = "tbSell" + dp.dSellAutoID.ToString();
tb1.Width = 50;
tb1.Text = Math.Round(Convert.ToDecimal(dp.dSellPrice), 2).ToString();
td4.Controls.Add(tb1);
tr.Cells.Add(td4);


And here's the JS:

function editRow(rowID) {
//alert(rowID);
$('#' + 'lbSell' + rowID).show();
$('#' + 'tbSell' + rowID).hide();
}

Answer Source

Are you using master pages? In that case, the ID changes while the page is being rendered. To prevent it, you can add ClientIDMode="Static" to the page directive

<%@ Page Title="" Language="C#" ClientIDMode="Static" MasterPageFile="~/epinet.master" %>

Please see: https://stackoverflow.com/a/5494142/5746368