Warm tip: This article is reproduced from stackoverflow.com, please click
asp.net c# html

how to show a label in an aspx page based on a request query string

发布于 2020-03-29 21:02:38

i have to labels on page load. one comes from a query string and one is coded onto the page. as follows

<script runat="server" language="C#">
    protected void Page_Load(object sender, EventArgs e)
    {

        lblMessage.Text = Request.QueryString["message"];
        lblcard.Text = "Transaction made successfully!";
    }
</script>

how do i check if lblmessage has a text then it should only display that label and hide the lblcard text,if lblmessage doesnt have a text then it should show the "transaction made " text

Questioner
marry
Viewed
60
Ivan Kahl 2020-01-31 18:55

You would use the String.IsNullOrEmpty method documented here.

Your code would look something like this:

<script runat="server" language="C#">
    protected void Page_Load(object sender, EventArgs e)
    {
        lblMessage.Text = Request.QueryString["message"];

        if (String.IsNullOrEmpty(lblMessage.Text) {
            lblcard.Text = "Transaction made successfully!";
        }
    }
</script>