Problem with postback
-
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;
-
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;
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
-
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
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
-
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
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?
-
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
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
-
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
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.
-
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.
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
-
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
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
-
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
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