Click here to Skip to main content
15,909,193 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Button click event Pin
N a v a n e e t h29-Jul-07 20:25
N a v a n e e t h29-Jul-07 20:25 
GeneralRe: Button click event Pin
miniThomas29-Jul-07 20:40
miniThomas29-Jul-07 20:40 
GeneralRe: Button click event Pin
N a v a n e e t h29-Jul-07 21:21
N a v a n e e t h29-Jul-07 21:21 
QuestionHow can eliminate constant polling? Pin
Mikeyyy29-Jul-07 19:37
Mikeyyy29-Jul-07 19:37 
AnswerRe: How can eliminate constant polling? Pin
Christian Graus29-Jul-07 20:02
protectorChristian Graus29-Jul-07 20:02 
QuestionProblem with postback Pin
dharanighanta29-Jul-07 19:31
dharanighanta29-Jul-07 19:31 
AnswerRe: Problem with postback Pin
Paul Conrad29-Jul-07 19:45
professionalPaul Conrad29-Jul-07 19:45 
GeneralRe: Problem with postback Pin
dharanighanta29-Jul-07 19:58
dharanighanta29-Jul-07 19:58 
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, cn); 

SqlDataReader rdr1 = cmd.ExecuteReader( ); 

using (rdr1) 

{

while (rdr1.Read() ) 

{

returnString. Append(rdr1[ 2]);

returnString. Append(","); 

}

}

rdr1.Close() ;

cn.Close();

}

catch (Exception ex) 

{

Response.Write( ex.Message) ;

}

}

return returnString. ToString( ); 

}

protected void Button1_Click(object sender, EventArgs e) 

{

Response.Write( ddl.SelectedItem .Text);

Response.Write( DropDownList1. SelectedItem. Text);

}

}



ASPX CODE:

<%

@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallBack. aspx.cs" Inherits="ClientCallBack" EnableEventValidati on="false" %> 

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/ /EN" "http://www. w3.org/TR/ xhtml1/DTD/ xhtml1-transitio nal.dtd"> 

< 

html xmlns="http://www. w3.org/1999/ xhtml"> 

< 

head id="Head1" runat="server"> 

<title>Client Callback on ChillapzLocal</title> 

<script type="text/javascript" language="javascript"> 

//Function to handle and process the server-side result 

//The result comes as string and the method takes two arguments, here. 

function CallbackonClientsid e(stringResult, context) 

{

var listCompany = document.forms[ 0].elements['DropDownList1']; 

listCompany. innerHTML = 

""; 

var entries = stringResult. split(','); 

var str = ""; 

for(var i=0;i<entries.length- 1;i++) 

{

var company = entries[i]; 

//Create the list item 

var item = document.createElem ent('option'); 

item.value = company;

item.innerHTML = company;

listCompany. appendChild( item);

}

//alert("end" ); 

}

</script> 

</

head> 

< 

body> 

<form id="form1" runat="server"> 

<div> 

State: 

          

<asp:DropDownList ID="ddl" runat="server"> 

</asp:DropDownList> 

<br /> 

<br /> 

County: 

       

<asp:DropDownList ID="DropDownList1" runat="server"> 

</asp:DropDownList> <br /> 

<br /> 

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div> 

</form> 

</

body> 

</

html>

GeneralRe: Problem with postback Pin
dharanighanta29-Jul-07 20:05
dharanighanta29-Jul-07 20:05 
GeneralRe: Problem with postback Pin
Paul Conrad29-Jul-07 20:07
professionalPaul Conrad29-Jul-07 20:07 
GeneralRe: Problem with postback Pin
dharanighanta29-Jul-07 20:58
dharanighanta29-Jul-07 20:58 
GeneralRe: Problem with postback Pin
ballameharmurali30-Jul-07 1:52
ballameharmurali30-Jul-07 1:52 
GeneralRe: Problem with postback Pin
dharanighanta30-Jul-07 2:02
dharanighanta30-Jul-07 2:02 
GeneralRe: Problem with postback Pin
Paul Conrad30-Jul-07 5:19
professionalPaul Conrad30-Jul-07 5:19 
QuestionIssue in using MSDataShape Pin
Venkatesh Mookkan29-Jul-07 19:25
Venkatesh Mookkan29-Jul-07 19:25 
AnswerRe: Issue in using MSDataShape Pin
Christian Graus29-Jul-07 19:27
protectorChristian Graus29-Jul-07 19:27 
GeneralRe: Issue in using MSDataShape Pin
Venkatesh Mookkan29-Jul-07 19:38
Venkatesh Mookkan29-Jul-07 19:38 
QuestionFunny validator problem Pin
Anton Afanasyev29-Jul-07 19:20
Anton Afanasyev29-Jul-07 19:20 
QuestionVideo and Flash files Pin
.NET- India 29-Jul-07 19:10
.NET- India 29-Jul-07 19:10 
QuestionMerging two GridView Rows Pin
varshavmane29-Jul-07 18:29
varshavmane29-Jul-07 18:29 
GeneralRe: Merging two GridView Rows Pin
BasharatAli29-Jul-07 19:10
BasharatAli29-Jul-07 19:10 
GeneralRe: Merging two GridView Rows Pin
varshavmane29-Jul-07 19:16
varshavmane29-Jul-07 19:16 
AnswerRe: Merging two GridView Rows Pin
BasharatAli29-Jul-07 19:43
BasharatAli29-Jul-07 19:43 
AnswerRe: Merging two GridView Rows Pin
BasharatAli29-Jul-07 19:52
BasharatAli29-Jul-07 19:52 
GeneralRe: Merging two GridView Rows Pin
varshavmane29-Jul-07 20:22
varshavmane29-Jul-07 20:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.