<%@ Page Language="VB" AutoEventWireup="true"
CodeFile="ClientCallback.aspx.vb" Inherits="ClientCallback" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html >
<head id="Head1" runat="server">
<title>Client Callback Example</title>
<script type="text/javascript">
function LookUpStock() {
var lb = document.getElementById("ListBox1");
try {
var product = lb.options[lb.selectedIndex].text;
CallServer(product, "");
}
catch (err) {
alert("Please select a product.");
}
}
function ReceiveServerData(rValue) {
document.getElementById("ResultsSpan").innerHTML = rValue;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" Runat="server"></asp:ListBox>
<br />
<br />
<input type="button" value="Look Up Stock" onclick="LookUpStock()" />
<br />
<br />
Items in stock: <span id="ResultsSpan" runat="server"></span>
<br />
</div>
</form>
</body>
</html>
Partial Class ClientCallback
Inherits System.Web.UI.Page
Implements System.Web.UI.ICallbackEventHandler
Protected catalog As ListDictionary
Protected returnValue As String
Sub Page_Load(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles Me.Load
Dim cbReference As String
cbReference = Page.ClientScript.GetCallbackEventReference(Me, _
"arg", "ReceiveServerData", "context")
Dim callbackScript As String = ""
callbackScript &= "function CallServer(arg, context) { " & _
cbReference & "} ;"
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), _
"CallServer", callbackScript, True)
' Populate List Dictionary with invented database data
catalog = New ListDictionary()
catalog.Add("monitor", 12)
catalog.Add("laptop", 10)
catalog.Add("keyboard", 23)
catalog.Add("mouse", 17)
ListBox1.DataSource = catalog
ListBox1.DataTextField = "key"
ListBox1.DataBind()
End Sub
Public Sub RaiseCallbackEvent(ByVal eventArgument As String) _
Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
If catalog(eventArgument) Is Nothing Then
returnValue = "-1"
Else
returnValue = catalog(eventArgument).ToString()
End If
End Sub
Public Function GetCallbackResult() _
As String Implements _
System.Web.UI.ICallbackEventHandler.GetCallbackResult
Return returnValue
End Function
End Class
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
I faceing similer problem before few days..i solve it with a trick.if it helpfull then follow ...
I am call a javascript method on textbox onblur() method .In this javascript method we set text box value in a hiddenfield.after that when postback event file then set hidden field value in a session.
Smadhu
Member
510 Points
989 Posts
how to save value of textbox in session varaible without postback,
Feb 29, 2012 08:06 AM|LINK
how to save value of textbox in session varaible without postback,
i dont want to do postback
MetalAsp.Net
All-Star
112168 Points
18255 Posts
Moderator
Re: how to save value of textbox in session varaible without postback,
Feb 29, 2012 08:14 AM|LINK
You'll need to make an AJAX call to a webservice/pagemethod and set the session value there.
kedarrkulkar...
All-Star
34515 Points
5554 Posts
Re: how to save value of textbox in session varaible without postback,
Feb 29, 2012 08:15 AM|LINK
use jquery post to call server side function and update session variable....
check this...
http://www.dotnetcurry.com/ShowArticle.aspx?ID=453
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
venkatmca008
Participant
1810 Points
341 Posts
Re: how to save value of textbox in session varaible without postback,
Feb 29, 2012 08:28 AM|LINK
hi..please download and use ..
http://go.microsoft.com/fwlink/?LinkId=192414
and refer this
http://msdn.microsoft.com/en-us/library/ms178208.aspx
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="ClientCallback.aspx.vb" Inherits="ClientCallback" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html > <head id="Head1" runat="server"> <title>Client Callback Example</title> <script type="text/javascript"> function LookUpStock() { var lb = document.getElementById("ListBox1"); try { var product = lb.options[lb.selectedIndex].text; CallServer(product, ""); } catch (err) { alert("Please select a product."); } } function ReceiveServerData(rValue) { document.getElementById("ResultsSpan").innerHTML = rValue; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ListBox ID="ListBox1" Runat="server"></asp:ListBox> <br /> <br /> <input type="button" value="Look Up Stock" onclick="LookUpStock()" /> <br /> <br /> Items in stock: <span id="ResultsSpan" runat="server"></span> <br /> </div> </form> </body> </html> Partial Class ClientCallback Inherits System.Web.UI.Page Implements System.Web.UI.ICallbackEventHandler Protected catalog As ListDictionary Protected returnValue As String Sub Page_Load(ByVal sender As Object, ByVal e As _ System.EventArgs) Handles Me.Load Dim cbReference As String cbReference = Page.ClientScript.GetCallbackEventReference(Me, _ "arg", "ReceiveServerData", "context") Dim callbackScript As String = "" callbackScript &= "function CallServer(arg, context) { " & _ cbReference & "} ;" Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), _ "CallServer", callbackScript, True) ' Populate List Dictionary with invented database data catalog = New ListDictionary() catalog.Add("monitor", 12) catalog.Add("laptop", 10) catalog.Add("keyboard", 23) catalog.Add("mouse", 17) ListBox1.DataSource = catalog ListBox1.DataTextField = "key" ListBox1.DataBind() End Sub Public Sub RaiseCallbackEvent(ByVal eventArgument As String) _ Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent If catalog(eventArgument) Is Nothing Then returnValue = "-1" Else returnValue = catalog(eventArgument).ToString() End If End Sub Public Function GetCallbackResult() _ As String Implements _ System.Web.UI.ICallbackEventHandler.GetCallbackResult Return returnValue End Function End ClassMicrosoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
suryakant4it
Member
51 Points
59 Posts
Re: how to save value of textbox in session varaible without postback,
Feb 29, 2012 12:00 PM|LINK
I faceing similer problem before few days..i solve it with a trick.if it helpfull then follow ...
I am call a javascript method on textbox onblur() method .In this javascript method we set text box value in a hiddenfield.after that when postback event file then set hidden field value in a session.
If help full then remarked as answer.