calling server side method from javascript

smriti

Regular
Joined
Jan 7, 2005
Messages
54
I want some help regarding client callbacks
I have two dropdowns in my webpage . Whenever I select a value from the first dropdown the corresponding values(stored in data base)should be binded to the next dropdown by using client callbacks. I.e., Without refreshing the page.
I tried to do something based upon your article but
i am not able to find system.web.ui.ICallbackEventHandler
to implement.
If you have any sample code in vb, can u please send it to me provided if u r free.

Thanks
 
Use javascript. Store all possible sub list values in a Javascript array, when you select a parent list value, use javascript to fill the sub list with the array contents.
 
database connectivity

kahlua001 said:
Use javascript. Store all possible sub list values in a Javascript array, when you select a parent list value, use javascript to fill the sub list with the array contents.

Thanks for ur response

But this requires to establish database connectivity in javascript..
isn't it.
 
No, you do not need db connectivity in javascript. You connect to the database in your codebehind, and write out the javascript arrays on the client, ready to use when needed.
 
kahlua001 said:
No, you do not need db connectivity in javascript. You connect to the database in your codebehind, and write out the javascript arrays on the client, ready to use when needed.

I tried out with the following code,
I know that this causes page refresh,
can u provide me code or any sample how to access this in javascript
as i didn't use javascript till now. :o , provided u r free.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'***************************************
' Variable Declaration
'***************************************
If Not Page.IsPostBack Then
Dim sqlCon As SqlConnection
Dim sqlCmd As SqlCommand
Dim sqlDr As SqlDataReader

' Creating Connection to the Database

sqlCon = New SqlConnection(ConfigurationSettings.AppSettings("dsn"))
sqlCon.Open()
sqlCmd = New SqlCommand("select Client from xyz", sqlCon)
sqlDr = sqlCmd.ExecuteReader
DropDownList1.DataSource = sqlDr

'Fetching clientid from the Database And assign them to the dropdown list

While sqlDr.Read
Dim newListItem As New ListItem
newListItem.Value = sqlDr.GetString(0)
DropDownList1.Items.Add(newListItem)
End While
sqlCon.Close()
End If
End Sub


Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

'***************************************
' Variable Declarations
'***************************************

Dim strStr1 As String
Dim strStr2 As String
Dim sqlCon As SqlConnection
Dim sqlCmd As SqlCommand
Dim sqlDr As SqlDataReader

strStr1 = DropDownList1.SelectedValue
strStr2 = "Some query"

' Establishing a connection to the database

sqlCon = New SqlConnection(ConfigurationSettings.AppSettings("dsn"))
sqlCon.Open()
sqlCmd = New SqlCommand(strStr2, sqlCon)
sqlDr = sqlCmd.ExecuteReader
dropdownlist2.Items.Clear()
dropdownlist2.DataSource = sqlDr

' Fetching records from the database and assign them to the dropdown control

While sqlDr.Read
Dim newlistitem1 As New ListItem
newlistitem1.Text = sqlDr.GetValue(0)
dropdownlist2.Items.Add(newlistitem1)
End While
End Sub
 
Back
Top