Milnelli Milnelli - 1 year ago 60
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;

TextBox tb1 = new TextBox();

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

And here's the JS:

function editRow(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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download