Can we have CallBack functionality implemented more than 1 time on same page?

Posted by Laghaterohan under Regular Expressions on 4/21/2011 | Points: 10 | Views : 1509 | Status : [Member] | Replies : 1
Hello,

May i know if we can implement call back functionality more than 1 time on same page? What if such condition arise? and i am sure it does arise...What needs to be done...
Please let me know the answer...thanks

Best Regards,
Rohan Laghate



Responses

Posted by: Ndebata on: 4/22/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

One way you achieve this by using your own logic.
Please take a look at the bellow code,
In aspx file
<head runat="server">

<title></title>
<script type="text/javascript" language="javascript">
function ReceiveServerData(arg, context) {
}
function ProcessCallBackError(arg, context) { }

function OnTextblur(tid) {
var myarg = tid.id + '#' + tid.value;
CallTheServer(myarg);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtOne" runat="server" onblur="OnTextblur(this);"></asp:TextBox>
<br />
<asp:TextBox ID="txtTwo" runat="server" onblur="OnTextblur(this);"></asp:TextBox>
</div>
</form>
</body>


And in code behind file you can check the id and process accordingly..

public partial class _Default : System.Web.UI.Page ,ICallbackEventHandler

{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ClientScriptManager cs = Page.ClientScript;
String cbReference = cs.GetCallbackEventReference("'" + Page.UniqueID + "'", "arg", "ReceiveServerData", "context", "ProcessCallBackError", false);
String callbackScript = "function CallTheServer(arg, context) {" + cbReference + "; }";
cs.RegisterClientScriptBlock(this.GetType(), "CallTheServer", callbackScript, true);

}
public string GetCallbackResult()
{
return null;
}
public void RaiseCallbackEvent(string eventArgument)
{
if (!string.IsNullOrEmpty(eventArgument) && eventArgument.Contains("#"))
{
string _id = eventArgument.Substring(0, eventArgument.IndexOf('#'));
string _value = eventArgument.Substring(eventArgument.IndexOf('#')+1);
switch (_id)
{
case "txtOne":
{
// process _value
} ; break;
case "txtTwo":
{
// process _value
} ; break;
default:
break;
}
}
}
}


Thanks,
Debata

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response