Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1070439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:34:01+00:00 2026-05-16T20:34:01+00:00

I am trying to set some client-side properties on a set of controls in

  • 0

I am trying to set some client-side properties on a set of controls in the EditItemTemplate of an ASP.Net ListView.

For instance, if the EditItemTemplate contains something like this:

<tr id='phoneRow'>
  <td>
    <asp:Label ID="lblPhoneLabel" runat="server" Text="Phone Number: " />
  </td>
  <td>
    <asp:Label ID="lblPhoneNumber" runat="server" 
               Text='<%# Bind("PhoneNumber") %>' />
  </td>
</tr>

I want to only show the row if there is actually a phone number, so JavaScript is something like:

function showOrHidePhoneRow(rowId, labelId)
{
    var row = document.getElementById(rowId);
    var label = document.getElementById(labelId);

    if (label.value == "")
        row.style.visibility = "collapsed";
    else
        row.style.visibility = "visible";
}

I am trying to add a call to this function in the code-behind, but I’m not sure how. It seems onload is too late.

protected void lvwExample_ItemCreated(object sender, ListViewItemEventArgs e)
{
    if (e.Item.ItemType == ListViewItemType.DataItem)
    {
        ListViewDataItem item = e.Item as ListViewDataItem;
        if (item.DisplayIndex == lvwExample.EditIndex)
        {
            Label label = item.FindControl("lblPhoneNumber") as Label;
            if (label != null)
            {
                // Get here, but row always visible
                label.Attributes.Add("onload",
                    "showOrHidePhoneRow('phoneRow', '" + label.ClientId + "');");
            }
        }
    }
}

Any pointers would be greatly appreciated.

Thanks,
wTs

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:34:01+00:00Added an answer on May 16, 2026 at 8:34 pm

    The problem here is that an asp:label tag is rendered as a span tag in the html… and the onload event doesn’t exist in the tag…
    So you are setting the attribute at the right time, but you are trying to handle an event that doesn’t get fired!
    I think the soution is to complete avoid javascript execution in your scenario and use the server event to handle it.
    Something like

    Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound
        Dim myLabel As Label = e.Item.FindControl("lblPhoneNumber")
        If Not myLabel Is Nothing Then
            e.Item.Visible = IIf(myLabel.Text = "", True, False)
        End If
    End Sub
    

    This way you handle every single item and decide if you want to hide your row, based the value of the label.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a client-side ajax login on Asp.Net MVC. I used to
I'm trying to set up a model (client) that contains some general attributes about
I'm iterating through some objects and trying to set some properties that, apparently, don't
I am new to ASP.Net MVC 3, facing some issues while trying to implementing
I have an asp.net mvc 3 application, and am now trying to add some
Can't seem to get checkbox to be validate on client-side using asp.net mvc 2.
I have Results page that contains an signup form. I'm trying to use client-side
I'm trying to set some javascript data (json) in my markup by calling a
I am trying to set some text on a label descriptionLabel.text = [NSString stringWithFormat:mySTUser.bio];
I am trying to set some default inherited permissions to a directory that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.