Write a program to check whether empty query string is entered in Asp.Net.


Take an one web Page give any Suitable name as you want.
Here Page taken with the name of Default1.aspx

Page1: Default1.aspx
Design:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        <asp:TextBox ID="txtUserid" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="QuerySend" runat="server" onclick="QuerySend_Click" Text="Send"/>
    </div>
    </form>
</body>
</html>

Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void QuerySend_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default2.aspx?UserId=" + txtUserid.Text);
    }

}


Now take an another web page
Page2: Default2.aspx
Design:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>   
        <asp:Label ID="lblUserid" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["UserId"].ToString()))
            {
                lblUserid.Text = Request.QueryString["UserId"];
            }
            else
            {
                lblUserid.Text = "Empty String";
            }
        }
    }
}

Popular posts from this blog

Mandavrayji Temple, Muli, Surendranagar, Gujarat

Write a program to change color of Label text control programmatically in Asp.Net.