Chetan Sarode
Chetan Sarode

Reputation: 79

variable not use in another webform

managing connection string on dropdown selection now the question is this "connection" object is not working in another webform because i need to use this connection on hole app using this connection object how to solve

String connection = String.Empty;

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (DropDownList1.SelectedItem.Text.Equals("RVL LOGISTICS (I) PVT LTD"))
    {
        connection = ConfigurationManager.ConnectionStrings["CompMasterConnectionString"].ConnectionString;
    }
    else if (DropDownList1.SelectedItem.Text.Equals("SIMONS SHIPPING PVT LTD"))
    {
        connection = ConfigurationManager.ConnectionStrings["DUM01ConnectionString"].ConnectionString;
    }
    else
    {
        DropDownList2.Enabled = false;
    }
}

Upvotes: 1

Views: 56

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 157048

Page state is not persistent: it goes out of memory once the page is rendered.

You have to store the value elsewhere in order to reuse it. Where you save it depends on where you want to use it.

Some options:

  • Pass it through an URL. This might have security implications;
  • View state;
  • Session object storage;
  • Application object storage.

Upvotes: 2

Related Questions