Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem with postback

Problem with postback

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-netdatabasedesign
9 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dharanighanta
    wrote on last edited by
    #1

    Hi All, We have two dropdownlists in my web page.In second dropdownlist items will be appear based upon first dropdownlist selection item with out page postback.I have implemented using System.Web.UI.ICallbackEventHandler interface with asp.net2.0. But i structed with button click event.If i click button for save the info into database the second dropdownlist items cleared.I am sending my code here.Pls go throught it tell me solution..... CODEBEHIEND CODE: Using System; Using System.Data; Using System.Data. SqlClient; Using System.Configuratio n; Using System.Web.Configur ation; Using System.Collections; Using System.Web; Using System.Web.Security ; Using System.Web.UI; Using System.Web.UI. WebControls; Using System.Web.UI. WebControls. WebParts; Using System.Web.UI. HtmlControls; Using System.Text; Public partial class ClientCallBack : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler { private string raiseCallArgument, stateId; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string strConnection = WebConfigurationMan ager.ConnectionStrings["DemoConn"].ConnectionString; SqlConnection con = new SqlConnection(strConnection) ; string strSQL = "SELECT DISTINCT * FROM tblRmStateMaster"; using (con) { con.Open(); SqlCommand objCmd = new SqlCommand(strSQL, con); SqlDataReader dtReader = objCmd.ExecuteReade r(); using (dtReader) { if (dtReader.HasRows) { ddl.DataSource = dtReader; ddl.DataTextField = "Statename"; ddl.DataValueField = "Statename"; ddl.DataBind( ); } } } } if (Request.Browser. SupportsCallback ) { string callbackRef = Page.ClientScript. GetCallbackEvent Reference(this, "document.forms[ 0].elements[ 'ddl'].value", "CallbackonClientsi de", "null"); ddl.Attributes["onChange"] = callbackRef; } } public void RaiseCallbackEvent(string raiseCallArgument) { this.raiseCallArgument = raiseCallArgument; stateId = this.raiseCallArgument; } //This method should return a string value for the Javascript method to handle public string GetCallbackResult( ) { StringBuilder returnString = new StringBuilder(); using (SqlConnection cn = new SqlConnection(ConfigurationManage r.ConnectionStrings["DemoConn"].ToString() )) { cn.Close(); cn.Open(); SqlCommand cmd1 = new SqlCommand("select * from tblRmStateMaster where Statename='" + stateId + "' ", cn); SqlDataReader dr;

    P 1 Reply Last reply
    0
    • D dharanighanta

      Hi All, We have two dropdownlists in my web page.In second dropdownlist items will be appear based upon first dropdownlist selection item with out page postback.I have implemented using System.Web.UI.ICallbackEventHandler interface with asp.net2.0. But i structed with button click event.If i click button for save the info into database the second dropdownlist items cleared.I am sending my code here.Pls go throught it tell me solution..... CODEBEHIEND CODE: Using System; Using System.Data; Using System.Data. SqlClient; Using System.Configuratio n; Using System.Web.Configur ation; Using System.Collections; Using System.Web; Using System.Web.Security ; Using System.Web.UI; Using System.Web.UI. WebControls; Using System.Web.UI. WebControls. WebParts; Using System.Web.UI. HtmlControls; Using System.Text; Public partial class ClientCallBack : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler { private string raiseCallArgument, stateId; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string strConnection = WebConfigurationMan ager.ConnectionStrings["DemoConn"].ConnectionString; SqlConnection con = new SqlConnection(strConnection) ; string strSQL = "SELECT DISTINCT * FROM tblRmStateMaster"; using (con) { con.Open(); SqlCommand objCmd = new SqlCommand(strSQL, con); SqlDataReader dtReader = objCmd.ExecuteReade r(); using (dtReader) { if (dtReader.HasRows) { ddl.DataSource = dtReader; ddl.DataTextField = "Statename"; ddl.DataValueField = "Statename"; ddl.DataBind( ); } } } } if (Request.Browser. SupportsCallback ) { string callbackRef = Page.ClientScript. GetCallbackEvent Reference(this, "document.forms[ 0].elements[ 'ddl'].value", "CallbackonClientsi de", "null"); ddl.Attributes["onChange"] = callbackRef; } } public void RaiseCallbackEvent(string raiseCallArgument) { this.raiseCallArgument = raiseCallArgument; stateId = this.raiseCallArgument; } //This method should return a string value for the Javascript method to handle public string GetCallbackResult( ) { StringBuilder returnString = new StringBuilder(); using (SqlConnection cn = new SqlConnection(ConfigurationManage r.ConnectionStrings["DemoConn"].ToString() )) { cn.Close(); cn.Open(); SqlCommand cmd1 = new SqlCommand("select * from tblRmStateMaster where Statename='" + stateId + "' ", cn); SqlDataReader dr;

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      Can you narrow down where the problem is occurring? It is rather difficult with the way the code is formatted in your post. Try to have it inside < pre > / < /pre >tags to preserve the indentation for the most part :)

      "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

      D 1 Reply Last reply
      0
      • P Paul Conrad

        Can you narrow down where the problem is occurring? It is rather difficult with the way the code is formatted in your post. Try to have it inside < pre > / < /pre >tags to preserve the indentation for the most part :)

        "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

        D Offline
        D Offline
        dharanighanta
        wrote on last edited by
        #3

        Hi Paul, Thank you for the immediate reply.I am sending code put it in pre tags... CODEBEHIEND CODE:

        Using System;

        Using System.Data;

        Using System.Data. SqlClient;

        Using System.Configuratio n;

        Using System.Web.Configur ation;

        Using System.Collections;

        Using System.Web;

        Using System.Web.Security ;

        Using System.Web.UI;

        Using System.Web.UI. WebControls;

        Using System.Web.UI. WebControls. WebParts;

        Using System.Web.UI. HtmlControls;

        Using System.Text;

        Public partial class ClientCallBack : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler

        {

        private string raiseCallArgument, stateId;

        protected void Page_Load(object sender, EventArgs e)

        {

        if (!IsPostBack)

        {

        string strConnection = WebConfigurationMan ager.ConnectionStrings["DemoConn"].ConnectionString;

        SqlConnection con = new SqlConnection(strConnection) ;

        string strSQL = "SELECT DISTINCT * FROM tblRmStateMaster";

        using (con)

        {

        con.Open();

        SqlCommand objCmd = new SqlCommand(strSQL, con);

        SqlDataReader dtReader = objCmd.ExecuteReade r();

        using (dtReader)

        {

        if (dtReader.HasRows)

        {

        ddl.DataSource = dtReader;

        ddl.DataTextField = "Statename";

        ddl.DataValueField = "Statename";

        ddl.DataBind( );

        }

        }

        }

        }

        if (Request.Browser. SupportsCallback )

        {

        string callbackRef = Page.ClientScript. GetCallbackEvent Reference(this, "document.forms[ 0].elements[ 'ddl'].value", "CallbackonClientsi de", "null");

        ddl.Attributes["onChange"] = callbackRef;

        }

        }

        public void RaiseCallbackEvent(string raiseCallArgument)

        {

        this.raiseCallArgument = raiseCallArgument;

        stateId = this.raiseCallArgument;

        }

        //This method should return a string value for the Javascript method to handle

        public string GetCallbackResult( )

        {

        StringBuilder returnString = new StringBuilder();

        using (SqlConnection cn = new SqlConnection(ConfigurationManage r.ConnectionStrings["DemoConn"].ToString() ))

        {

        cn.Close();

        cn.Open();

        SqlCommand cmd1 = new SqlCommand("select * from tblRmStateMaster where Statename='" + stateId + "' ", cn);

        SqlDataReader dr;

        dr = cmd1.ExecuteReader( );

        string str = "";

        while (dr.Read())

        {

        str = dr[

        "Stateid"].ToString() ;

        }

        dr.Close();

        cn.Close();

        int a = ddl.SelectedIndex + 1;

        string exp = raiseCallArgument;

        try

        {

        cn.Open();

        SqlCommand cmd = new SqlCommand("select DISTINCT * from tblRmCountyMaster where Stateid=" + str

        D P 2 Replies Last reply
        0
        • D dharanighanta

          Hi Paul, Thank you for the immediate reply.I am sending code put it in pre tags... CODEBEHIEND CODE:

          Using System;

          Using System.Data;

          Using System.Data. SqlClient;

          Using System.Configuratio n;

          Using System.Web.Configur ation;

          Using System.Collections;

          Using System.Web;

          Using System.Web.Security ;

          Using System.Web.UI;

          Using System.Web.UI. WebControls;

          Using System.Web.UI. WebControls. WebParts;

          Using System.Web.UI. HtmlControls;

          Using System.Text;

          Public partial class ClientCallBack : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler

          {

          private string raiseCallArgument, stateId;

          protected void Page_Load(object sender, EventArgs e)

          {

          if (!IsPostBack)

          {

          string strConnection = WebConfigurationMan ager.ConnectionStrings["DemoConn"].ConnectionString;

          SqlConnection con = new SqlConnection(strConnection) ;

          string strSQL = "SELECT DISTINCT * FROM tblRmStateMaster";

          using (con)

          {

          con.Open();

          SqlCommand objCmd = new SqlCommand(strSQL, con);

          SqlDataReader dtReader = objCmd.ExecuteReade r();

          using (dtReader)

          {

          if (dtReader.HasRows)

          {

          ddl.DataSource = dtReader;

          ddl.DataTextField = "Statename";

          ddl.DataValueField = "Statename";

          ddl.DataBind( );

          }

          }

          }

          }

          if (Request.Browser. SupportsCallback )

          {

          string callbackRef = Page.ClientScript. GetCallbackEvent Reference(this, "document.forms[ 0].elements[ 'ddl'].value", "CallbackonClientsi de", "null");

          ddl.Attributes["onChange"] = callbackRef;

          }

          }

          public void RaiseCallbackEvent(string raiseCallArgument)

          {

          this.raiseCallArgument = raiseCallArgument;

          stateId = this.raiseCallArgument;

          }

          //This method should return a string value for the Javascript method to handle

          public string GetCallbackResult( )

          {

          StringBuilder returnString = new StringBuilder();

          using (SqlConnection cn = new SqlConnection(ConfigurationManage r.ConnectionStrings["DemoConn"].ToString() ))

          {

          cn.Close();

          cn.Open();

          SqlCommand cmd1 = new SqlCommand("select * from tblRmStateMaster where Statename='" + stateId + "' ", cn);

          SqlDataReader dr;

          dr = cmd1.ExecuteReader( );

          string str = "";

          while (dr.Read())

          {

          str = dr[

          "Stateid"].ToString() ;

          }

          dr.Close();

          cn.Close();

          int a = ddl.SelectedIndex + 1;

          string exp = raiseCallArgument;

          try

          {

          cn.Open();

          SqlCommand cmd = new SqlCommand("select DISTINCT * from tblRmCountyMaster where Stateid=" + str

          D Offline
          D Offline
          dharanighanta
          wrote on last edited by
          #4

          Hi paul, I posted aspx source code but in that code i had two dropdownlist and one button control those controls are not displaying in the posted message.why it is not appearing?

          1 Reply Last reply
          0
          • D dharanighanta

            Hi Paul, Thank you for the immediate reply.I am sending code put it in pre tags... CODEBEHIEND CODE:

            Using System;

            Using System.Data;

            Using System.Data. SqlClient;

            Using System.Configuratio n;

            Using System.Web.Configur ation;

            Using System.Collections;

            Using System.Web;

            Using System.Web.Security ;

            Using System.Web.UI;

            Using System.Web.UI. WebControls;

            Using System.Web.UI. WebControls. WebParts;

            Using System.Web.UI. HtmlControls;

            Using System.Text;

            Public partial class ClientCallBack : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler

            {

            private string raiseCallArgument, stateId;

            protected void Page_Load(object sender, EventArgs e)

            {

            if (!IsPostBack)

            {

            string strConnection = WebConfigurationMan ager.ConnectionStrings["DemoConn"].ConnectionString;

            SqlConnection con = new SqlConnection(strConnection) ;

            string strSQL = "SELECT DISTINCT * FROM tblRmStateMaster";

            using (con)

            {

            con.Open();

            SqlCommand objCmd = new SqlCommand(strSQL, con);

            SqlDataReader dtReader = objCmd.ExecuteReade r();

            using (dtReader)

            {

            if (dtReader.HasRows)

            {

            ddl.DataSource = dtReader;

            ddl.DataTextField = "Statename";

            ddl.DataValueField = "Statename";

            ddl.DataBind( );

            }

            }

            }

            }

            if (Request.Browser. SupportsCallback )

            {

            string callbackRef = Page.ClientScript. GetCallbackEvent Reference(this, "document.forms[ 0].elements[ 'ddl'].value", "CallbackonClientsi de", "null");

            ddl.Attributes["onChange"] = callbackRef;

            }

            }

            public void RaiseCallbackEvent(string raiseCallArgument)

            {

            this.raiseCallArgument = raiseCallArgument;

            stateId = this.raiseCallArgument;

            }

            //This method should return a string value for the Javascript method to handle

            public string GetCallbackResult( )

            {

            StringBuilder returnString = new StringBuilder();

            using (SqlConnection cn = new SqlConnection(ConfigurationManage r.ConnectionStrings["DemoConn"].ToString() ))

            {

            cn.Close();

            cn.Open();

            SqlCommand cmd1 = new SqlCommand("select * from tblRmStateMaster where Statename='" + stateId + "' ", cn);

            SqlDataReader dr;

            dr = cmd1.ExecuteReader( );

            string str = "";

            while (dr.Read())

            {

            str = dr[

            "Stateid"].ToString() ;

            }

            dr.Close();

            cn.Close();

            int a = ddl.SelectedIndex + 1;

            string exp = raiseCallArgument;

            try

            {

            cn.Open();

            SqlCommand cmd = new SqlCommand("select DISTINCT * from tblRmCountyMaster where Stateid=" + str

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            You may have to step through the code, cannot really tell where the problem is.

            "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

            D 1 Reply Last reply
            0
            • P Paul Conrad

              You may have to step through the code, cannot really tell where the problem is.

              "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

              D Offline
              D Offline
              dharanighanta
              wrote on last edited by
              #6

              Hi Paul, Just go through the below link http://www.remapper.com/callback.aspx In that i have two dropdownlists,I will select state from first dropdownlist then those counties will be appear in second dropdownlist without postaback of the page.I am getting but if i click the button for retreiving selected state and county value then county values are disappeared.

              B 1 Reply Last reply
              0
              • D dharanighanta

                Hi Paul, Just go through the below link http://www.remapper.com/callback.aspx In that i have two dropdownlists,I will select state from first dropdownlist then those counties will be appear in second dropdownlist without postaback of the page.I am getting but if i click the button for retreiving selected state and county value then county values are disappeared.

                B Offline
                B Offline
                ballameharmurali
                wrote on last edited by
                #7

                hello dharini, try to keep the countrydropdownlist in AutPostBack=True or otherwise how ur calling the values of the dropdownlist of country like that call that function int the button click event. ok then u will get byeee Murali Murali

                D 1 Reply Last reply
                0
                • B ballameharmurali

                  hello dharini, try to keep the countrydropdownlist in AutPostBack=True or otherwise how ur calling the values of the dropdownlist of country like that call that function int the button click event. ok then u will get byeee Murali Murali

                  D Offline
                  D Offline
                  dharanighanta
                  wrote on last edited by
                  #8

                  Hi Murali, Thank you for the reply.Actually,my requirement is fill the county dropdownlist with out page postback.I am sending my code below...Just go thru it....That code copy into ur application and check it.

                  CODEBEHIEND CODE:

                  Using System;

                  Using System.Data;

                  Using System.Data. SqlClient;

                  Using System.Configuratio n;

                  Using System.Web.Configur ation;

                  Using System.Collections;

                  Using System.Web;

                  Using System.Web.Security ;

                  Using System.Web.UI;

                  Using System.Web.UI. WebControls;

                  Using System.Web.UI. WebControls. WebParts;

                  Using System.Web.UI. HtmlControls;

                  Using System.Text;

                  Public partial class ClientCallBack : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler

                  {

                  private string raiseCallArgument, stateId;

                  protected void Page_Load(object sender, EventArgs e)

                  {

                  if (!IsPostBack)

                  {

                  string strConnection = WebConfigurationMan ager.ConnectionStrings["DemoConn"].ConnectionString;

                  SqlConnection con = new SqlConnection(strConnection) ;

                  string strSQL = "SELECT DISTINCT * FROM tblRmStateMaster";

                  using (con)

                  {

                  con.Open();

                  SqlCommand objCmd = new SqlCommand(strSQL, con);

                  SqlDataReader dtReader = objCmd.ExecuteReade r();

                  using (dtReader)

                  {

                  if (dtReader.HasRows)

                  {

                  ddl.DataSource = dtReader;

                  ddl.DataTextField = "Statename";

                  ddl.DataValueField = "Statename";

                  ddl.DataBind( );

                  }

                  }

                  }

                  }

                  if (Request.Browser. SupportsCallback )

                  {

                  string callbackRef = Page.ClientScript. GetCallbackEvent Reference(this, "document.forms[ 0].elements[ 'ddl'].value", "CallbackonClientsi de", "null");

                  ddl.Attributes["onChange"] = callbackRef;

                  }

                  }

                  public void RaiseCallbackEvent(string raiseCallArgument)

                  {

                  this.raiseCallArgument = raiseCallArgument;

                  stateId = this.raiseCallArgument;

                  }

                  //This method should return a string value for the Javascript method to handle

                  public string GetCallbackResult( )

                  {

                  StringBuilder returnString = new StringBuilder();

                  using (SqlConnection cn = new SqlConnection(ConfigurationManage r.ConnectionStrings["DemoConn"].ToString() ))

                  {

                  cn.Close();

                  cn.Open();

                  SqlCommand cmd1 = new SqlCommand("select * from tblRmStateMaster where Statename='" + stateId + "' ", cn);

                  SqlDataReader dr;

                  dr = cmd1.ExecuteReader( );

                  string str = "";

                  while (dr.Read())

                  {

                  str = dr[

                  "Stateid"].ToString() ;

                  }

                  dr.Close();

                  cn.Close();

                  int a = ddl.SelectedIndex + 1;

                  string exp = raiseCallArgument;

                  t

                  P 1 Reply Last reply
                  0
                  • D dharanighanta

                    Hi Murali, Thank you for the reply.Actually,my requirement is fill the county dropdownlist with out page postback.I am sending my code below...Just go thru it....That code copy into ur application and check it.

                    CODEBEHIEND CODE:

                    Using System;

                    Using System.Data;

                    Using System.Data. SqlClient;

                    Using System.Configuratio n;

                    Using System.Web.Configur ation;

                    Using System.Collections;

                    Using System.Web;

                    Using System.Web.Security ;

                    Using System.Web.UI;

                    Using System.Web.UI. WebControls;

                    Using System.Web.UI. WebControls. WebParts;

                    Using System.Web.UI. HtmlControls;

                    Using System.Text;

                    Public partial class ClientCallBack : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler

                    {

                    private string raiseCallArgument, stateId;

                    protected void Page_Load(object sender, EventArgs e)

                    {

                    if (!IsPostBack)

                    {

                    string strConnection = WebConfigurationMan ager.ConnectionStrings["DemoConn"].ConnectionString;

                    SqlConnection con = new SqlConnection(strConnection) ;

                    string strSQL = "SELECT DISTINCT * FROM tblRmStateMaster";

                    using (con)

                    {

                    con.Open();

                    SqlCommand objCmd = new SqlCommand(strSQL, con);

                    SqlDataReader dtReader = objCmd.ExecuteReade r();

                    using (dtReader)

                    {

                    if (dtReader.HasRows)

                    {

                    ddl.DataSource = dtReader;

                    ddl.DataTextField = "Statename";

                    ddl.DataValueField = "Statename";

                    ddl.DataBind( );

                    }

                    }

                    }

                    }

                    if (Request.Browser. SupportsCallback )

                    {

                    string callbackRef = Page.ClientScript. GetCallbackEvent Reference(this, "document.forms[ 0].elements[ 'ddl'].value", "CallbackonClientsi de", "null");

                    ddl.Attributes["onChange"] = callbackRef;

                    }

                    }

                    public void RaiseCallbackEvent(string raiseCallArgument)

                    {

                    this.raiseCallArgument = raiseCallArgument;

                    stateId = this.raiseCallArgument;

                    }

                    //This method should return a string value for the Javascript method to handle

                    public string GetCallbackResult( )

                    {

                    StringBuilder returnString = new StringBuilder();

                    using (SqlConnection cn = new SqlConnection(ConfigurationManage r.ConnectionStrings["DemoConn"].ToString() ))

                    {

                    cn.Close();

                    cn.Open();

                    SqlCommand cmd1 = new SqlCommand("select * from tblRmStateMaster where Statename='" + stateId + "' ", cn);

                    SqlDataReader dr;

                    dr = cmd1.ExecuteReader( );

                    string str = "";

                    while (dr.Read())

                    {

                    str = dr[

                    "Stateid"].ToString() ;

                    }

                    dr.Close();

                    cn.Close();

                    int a = ddl.SelectedIndex + 1;

                    string exp = raiseCallArgument;

                    t

                    P Offline
                    P Offline
                    Paul Conrad
                    wrote on last edited by
                    #9

                    dharanighanta wrote:

                    my requirement is fill the county dropdownlist with out page postback

                    Why? I doubt it is possible without page postback. Anytime I've done web stuff that required populating a control after another control had some user action performed on it, I've always had to run the page through again but the next time, conditional branches guiding the behind the scenes code based on that user action. I don't know much about Ajax, but maybe that could help.

                    "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups