C#: Label contains no text

Posted by Vinzcent on Stack Overflow See other posts from Stack Overflow or by Vinzcent
Published on 2010-05-22T13:58:17Z Indexed on 2010/05/22 14:00 UTC
Read the original article Hit count: 221

Filed under:
|
|

Hey

I would like to get the text out of a label. But the label text is set with Javascript. On the page I can see that there is text in the label, but when I debug it shows this: "".

So how do I get the text out of a label that is set with Javascript, at least that is what I think is the problem.

My code:

<asp:TextBox ID="txtCount" runat="server" Width="50px" Font-Names="Georgia, Arial, sans-Serif" ForeColor="#444444"></asp:TextBox>
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender1" runat="server" Minimum="1"
 TargetButtonDownID="btnDown" TargetButtonUpID="btnUp" TargetControlID="txtCount"  Width="20" />
<asp:ImageButton ID="btnUp" runat="server" AlternateText="up" ImageUrl="Images/arrowUp.png"
 OnClientClick="setAmountUp()" ImageAlign="Top" CausesValidation="False" />
 <asp:ImageButton ID="btnDown" runat="server" AlternateText="down" ImageUrl="Images/arrowDown.png"  OnClientClick="setAmountDown()" ImageAlign="Bottom" 
 CausesValidation="False" />

<asp:Label ID="lblKorting" runat="server" />

 <asp:Label ID="lblAmount" runat="server" />

<asp:Button ID="btnBestel" runat="server" CssClass="btn" Text="Bestel" OnClick="btnBestel_Click1" />

JS

function setAmountUp()
{
    var aantal = document.getElementById('<%=txtCount.ClientID%>').value-0;

    aantal+=1;
    calculateAmount(aantal);
}

function setAmountDown()
{
    var aantal = document.getElementById('<%=txtCount.ClientID%>').value-0;

    if(aantal > 1)
        aantal -=1;

    calculateAmount(aantal);
}

function calculateAmount(aantal)
{

    var prijs = document.getElementById('<%=lblPriceBestel.ClientID%>').innerHTML -0;   
    var totaal = 0;

    if(aantal < 2)
    {
        totaal = prijs * aantal;
        document.getElementById('<%=lblKorting.ClientID%>').innerHTML = "";
    }

    else if(aantal >= 2 && aantal < 5)
    {
        totaal = (prijs * aantal)*0.95;
        document.getElementById('<%=lblKorting.ClientID%>').innerHTML = "-5%";
    }

    else if(aantal >= 5)
    {
        totaal = (prijs * aantal)*0.90;
        document.getElementById('<%=lblKorting.ClientID%>').innerHTML = "-10%";
    }

    document.getElementById('<%=lblAmount.ClientID%>').innerHTML = totaal;
}

C#

 private OrderBO bestelling;
    protected void btnBestel_Click1(object sender, EventArgs e)
    {
        bestelling = new OrderBO();
        bestelling.Amount = Convert.ToInt32(lblAmount.Text); //<--- THIS IS "" in the debugger, but on the page 10
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET