Click here to Skip to main content
15,666,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem that seems so simple to fix but I cannot figure out why this is not working. I have done this in other apps with no problem.

I have an ASPX page that displays data at the top for info only and a Gridview to show related records that can be edited. I use ASP:LABELs to display the data fields at the top of the page. The Code Behind handles retrieving the data during Page Load. What I am getting is the field legend with no data. I have tried everything I know and have tried everything I can Google. The code below shows that I have removed all the data fields and reduced it to a variable (m) that gets set in the Code Behind to "StuffToShow". The resulting page should show

"Case Number: StuffToShow" but only shows "Case Number: "

I cannot figure out why it is doing this. You can see in the areas commented out that I tried other things with no luck. The attached code is not complete and includes only what I thought is relevant to keep it short.

Any ideas or suggestions will be much appreciated. There has got to be a simple reason for this not working that I just cannot see.

Thank you!!!

<%@ Page Language="C#" MasterPageFile="~/SiteMaster.master"   AutoEventWireup="false" CodeFile="DisplayDerivativesDetail.aspx.cs" Inherits="DisplayDerivativesDetail" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PageHeading" Runat="Server">
 	    <h3>Monthly Derivatives - Display Detail</h3>

<asp:Content ID="Content2" ContentPlaceHolderID="PageContent" Runat="Server">
    <div id="main">
         <asp:Label ID="lblInstructions" runat="server" Text="Display Detail Information:" >
        </asp:Label><br /><br />
        <!-- drop down list for detail status -->
        <asp:Label ID="lblStatus" runat="server" Text="Detail Status:" Width="80px" ></asp:Label>
        <asp:DropDownList ID="ddlStatus" runat="server" Width="75px">
            <asp:ListItem Text="Active" Selected="True" Value="AC" />
            <asp:ListItem Text="Inactive"  Value="IN" />
        </asp:DropDownList><br /><br />  

        <asp:Label ID="Label1" runat="server" Text="Case Number:" ></asp:Label>   
        <asp:Label ID="m" runat="server" ></asp:Label><br /><br />
        <!-- <asp:Label ID="Label2" runat="server" Text="NCP Name: "></asp:Label>   
        <asp:Label ID="lblNCPName" runat="server" Text="Data"  Width="280px"></asp:Label>
        <br />
        <asp:Label ID="Label3" runat="server" Text="Court Number: " Width="125px"></asp:Label>   
        <asp:Label ID="lblCourtNumber" runat="server" Width="125px"></asp:Label>
        <asp:Label ID="Label4" runat="server" Text="Monthly Amount: " ></asp:Label>   
        <asp:Label ID="lblMonthlyAmt" runat="server" Width="125px"></asp:Label>
        <br />
        <asp:Label ID="Label5" runat="server" Text="Start Date: " ></asp:Label>   
        <asp:Label ID="lblStartDate" runat="server" Width="125px"></asp:Label>
        <asp:Label ID="Label6" runat="server" Text="Review Date: "></asp:Label>   
        <asp:Label ID="lblReviewDate" runat="server" Width="125px"></asp:Label>
        <asp:Label ID="Label7" runat="server" Text="End Date: "></asp:Label>   
        <asp:Label ID="lblEndDate" runat="server" Width="125px"></asp:Label>
        <br /><br /> -->
        <!-- grid of Detail records for a selected Case  -->
        <asp:GridView ID="gvDetail" Runat="server" 
                 AllowPaging="True" AllowSorting="True" 
                 ShowFooter="True" > 
                <FooterStyle CssClass="HeaderFooter"></FooterStyle>
                <HeaderStyle Font-Bold="True" Wrap="True" CssClass="HeaderFooter"></HeaderStyle>
                <AlternatingRowStyle Font-Bold="False" BackColor="GhostWhite"></AlternatingRowStyle>
                <asp:BoundField DataField="PaymentDate" HeaderText="Payment Date" SortExpression="PaymentDate" ItemStyle-Wrap="false" />
                <asp:BoundField DataField="Amount" HeaderText="Payment Amt" SortExpression="Amount" ItemStyle-Wrap="false" />
                <asp:BoundField DataField="DetailComment" HeaderText="Comment" SortExpression="DetailComment" ItemStyle-Wrap="false" />
                <asp:BoundField DataField="DetailAddedBy" HeaderText="Added By" SortExpression="DetailAddedBy" ItemStyle-Wrap="false" />
                <asp:BoundField DataField="DetailAdded" HeaderText="Added" SortExpression="DetailAdded" ItemStyle-Wrap="false" />
                <asp:BoundField DataField="DetailUpdatedBy" HeaderText="Updated By" SortExpression="DetailUpdatedBy" ItemStyle-Wrap="false" />
                <asp:BoundField DataField="DetailUpdated" HeaderText="Updated" SortExpression="DetailUpdatedBy" ItemStyle-Wrap="false" />
                <asp:TemplateField HeaderText="Detail ID" SortExpression="DetailID" visible="false">
                        <asp:TextBox ID="eitDetailID" runat="server" ReadOnly="True" Text='<%# Bind("DetailID") %>'></asp:TextBox>
                        <asp:Label ID="itDetailID" runat="server" Text='<%# Bind("DetailID") %>'></asp:Label>
                    <ItemStyle Wrap="False" />
                <asp:TemplateField HeaderText="Case ID" SortExpression="CaseID" visible="false">
                        <asp:TextBox ID="eitCaseID" runat="server" ReadOnly="True" Text='<%# Bind("CaseID") %>'></asp:TextBox>
                        <asp:Label ID="itCaseID" runat="server" Text='<%# Bind("CaseID") %>'></asp:Label>
                    <ItemStyle Wrap="False" />
                <asp:BoundField DataField="CaseID" HeaderText="Case ID" SortExpression="CaseID"  Visible="false"  />

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ParameterPasser;
public partial class DisplayDerivativesDetail : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
            //*  Grab the CaseID passed from DisplayDerivativesCases.aspx and convert to integer *// 
            //int intCaseID;
            //string strCaseID = Request.QueryString["CaseID"];
            //intCaseID = Convert.ToInt32(strCaseID);
            //// Get Case Info for display only
            //DerivativesBAL.DerivativesBAL obj10 = new DerivativesBAL.DerivativesBAL();
            //DataSet dsName = obj10.GetCase(intCaseID);
            m.Text = "StuffToShow";
            //lblCaseNumber.Text = dsName.Tables[0].Rows[0]["CaseNumber"].ToString();
            //lblNCPName.Text = dsName.Tables[0].Rows[0]["NCPNameLast"] + ", " +
            //dsName.Tables[0].Rows[0]["NCPNameFirst"] + " " +
            //lblCourtNumber.Text = dsName.Tables[0].Rows[0]["CourtNumber"].ToString();
            //lblMonthlyAmt.Text = dsName.Tables[0].Rows[0]["MonthlyAmt"].ToString();
            //lblStartDate.Text = dsName.Tables[0].Rows[0]["StartDate"].ToString();
            //lblReviewDate.Text = dsName.Tables[0].Rows[0]["ReviewDate"].ToString();
            //lblEndDate.Text = dsName.Tables[0].Rows[0]["EndDate"].ToString();
            //if (lblCaseNumber.Text == null)
            //    lblCaseNumber.Text = "EMPTY";
            //    lblCaseNumber.Text = "HAS INFO";
Updated 16-May-12 11:31am
ledtech3 16-May-12 19:41pm    
I'm not a aspx guy but the line asp:Label ID="m" runat="server"

seems to be the only reference to "m" that I see. So I would think that the label ID of "m" would be what was showing the text "StuffToShow" ,also there is no "text =" there. Would adding a "Text = m.text" do any good ?
JTRizos 17-May-12 12:21pm    
Thanx ledtech3, when I use Text=m.text, the result is "Case Number: m.text". Text= works fine in the ASPX code. It's the code behid that seems to be blocked.

Thanx for the suggestion. Much appreciated.
Steve Echols 16-May-12 23:56pm    
Does the text disappear after a post back? I don't think the label control maintains view state, so setting the text property of a label control wrapped in a IsPostBack check won't work. I could be wrong, but something to consider....
JTRizos 17-May-12 12:22pm    
Thanx Steve Echols, I haven't used a post back on the display screens and haven't needed it in other similar pages. I do use post back in an update program. Having said that, I did try post back in this code and it made no difference.

I appreciate the suggestion, however.


There must be something wrong, but as I've given this code a real execution on my IDE (Visual Studio 2010), it works absolutely fine. It shows-"Case Number: StuffToShow". I also checked manipulating the commented part of the code and all those works fine as expected.

I suggest you to check if there is any other manipulation before the page loads or if any variable is there in masterfile with same id.

Sunny K
Share this answer
JTRizos 17-May-12 12:11pm    
Thanx Sunny,

I guess I feel a little bit better that it works for you. I'll take your suggestion and see what I find. Seems like such a simple thing to do.

Your suggestion is much appreciated!!!
Another Idea might be, if it is not finding the code file. verify the spelling and that it can find it.
I don't understand why it works, but it just worked for me using VB.Net

I used a stock VS2008 build for a webapplication.
Dropped Into the the deault aspx:
<asp:Label ID="Label1" runat="server" Text="Case Number:" ></asp:Label>
 <asp:Label ID="m" runat="server" ></asp:Label><br /><br />

and dropped in below to the default aspx vb file:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    m.Text = "StuffToShow"
End Sub

and the result was
Case Number:StuffToShow
Share this answer
First off, I want to thank all who responded. I was glad to hear that my code was working. After reading the responses I reevaluated what I had done. I always work with the code and have never used the designer. So, I pulled up the designer in VS 2005. I could see the "m" variable in the design view and opened it's properties. I looked in Events and found that DataBinding and Load were blank. I selected Page_Load for both and it worked.

Not sure yet why but this gives me a whole new place to look and learn.

Thanx again. This forum always comes through and provides helpful hints for exploring.
Share this answer
ledtech3 18-May-12 11:07am    
Glad you got it Solved.

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