Greetings, I have a problem, I'm building a test site for example that connects to facebook chat and shows online contacts, well I did the xmpp connection and connect well and also brings users connected, this I know that becouse i check it with the points
of interruption.
the problem is, is when I add the contacts to the listbox or listview by listcontact.item.add or link a class or table via datasource does not display anything in the listbox, and even try to show it in a textbox and did not show eithe, i put my sample
code and put the web to see I'm doing wrong.
the problem is in xmppClient_OnPresence, I have tried with many codes but I do not load. thats why you can see so many junk code, Greetings and I hope you can help me solve the problem, sorry for my english
Imports System.Collections
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Diagnostics
Imports System.Drawing
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Windows.Forms
Imports System.Security.Cryptography.X509Certificates
Imports System.Xml.Linq
Imports Matrix
Imports Matrix.Xml
Imports Matrix.Xmpp
Imports Matrix.Xmpp.Client
Imports Matrix.Xmpp.Register
Imports Matrix.Xmpp.XData
Imports Presence = Matrix.Xmpp.Client.Presence
Imports RosterItem = Matrix.Xmpp.Roster.RosterItem
Imports Subscription = Matrix.Xmpp.Roster.Subscription
Imports EventArgs = Matrix.EventArgs
Partial Class Default4
Inherits System.Web.UI.Page
Public Shared Function SendMessage(window As IntPtr, message As Integer, wparam As Integer, lparam As Integer) As IntPtr
End Function
Public Shared Function GetRosterImageIndex(pres As Presence) As Integer
If pres.Type = PresenceType.unavailable Then
Return 0
End If
Select Case pres.Show
Case Show.chat
Return 1
Case Show.away
Return 2
Case Show.xa
Return 2
Case Show.dnd
Return 3
Case Else
Return 1
End Select
End Function
Const WM_VSCROLL As Integer = &H115
Const SB_BOTTOM As Integer = 7
Public listado As New System.Windows.Forms.ListView
Private WithEvents rtfDebug As System.Windows.Forms.RichTextBox
Private WithEvents xmppClient As Matrix.Xmpp.Client.XmppClient
Private WithEvents presenceManager As Matrix.Xmpp.Client.PresenceManager
Private WithEvents Ros As Matrix.Xmpp.Roster.RosterEventArgs
Private ReadOnly _dictContactGroups As New Dictionary(Of String, ListViewGroup)()
Private ReadOnly _dictContats As New Dictionary(Of Jid, RosterItem)()
Private Shared Sub SetLicense()
'const string LIC = @"YOUR LICENSE";
'Matrix.License.LicenseManager.SetLicense(LIC);
End Sub
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager
Me.cmdConnect = New System.Web.UI.WebControls.Button()
Me.cmdDisconnect = New System.Web.UI.WebControls.Button()
Me.listContacts = New System.Web.UI.WebControls.ListBox()
'Me.listContacts = New System.Web.UI.WebControls.ListView()
Me.listEvents = New System.Web.UI.WebControls.ListBox()
Me.txtHost = New System.Web.UI.WebControls.TextBox()
Me.txtserver = New System.Web.UI.WebControls.TextBox()
Me.txtPassword = New System.Web.UI.WebControls.TextBox()
'
'
'xmppClient
'
Me.xmppClient = New Matrix.Xmpp.Client.XmppClient
Me.xmppClient.Compression = False
Me.xmppClient.Hostname = Nothing
Me.xmppClient.ProxyHostname = Nothing
Me.xmppClient.ProxyPass = Nothing
Me.xmppClient.ProxyPort = 1080
Me.xmppClient.ProxyType = Matrix.Net.Proxy.ProxyType.None
Me.xmppClient.ProxyUser = Nothing
Me.xmppClient.ResolveSrvRecords = True
Me.xmppClient.Status = ""
Me.xmppClient.Transport = Matrix.Net.Transport.Socket
Me.xmppClient.Uri = Nothing
End Sub
Public Sub New()
InitializeComponent()
SetLicense()
End Sub
Private Sub DisplayEvent(ev As String)
listEvents.Items.Add(ev)
listEvents.SelectedIndex = listEvents.Items.Count - 1
End Sub
Protected Sub cmdConnect_Click(sender As Object, e As System.EventArgs) Handles cmdConnect.Click
xmppClient.SetXmppDomain(txtserver.Text)
xmppClient.SetUsername(txtUsername.Text)
xmppClient.Password = txtPassword.Text
xmppClient.Status = "ready for chat"
xmppClient.Show = Xmpp.Show.chat
If Not String.IsNullOrEmpty(txtHost.Text) Then
xmppClient.Hostname = txtHost.Text
End If
xmppClient.Open()
End Sub
Protected Sub cmdDisconnect_Click(sender As Object, e As System.EventArgs) Handles cmdDisconnect.Click
xmppClient.Close()
End Sub
Private Sub xmppClient_OnPrebind(sender As Object, e As Matrix.Net.PrebindEventArgs) Handles xmppClient.OnPrebind
DisplayEvent("OnPrebind Rid:" + e.Rid + " Sid:" + e.Sid)
End Sub
Private Sub xmppClient_OnError(sender As Object, e As ExceptionEventArgs) Handles xmppClient.OnError
DisplayEvent("OnError")
End Sub
Private Sub xmppClient_OnLogin(sender As Object, e As Matrix.EventArgs) Handles xmppClient.OnLogin
DisplayEvent("OnLogin")
End Sub
Private Sub xmppClient_OnBind(sender As Object, e As JidEventArgs) Handles xmppClient.OnBind
DisplayEvent("OnBind")
End Sub
Private Sub xmppClient_OnClose(sender As Object, e As Matrix.EventArgs) Handles xmppClient.OnClose
DisplayEvent("OnClose")
listContacts.Items.Clear()
End Sub
Private Sub xmppClient_OnRosterStart(sender As Object, e As Matrix.EventArgs) Handles xmppClient.OnRosterStart
End Sub
Private Sub xmppClient_OnRosterEnd(sender As Object, e As Matrix.EventArgs) Handles xmppClient.OnRosterEnd
DisplayEvent("OnRosterEnd")
End Sub
Private Sub xmppClient_OnRosterItem(sender As Object, e As Matrix.Xmpp.Roster.RosterEventArgs)
Dim version = e.Version
DisplayEvent(String.Format("OnRosterItem" & vbTab & "{0}" & vbTab & "{1}", e.RosterItem.Jid, e.RosterItem.Name))
If e.RosterItem.Subscription <> Subscription.remove Then
' set a default group name
Dim groupname As String = "Contacts"
' id the contact has groups get the 1st group. In this example we don't support multiple or nested groups
' for contacts, but XMPP has support for this.
If e.RosterItem.HasGroups Then
groupname = e.RosterItem.GetGroups()(0)
End If
If Not _dictContactGroups.ContainsKey(groupname) Then
Dim newGroup = New ListViewGroup(groupname)
_dictContactGroups.Add(groupname, newGroup)
'listContacts.Groups.Add(newGroup)
End If
Dim listGroup = _dictContactGroups(groupname)
' contact already exists, this is a contact update
If _dictContats.ContainsKey(e.RosterItem.Jid) Then
listContacts.Items.RemoveAt(e.RosterItem.Jid)
End If
'var newItem = new ListViewItem(e.RosterItem.Jid, listGroup) {Name = e.RosterItem.Jid};
Dim newItem = New RosterListViewItem(If(e.RosterItem.Name, e.RosterItem.Jid.ToString), 0, listGroup) With {.Name = e.RosterItem.Jid.Bare}
newItem.SubItems.AddRange(New String() {"", ""})
listado.Items.Add(newItem)
End If
End Sub
Private Sub xmppClient_OnPresence(sender As Object, e As PresenceEventArgs)
DisplayEvent(String.Format("OnPresence" & vbTab & "{0}", e.Presence.From))
If e.Presence.Type = PresenceType.subscribe Then
ElseIf e.Presence.Type = PresenceType.subscribed Then
ElseIf e.Presence.Type = PresenceType.unsubscribe Then
ElseIf e.Presence.Type = PresenceType.unsubscribed Then
Else
Dim item = TryCast(listado.Items(e.Presence.From.Bare), RosterListViewItem)
Dim dStudent As New Dictionary(Of Integer, String)()
For i = 0 To item.SubItems.Count - 1
dStudent.Add(i, item.Text)
txtJabberIdReceiver.Text = item.Text
Console.WriteLine(item.Text)
Next
listContacts.DataSource = dStudent
listContacts.DataTextField = "Value"
listContacts.DataValueField = "Key"
listContacts.DataBind()
If item IsNot Nothing Then
item.ImageIndex = GetRosterImageIndex(e.Presence)
Dim resource As String = e.Presence.From.Resource
If e.Presence.Type <> PresenceType.unavailable Then
If Not item.Resources.Contains(resource) Then
item.Resources.Add(resource)
End If
Else
If item.Resources.Contains(resource) Then
item.Resources.Remove(resource)
End If
End If
End If
End If
End Sub
Have you also checked you are getting any data? Connecting is nice. But if no data comes through, you'll still end up with an empty ListBox.
Also, what is the ToString() of the objects? If you don't set either DataTextField or DataValueField, ListBox will try to use the ToString() value. If that is empty, you will get a ListBox with all empty items.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Hi, yes im getting data because i check it with interruption points f11 in visual studio 2010, somebody told me i have to polled or push the data to the listbox whit comet or reverse ajax becouse im using matrix to get the contacts. i dont understand very
well because im starting to create an website of this kind, sorry for my english
Well, the nature of web-pages is that the initiative is with the browser. In other words, a page won't refresh unless the browser does something. You can't receive data on the server and push it to the browser.
The way around it is to use things like flash, silverlight, or some smart javascript. (Like reverse Ajax.)
The more conventional way to solve it is to use a Timer in the web-page to give the browser the initiative to refresh content. The server can then put in the fresh content.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
edmyjose
0 Points
6 Posts
listbox no load data in code behind
Aug 07, 2012 12:29 PM|LINK
Greetings, I have a problem, I'm building a test site for example that connects to facebook chat and shows online contacts, well I did the xmpp connection and connect well and also brings users connected, this I know that becouse i check it with the points of interruption.
the problem is, is when I add the contacts to the listbox or listview by listcontact.item.add or link a class or table via datasource does not display anything in the listbox, and even try to show it in a textbox and did not show eithe, i put my sample code and put the web to see I'm doing wrong.
the problem is in xmppClient_OnPresence, I have tried with many codes but I do not load. thats why you can see so many junk code, Greetings and I hope you can help me solve the problem, sorry for my english
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default4.aspx.vb" Inherits="Default4" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <!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 runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ListBox ID="listEvents" runat="server" AutoPostBack="true" Width="109px"></asp:ListBox> <asp:ListBox ID="listContacts" runat="server" Height="299px" Width="246px" AutoPostBack="True"></asp:ListBox> <asp:TextBox ID="rtfDebug1" runat="server" TextMode="MultiLine" Height="243px" Width="250px"></asp:TextBox> <br /> <asp:TextBox ID="txtUsername" runat="server" Text="usuario"></asp:TextBox> <asp:TextBox ID="txtPassword" runat="server" Text="clave"></asp:TextBox> <asp:TextBox ID="txtserver" runat="server" Text="chat.facebook.com"></asp:TextBox> <br /> <asp:TextBox ID="txtMessage" runat="server"></asp:TextBox> <asp:Button ID="cmdConnect" runat="server" onclick="cmdConnect_Click" Text="Login" /> <asp:Button ID="cmdDisconnect" runat="server" onclick="cmdDisconnect_Click" Text="Logout" /> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:TextBox ID="txtJabberIdReceiver" runat="server" Text="txtJabberIdReceiver"></asp:TextBox> <asp:TextBox ID="txtHost" runat="server" Text="txtHost"></asp:TextBox> </div> </form> </body> </html>Imports System.Collections Imports System.Collections.Generic Imports System.Configuration Imports System.Data Imports System.Diagnostics Imports System.Drawing Imports System.IO Imports System.Runtime.InteropServices Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.HtmlControls Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Windows.Forms Imports System.Security.Cryptography.X509Certificates Imports System.Xml.Linq Imports Matrix Imports Matrix.Xml Imports Matrix.Xmpp Imports Matrix.Xmpp.Client Imports Matrix.Xmpp.Register Imports Matrix.Xmpp.XData Imports Presence = Matrix.Xmpp.Client.Presence Imports RosterItem = Matrix.Xmpp.Roster.RosterItem Imports Subscription = Matrix.Xmpp.Roster.Subscription Imports EventArgs = Matrix.EventArgs Partial Class Default4 Inherits System.Web.UI.Page Public Shared Function SendMessage(window As IntPtr, message As Integer, wparam As Integer, lparam As Integer) As IntPtr End Function Public Shared Function GetRosterImageIndex(pres As Presence) As Integer If pres.Type = PresenceType.unavailable Then Return 0 End If Select Case pres.Show Case Show.chat Return 1 Case Show.away Return 2 Case Show.xa Return 2 Case Show.dnd Return 3 Case Else Return 1 End Select End Function Const WM_VSCROLL As Integer = &H115 Const SB_BOTTOM As Integer = 7 Public listado As New System.Windows.Forms.ListView Private WithEvents rtfDebug As System.Windows.Forms.RichTextBox Private WithEvents xmppClient As Matrix.Xmpp.Client.XmppClient Private WithEvents presenceManager As Matrix.Xmpp.Client.PresenceManager Private WithEvents Ros As Matrix.Xmpp.Roster.RosterEventArgs Private ReadOnly _dictContactGroups As New Dictionary(Of String, ListViewGroup)() Private ReadOnly _dictContats As New Dictionary(Of Jid, RosterItem)() Private Shared Sub SetLicense() 'const string LIC = @"YOUR LICENSE"; 'Matrix.License.LicenseManager.SetLicense(LIC); End Sub Private Sub InitializeComponent() Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager Me.cmdConnect = New System.Web.UI.WebControls.Button() Me.cmdDisconnect = New System.Web.UI.WebControls.Button() Me.listContacts = New System.Web.UI.WebControls.ListBox() 'Me.listContacts = New System.Web.UI.WebControls.ListView() Me.listEvents = New System.Web.UI.WebControls.ListBox() Me.txtHost = New System.Web.UI.WebControls.TextBox() Me.txtserver = New System.Web.UI.WebControls.TextBox() Me.txtPassword = New System.Web.UI.WebControls.TextBox() ' ' 'xmppClient ' Me.xmppClient = New Matrix.Xmpp.Client.XmppClient Me.xmppClient.Compression = False Me.xmppClient.Hostname = Nothing Me.xmppClient.ProxyHostname = Nothing Me.xmppClient.ProxyPass = Nothing Me.xmppClient.ProxyPort = 1080 Me.xmppClient.ProxyType = Matrix.Net.Proxy.ProxyType.None Me.xmppClient.ProxyUser = Nothing Me.xmppClient.ResolveSrvRecords = True Me.xmppClient.Status = "" Me.xmppClient.Transport = Matrix.Net.Transport.Socket Me.xmppClient.Uri = Nothing End Sub Public Sub New() InitializeComponent() SetLicense() End Sub Private Sub DisplayEvent(ev As String) listEvents.Items.Add(ev) listEvents.SelectedIndex = listEvents.Items.Count - 1 End Sub Protected Sub cmdConnect_Click(sender As Object, e As System.EventArgs) Handles cmdConnect.Click xmppClient.SetXmppDomain(txtserver.Text) xmppClient.SetUsername(txtUsername.Text) xmppClient.Password = txtPassword.Text xmppClient.Status = "ready for chat" xmppClient.Show = Xmpp.Show.chat If Not String.IsNullOrEmpty(txtHost.Text) Then xmppClient.Hostname = txtHost.Text End If xmppClient.Open() End Sub Protected Sub cmdDisconnect_Click(sender As Object, e As System.EventArgs) Handles cmdDisconnect.Click xmppClient.Close() End Sub Private Sub xmppClient_OnPrebind(sender As Object, e As Matrix.Net.PrebindEventArgs) Handles xmppClient.OnPrebind DisplayEvent("OnPrebind Rid:" + e.Rid + " Sid:" + e.Sid) End Sub Private Sub xmppClient_OnError(sender As Object, e As ExceptionEventArgs) Handles xmppClient.OnError DisplayEvent("OnError") End Sub Private Sub xmppClient_OnLogin(sender As Object, e As Matrix.EventArgs) Handles xmppClient.OnLogin DisplayEvent("OnLogin") End Sub Private Sub xmppClient_OnBind(sender As Object, e As JidEventArgs) Handles xmppClient.OnBind DisplayEvent("OnBind") End Sub Private Sub xmppClient_OnClose(sender As Object, e As Matrix.EventArgs) Handles xmppClient.OnClose DisplayEvent("OnClose") listContacts.Items.Clear() End Sub Private Sub xmppClient_OnRosterStart(sender As Object, e As Matrix.EventArgs) Handles xmppClient.OnRosterStart End Sub Private Sub xmppClient_OnRosterEnd(sender As Object, e As Matrix.EventArgs) Handles xmppClient.OnRosterEnd DisplayEvent("OnRosterEnd") End Sub Private Sub xmppClient_OnRosterItem(sender As Object, e As Matrix.Xmpp.Roster.RosterEventArgs) Dim version = e.Version DisplayEvent(String.Format("OnRosterItem" & vbTab & "{0}" & vbTab & "{1}", e.RosterItem.Jid, e.RosterItem.Name)) If e.RosterItem.Subscription <> Subscription.remove Then ' set a default group name Dim groupname As String = "Contacts" ' id the contact has groups get the 1st group. In this example we don't support multiple or nested groups ' for contacts, but XMPP has support for this. If e.RosterItem.HasGroups Then groupname = e.RosterItem.GetGroups()(0) End If If Not _dictContactGroups.ContainsKey(groupname) Then Dim newGroup = New ListViewGroup(groupname) _dictContactGroups.Add(groupname, newGroup) 'listContacts.Groups.Add(newGroup) End If Dim listGroup = _dictContactGroups(groupname) ' contact already exists, this is a contact update If _dictContats.ContainsKey(e.RosterItem.Jid) Then listContacts.Items.RemoveAt(e.RosterItem.Jid) End If 'var newItem = new ListViewItem(e.RosterItem.Jid, listGroup) {Name = e.RosterItem.Jid}; Dim newItem = New RosterListViewItem(If(e.RosterItem.Name, e.RosterItem.Jid.ToString), 0, listGroup) With {.Name = e.RosterItem.Jid.Bare} newItem.SubItems.AddRange(New String() {"", ""}) listado.Items.Add(newItem) End If End Sub Private Sub xmppClient_OnPresence(sender As Object, e As PresenceEventArgs) DisplayEvent(String.Format("OnPresence" & vbTab & "{0}", e.Presence.From)) If e.Presence.Type = PresenceType.subscribe Then ElseIf e.Presence.Type = PresenceType.subscribed Then ElseIf e.Presence.Type = PresenceType.unsubscribe Then ElseIf e.Presence.Type = PresenceType.unsubscribed Then Else Dim item = TryCast(listado.Items(e.Presence.From.Bare), RosterListViewItem) Dim dStudent As New Dictionary(Of Integer, String)() For i = 0 To item.SubItems.Count - 1 dStudent.Add(i, item.Text) txtJabberIdReceiver.Text = item.Text Console.WriteLine(item.Text) Next listContacts.DataSource = dStudent listContacts.DataTextField = "Value" listContacts.DataValueField = "Key" listContacts.DataBind() If item IsNot Nothing Then item.ImageIndex = GetRosterImageIndex(e.Presence) Dim resource As String = e.Presence.From.Resource If e.Presence.Type <> PresenceType.unavailable Then If Not item.Resources.Contains(resource) Then item.Resources.Add(resource) End If Else If item.Resources.Contains(resource) Then item.Resources.Remove(resource) End If End If End If End If End SubEnd Class
superguppie
All-Star
48225 Points
8679 Posts
Re: listbox no load data in code behind
Aug 08, 2012 03:21 PM|LINK
Have you also checked you are getting any data? Connecting is nice. But if no data comes through, you'll still end up with an empty ListBox.
Also, what is the ToString() of the objects? If you don't set either DataTextField or DataValueField, ListBox will try to use the ToString() value. If that is empty, you will get a ListBox with all empty items.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
edmyjose
0 Points
6 Posts
Re: listbox no load data in code behind
Aug 13, 2012 04:18 PM|LINK
Hi, yes im getting data because i check it with interruption points f11 in visual studio 2010, somebody told me i have to polled or push the data to the listbox whit comet or reverse ajax becouse im using matrix to get the contacts. i dont understand very well because im starting to create an website of this kind, sorry for my english
superguppie
All-Star
48225 Points
8679 Posts
Re: listbox no load data in code behind
Aug 14, 2012 10:11 AM|LINK
Well, the nature of web-pages is that the initiative is with the browser. In other words, a page won't refresh unless the browser does something. You can't receive data on the server and push it to the browser.
The way around it is to use things like flash, silverlight, or some smart javascript. (Like reverse Ajax.)
The more conventional way to solve it is to use a Timer in the web-page to give the browser the initiative to refresh content. The server can then put in the fresh content.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.