nemostyle
nemostyle

Reputation: 814

What is the best way to return values from another page in code behind in asp.net?

I have two pages. On the first one I have two drop down lists and button like this:

enter image description here

Code for this button is:

protected void btnIzabraniProizvodi_Click(object sender, EventArgs e)
{
    Session["Id_Dobavljaca"] = ddlDobavljaci.SelectedValue;
    Session["Id_Kategorija"] = ddlKategorija.SelectedValue;
    Response.Redirect("IzabraniProizvodi.aspx");
}

When I click on this button the secont page opens.enter image description here

This two sessions are input parameters for the SQL query. Here is the code on the second page:

protected void Page_Load(object sender, EventArgs e)
{
    string idDobavljaca = Session["Id_Dobavljaca"].ToString();
    string idKategorija = Session["Id_Kategorija"].ToString();
    string konekcioniString = ConfigurationManager.ConnectionStrings["moja_konekcija"].ConnectionString;
        using (SqlConnection sqlKonekcija = new SqlConnection(konekcioniString))
        {
            SqlDataAdapter sqlDA = new SqlDataAdapter("spVratiIzabraneProizvode", sqlKonekcija);
            sqlDA.SelectCommand.Parameters.AddWithValue("@Id_dobavljaca", idDobavljaca);
            sqlDA.SelectCommand.Parameters.AddWithValue("@Id_kategorija", idKategorija);
            sqlDA.SelectCommand.CommandType = CommandType.StoredProcedure;

            DataSet ds = new DataSet();
            sqlDA.Fill(ds);

            ds.Tables[0].TableName = "IzabraniProizvodi";
            gridView.DataSource = ds.Tables["IzabraniProizvodi"];
            gridView.DataBind();
        }
    }

My question is, when this dataSet is empty how can I get some message on the first page below the button: "No information for this values, try again with different values"? Any idea?

Upvotes: 0

Views: 45

Answers (1)

Farzin Kanzi
Farzin Kanzi

Reputation: 3435

There is no way to do this normally and you have two not good ways:

  1. You can use child and parent page. The second page will be the child of first page and data will send from child to parent by javascript. but the problem is that this does not work in chrome for security reasons.
  2. The second way is to check automatically from first page by ajax method in periods of times.

    setInterval(function(){ AJAX-CHECK }, 5000)

If you want each one of those senarios i will more explain.

Upvotes: 1

Related Questions