Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way for me to stop the web page from refreshing every time a user selects something from the dropdownlist? I have 11 dropdownlist and every one has a different function. Here is my code.

C#
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing.Printing;
public partial class SchoolReports : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ButtonPrint.Attributes.Add("onclick", "window.print(); return false");
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
    }
    protected void DropDownListSchools_SelectedIndexChanged(object sender, EventArgs e)
    {
        

        lblINST_ID.Text = DropDownListSchools.SelectedValue;
        

    }
    protected void DropDownListCFY1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTASSETS, TOTLIABILITY, UNRNETASSETS, NonExppermresAssets, TotalRev, TuitFees, CurrDebt, LongTermDebt from TableFIN2009 where INST_ID = " + DropDownListCFY1.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA1.Text = dr["TOTASSETS"].ToString();
            TextBoxTL1.Text = dr["TOTLIABILITY"].ToString();
            TextBoxUNA1.Text = dr["UNRNETASSETS"].ToString();
            TextBoxPRNA1.Text = dr["NonExppermresAssets"].ToString();
            TextBoxTR1.Text = dr["TotalRev"].ToString();
            TextBoxTFN1.Text = dr["TuitFees"].ToString();
            TextBoxCD1.Text = dr["CurrDebt"].ToString();
            TextBoxLDT1.Text = dr["LongTermDebt"].ToString();
            
            int a = Convert.ToInt32(TextBoxTA1.Text);
            int b = Convert.ToInt32(TextBoxTL1.Text);
            TextBoxTNA1.Text = Convert.ToString(a - b);

            int a1 = Convert.ToInt32(TextBoxUNA1.Text);
            int b1 = Convert.ToInt32(TextBoxPRNA1.Text);
            TextBoxTNAS1.Text = Convert.ToString(a1 + b1); 



        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListCFY2_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTASSETS, TOTLIABILITY, UNRNETASSETS, NonExppermresAssets, TotalRev, TuitFees, CurrDebt, LongTermDebt from TableFIN2010 where INST_ID = " + DropDownListCFY2.SelectedValue.ToString(), con);
        
        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA2.Text = dr["TOTASSETS"].ToString();
            TextBoxTL2.Text = dr["TOTLIABILITY"].ToString();
            TextBoxUNA2.Text = dr["UNRNETASSETS"].ToString();
            TextBoxPRNA2.Text = dr["NonExppermresAssets"].ToString();
            TextBoxTR2.Text = dr["TotalRev"].ToString();
            TextBoxTFN2.Text = dr["TuitFees"].ToString();
            TextBoxCD2.Text = dr["CurrDebt"].ToString();
            TextBoxLTD2.Text = dr["LongTermDebt"].ToString();

            int a = Convert.ToInt32(TextBoxTA2.Text);
            int b = Convert.ToInt32(TextBoxTL2.Text);
            TextBoxTNA2.Text = Convert.ToString(a - b);

            int a2 = Convert.ToInt32(TextBoxUNA2.Text);
            int b2 = Convert.ToInt32(TextBoxPRNA2.Text);
            TextBoxTNAS2.Text = Convert.ToString(a2 + b2); 

        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListCFY3_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTASSETS, TOTLIABILITY, UNRNETASSETS, NonExppermresAssets, TotalRev, TuitFees, CurrDebt, LongTermDebt from TableFIN2011 where INST_ID = " + DropDownListCFY3.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA3.Text = dr["TOTASSETS"].ToString();
            TextBoxTL3.Text = dr["TOTLIABILITY"].ToString();
            TextBoxUNA3.Text = dr["UNRNETASSETS"].ToString();
            TextBoxPRNA3.Text = dr["NonExppermresAssets"].ToString();
            TextBoxTR3.Text = dr["TotalRev"].ToString();
            TextBoxTFN3.Text = dr["TuitFees"].ToString();
            TextBoxCD3.Text = dr["CurrDebt"].ToString();
            TextBoxLTD3.Text = dr["LongTermDebt"].ToString();

            int a = Convert.ToInt32(TextBoxTA3.Text);
            int b = Convert.ToInt32(TextBoxTL3.Text);
            TextBoxTNA3.Text = Convert.ToString(a - b);

            int a3 = Convert.ToInt32(TextBoxUNA3.Text);
            int b3 = Convert.ToInt32(TextBoxPRNA3.Text);
            TextBoxTNAS3.Text = Convert.ToString(a3 + b3); 

        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListCFY4_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTASSETS, TOTLIABILITY, UNRNETASSETS, NonExppermresAssets, TotalRev, TuitFees, CurrDebt, LongTermDebt from TableFIN2012 where INST_ID = " + DropDownListCFY4.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA4.Text = dr["TOTASSETS"].ToString();
            TextBoxTL4.Text = dr["TOTLIABILITY"].ToString();
            TextBoxUNA4.Text = dr["UNRNETASSETS"].ToString();
            TextBoxPRNA4.Text = dr["NonExppermresAssets"].ToString();
            TextBoxTR4.Text = dr["TotalRev"].ToString();
            TextBoxTFN4.Text = dr["TuitFees"].ToString();
            TextBoxCD4.Text = dr["CurrDebt"].ToString();
            TextBoxLTD4.Text = dr["LongTermDebt"].ToString();

            int a = Convert.ToInt32(TextBoxTA4.Text);
            int b = Convert.ToInt32(TextBoxTL4.Text);
            TextBoxTNA4.Text = Convert.ToString(a - b);

            int a4 = Convert.ToInt32(TextBoxUNA4.Text);
            int b4 = Convert.ToInt32(TextBoxPRNA4.Text);
            TextBoxTNAS4.Text = Convert.ToString(a4 + b4); 

        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListCFY5_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTASSETS, TOTLIABILITY, UNRNETASSETS, NonExppermresAssets, TotalRev, TuitFees, CurrDebt, LongTermDebt from TableFIN2013 where INST_ID = " + DropDownListCFY5.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA5.Text = dr["TOTASSETS"].ToString();
            TextBoxTL5.Text = dr["TOTLIABILITY"].ToString();
            TextBoxUNA5.Text = dr["UNRNETASSETS"].ToString();           
            TextBoxPRNA5.Text = dr["NonExppermresAssets"].ToString();
            TextBoxTR5.Text = dr["TotalRev"].ToString();
            TextBoxTFN5.Text = dr["TuitFees"].ToString();
            TextBoxCD5.Text = dr["CurrDebt"].ToString();
            TextBoxLTD5.Text = dr["LongTermDebt"].ToString();

            int a = Convert.ToInt32(TextBoxTA5.Text);
            int b = Convert.ToInt32(TextBoxTL5.Text);
            TextBoxTNA5.Text = Convert.ToString(a - b);

            int a5 = Convert.ToInt32(TextBoxUNA5.Text);
            int b5 = Convert.ToInt32(TextBoxPRNA5.Text);
            TextBoxTNAS5.Text = Convert.ToString(a5 + b5); 

        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListFY1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();

        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTAL_FTE from TableFTE2009 where INST_ID = " + DropDownListFY1.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
          TextBoxEPCOC1.Text = dr["TOTAL_FTE"].ToString();
        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListFY2_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();

        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTAL_FTE from TableFTE2010 where INST_ID = " + DropDownListFY2.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxEPCOC2.Text = dr["TOTAL_FTE"].ToString();
        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListFY3_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();

        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTAL_FTE from TableFTE2011 where INST_ID = " + DropDownListFY3.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxEPCOC3.Text = dr["TOTAL_FTE"].ToString();
        }
        dr.Close();
        con.Close();

    }
    protected void DropDownListFY4_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();

        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTAL_FTE from TableFTE2012 where INST_ID = " + DropDownListFY4.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxEPCOC4.Text = dr["TOTAL_FTE"].ToString();
        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListFY5_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();

        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTAL_FTE from TableFTE2013 where INST_ID = " + DropDownListFY5.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxEPCOC5.Text = dr["TOTAL_FTE"].ToString();
        }
        dr.Close();
        con.Close();
    }
    
}
Posted
Comments
Anand Kumar Prajapati 11-Sep-13 21:07pm    
use ajax for partial postback.
it will not refresh whole page.

Set Autopostback to false for the DropDownList so you have to refresh the data on clientside.

There is an onchange event for dropdownlist on clientside you can start with that. You can use updatepanel to refresh or you can look for ajax toolkit or jquery plugin to solve your problem.
 
Share this answer
 
v2
Comments
Computer Wiz99 11-Sep-13 13:17pm    
Ok. I have tried that and the dropdownlists will not work. Any other way? The dropdownlist is databound. I need the AutoPostBack to do the functions of the dropdownlist.
norbitrial 11-Sep-13 16:17pm    
You can refresh your dropdowlist on clientside.
Computer Wiz99 11-Sep-13 16:27pm    
How can I do that?
norbitrial 12-Sep-13 2:42am    
There is an onchange event for dropdownlist on clientside you can start with that. You can use updatepanel to refresh or you can look for ajax toolkit or jquery plugin to solve your problem.
Computer Wiz99 12-Sep-13 8:53am    
Ok. Thanks.
Set the autopostback property to false of the dropdownlist.
 
Share this answer
 
Comments
Computer Wiz99 11-Sep-13 13:09pm    
Ok. I have tried that and the dropdownlists will not work. Any other way? The dropdownlist is databound. I need the AutoPostBack to do the functions of the dropdownlist.
Richard C Bishop 11-Sep-13 13:11pm    
It has to refresh then, if you want it to not refresh you would need to use some client side scripting.
Computer Wiz99 11-Sep-13 13:12pm    
Ok. DO you have any articles on that?
Richard C Bishop 11-Sep-13 13:13pm    
Not personally, I know jquery or javascript would be a good place to start.
Computer Wiz99 11-Sep-13 13:14pm    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900