Husnain Khan Husnain Khan - 1 year ago 112
ASP.NET (C#) Question

Form get blank when Page_Load function is called?

I am facing a problem in my form. There are two text field and then there is drop-down menu, which link to a database.

When I click on the drop down menu, my two text fields are getting empty.

protected void OnChange_Acdemics(object Sender, EventArgs e)
DropDownList list = (DropDownList)Sender;
string value = (string)list.SelectedValue;

// degrees_dropdown.Visible = true;

// String query = "SELECT Degree_types.detail,Degree_Detail.GPA FROM Degree_Detail INNER JOIN Degree_types ON Degree_Detail.Degree_tilte = Degree_types.Degree_title where Degree_types.degree_type = '" + value + "';";
String query = "Select detail from Degree_Detail where id=" + int.Parse(value) + ";";
Dt = dbComm.GetDataTable(query);
Degree_Selection.DataTextField = "detail";
// Degree_Selection.DataValueField = "GPA";
Degree_Selection.DataSource = Dt;

catch (Exception ex)


Answer Source

You need to take care of this by using Page.IsPostBack:

   // load page 
   // check input values and set it again
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download