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
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