RaiseCallbackEvent Server Controls Such as TextBox1.Text value remains empty

E

emailseshu

Hi,

Iam trying to check the Client Side CallBack Feature in ASP.NET

Iam able to call th RaiseCallbackEvent from the Client Side Javascript
Function but when I go to the debug mode to check the Value of the
TextBox it always remains "" or empty rather than the value I gave as
input into the text box before invoking the RaiseCallBack.

Code is simple

1 WebForm.aspx Page


<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script type="text/javascript">
function LookUpStock()
{
var lb = document.getElementById("ListBox1");
var product = "";//lb.options[lb.selectedIndex].text;
CallServer(product, "");
}

function ReceiveServerData(rValue)
{
document.getElementById("ResultsSpan").innerHTML = rValue;

}
</script>



<script runat="server">
protected System.Collections.Specialized.ListDictionary
catalog;
protected String returnValue;

void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
String cbReference =
Page.ClientScript.GetCallbackEventReference(this,
textbox1.Text, "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" +
"{ " + cbReference + ";}";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"CallServer", callbackScript, true);


}
}




public string GetCallbackResult()
{
bool btest = Page.IsCallback;
return textbox1.Text; // This always comes as empty in
debug mode why?????
}



public void RaiseCallbackEvent(String eventArgument)
{

//
Response.Write("OK::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
// if (catalog[eventArgument] == null)
// {
////////// returnValue = "-1";
//}
// else
{

returnValue = textbox1.Text; //
catalog[eventArgument].ToString();
}



}




</script>
</head>
<body>

<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" Runat="server"></asp:ListBox>
<br />
<br />
<button type="Button" onclick="LookUpStock()">Look Up Stock</
button>
<br />
<br />
Items in stock: <span id="ResultsSpan" runat="server"></span>
<br />
<br />
<asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
<br />
</div>
</form>


</body>
</html>

Thanks in Advance
Regards
Seshu
 
G

Guest

Hi,
I think you are not doing properly.You will find following url useful for
raisecallbackevent:
http://west-wind.com/weblog/posts/2302.aspx
In this in GetCallbackEventReference you have to pass value of first
control.Then in RaiseCallbackEvent we will get value of this first
control.Here you can write some logic by using this value of first control
and then return string that uou want to diaplay in second control.Thereafter
in function OnCallback(Result,Context) you have to assign the string
returned(which you will get in result parameter) to second control through
javascript.
Hope this helps you out.
If you find this post useful then please do click yes at "Was this post
helpful to you".

Thanks and Regards,
Manish Bafna.
MCP and MCTS.





Hi,

Iam trying to check the Client Side CallBack Feature in ASP.NET

Iam able to call th RaiseCallbackEvent from the Client Side Javascript
Function but when I go to the debug mode to check the Value of the
TextBox it always remains "" or empty rather than the value I gave as
input into the text box before invoking the RaiseCallBack.

Code is simple

1 WebForm.aspx Page


<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script type="text/javascript">
function LookUpStock()
{
var lb = document.getElementById("ListBox1");
var product = "";//lb.options[lb.selectedIndex].text;
CallServer(product, "");
}

function ReceiveServerData(rValue)
{
document.getElementById("ResultsSpan").innerHTML = rValue;

}
</script>



<script runat="server">
protected System.Collections.Specialized.ListDictionary
catalog;
protected String returnValue;

void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
String cbReference =
Page.ClientScript.GetCallbackEventReference(this,
textbox1.Text, "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" +
"{ " + cbReference + ";}";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"CallServer", callbackScript, true);


}
}




public string GetCallbackResult()
{
bool btest = Page.IsCallback;
return textbox1.Text; // This always comes as empty in
debug mode why?????
}



public void RaiseCallbackEvent(String eventArgument)
{

//
Response.Write("OK::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
// if (catalog[eventArgument] == null)
// {
////////// returnValue = "-1";
//}
// else
{

returnValue = textbox1.Text; //
catalog[eventArgument].ToString();
}



}




</script>
</head>
<body>

<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" Runat="server"></asp:ListBox>
<br />
<br />
<button type="Button" onclick="LookUpStock()">Look Up Stock</
button>
<br />
<br />
Items in stock: <span id="ResultsSpan" runat="server"></span>
<br />
<br />
<asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
<br />
</div>
</form>


</body>
</html>

Thanks in Advance
Regards
Seshu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top