IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Acces textbox.text depuis un webservice


Sujet :

VB.NET

  1. #1
    Membre éclairé Avatar de DeWaRs
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Décembre 2006
    Messages
    291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 291
    Par défaut Acces textbox.text depuis un webservice
    Bonjour a tous,

    Je vais surement me faire taper dessus en posant cette question mais je ne trouve pas de réponse.
    Je cherche à recuperer la valeur d'une textbox dans un fichier .asmx.vb mais je n'y arrive pas.

    J'ai essayer de créer une fonction partager qui me retourne la valeur de la textbox mais je n'ai pas le droit :
    Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
    Je ne vois pas du tout comment faire, quelqu'un peut-il me guider ?

    Merci d'avance.

    DeWaRs

  2. #2
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Par défaut
    Oula, quel est le rapport entre un Web Service et une application (tu ne précise même pas si c'est Winforms ou ASP.NET) ?
    Qu'est ce que tu cherches à faire exactement ?
    Besoin d'un MessageBox amélioré ? InformationBox pour .NET 1.1, 2.0, 3.0, 3.5, 4.0 sous license Apache 2.0.

    Bonnes pratiques pour les accès aux données
    Débogage efficace en .NET
    LINQ to Objects : l'envers du décor

    Mon profil LinkedIn - MCT - MCPD WinForms - MCTS Applications Distribuées - MCTS WCF - MCTS WCF 4.0 - MCTS SQL Server 2008, Database Development - Mon blog - Twitter

  3. #3
    Membre éclairé Avatar de DeWaRs
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Décembre 2006
    Messages
    291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 291
    Par défaut
    Oula effectivement, j'ai oublier que je fait de l'ASP.NET avec VB.NET.

    En fait, j'utilise un Webservice pour faire des cascading dropdownlist (via ajaxtoolkit) et je voudrais que ses dropdownlist dépendent de la valeur d'une textbox. Mais je n'arrive pas a acceder à cette textbox.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
     
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.ComponentModel
    Imports System
    Imports System.Web
    Imports System.Collections
    Imports System.Collections.Generic
    Imports System.Collections.Specialized
    Imports AjaxControlToolkit
    Imports System.Configuration
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.DirectoryServices
     
     
    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
     
    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <System.Web.Script.Services.ScriptService()> _
    Public Class cascad
     
        Inherits System.Web.Services.WebService
     
     
     
        <WebMethod()> _
        Public Function GetBuilding(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
     
     
     
            Dim strConnection As String = ConfigurationManager.ConnectionStrings("IT_Rent_connection").ConnectionString
            Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
            Dim UserID as string 
            UserID = TBUserID.Text 
            Dim LDAP As New DirectoryEntry("LDAP://************")
            Dim searcher As DirectorySearcher = New DirectorySearcher(LDAP)
            searcher.PropertiesToLoad.Add("SAMAccountName")
            searcher.PropertiesToLoad.Add("co")
            searcher.Filter = "(&(SAMAccountName=" & UserID & ")(objectCategory=user))"
     
            'Looking for the countryname of the user
            Dim results As System.DirectoryServices.SearchResultCollection
            Try
                results = searcher.FindAll()
            Catch ex As Exception
     
            End Try
     
            Dim result As System.DirectoryServices.SearchResult
            Dim country As String = ""
            For Each result In results
                country = Trim(CStr(result.Properties("co")(0)))
            Next
     
            textbox_test.test()
     
            MsgBox(country)
     
            'Looking for the IdCountry
            country = "'" & country & "'"
            Dim strCountryQuery As String = "SELECT * FROM COUNTRY WHERE CountryName=" & country
            ' MsgBox(strCountryQuery)
            Dim cmdFetchCountry As SqlCommand = New SqlCommand(strCountryQuery, sqlConn)
            Dim dtrCountry As SqlDataReader
            Dim IdCountry As String = ""
            sqlConn.Open()
            dtrCountry = cmdFetchCountry.ExecuteReader
            While dtrCountry.Read()
                Dim strCountryName As String = dtrCountry("CountryName").ToString
                Dim strCountryId As String = dtrCountry("IdCountry").ToString
                IdCountry = strCountryId
            End While
            sqlConn.Close()
     
     
            'Looking for IDCountry with Country of the user 
     
            Dim strBuildingQuery As String = "SELECT * FROM BUILDING WHERE IdCountry=" & IdCountry
     
            Dim cmdFetchBuilding As SqlCommand = New SqlCommand(strBuildingQuery, sqlConn)
     
            Dim dtrBuilding As SqlDataReader
            Dim kvBuilding As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
            sqlConn.Open()
            Dim myBuilding As New List(Of CascadingDropDownNameValue)
            dtrBuilding = cmdFetchBuilding.ExecuteReader
     
            While dtrBuilding.Read()
                Dim strBuildingName As String = dtrBuilding("BuildingName").ToString
                Dim strBuildingId As String = dtrBuilding("IdBuilding").ToString
     
                myBuilding.Add(New CascadingDropDownNameValue(strBuildingName, strBuildingId))
            End While
     
            Return myBuilding.ToArray
        End Function
     
     
        <WebMethod()> _
        Public Function GetMaterial(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
            Dim strConnection As String = ConfigurationManager.ConnectionStrings("IT_Rent_connection").ConnectionString
            Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
            Dim strTeamQuery As String = "SELECT DISTINCT HardWareType.IdType,  HardWareType.HardwareName from country, building,	material,	HardWareType where	building.IdBuilding = @confid	and	country.IdCountry = building.IdCountry	and	building.IdBuilding = material.IdBuilding	and 	material.IdType = HardWareType.IdType"
     
            Dim cmdFetchTeam As SqlCommand = New SqlCommand(strTeamQuery, sqlConn)
     
            Dim dtrTeam As SqlDataReader
            Dim kvTeam As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
            'MsgBox(knownCategoryValues)
            Dim intConfId As Integer
     
            If Not kvTeam.ContainsKey("IdBuilding") Or Not Int32.TryParse(kvTeam("IdBuilding"), intConfId) Then
     
                Return Nothing
            End If
     
            cmdFetchTeam.Parameters.AddWithValue("@confid", intConfId)
            Dim myTeams As New List(Of CascadingDropDownNameValue)
     
            sqlConn.Open()
            dtrTeam = cmdFetchTeam.ExecuteReader
     
            While dtrTeam.Read()
                Dim strTeamName As String = dtrTeam("HardwareName").ToString
                Dim strTeamId As String = dtrTeam("IdType").ToString
     
                myTeams.Add(New CascadingDropDownNameValue(strTeamName, strTeamId))
            End While
     
            Return myTeams.ToArray
     
     
     
     
     
        End Function
     
    End Class
    C'est cette partie qui ne fonctionne pas :
    Dim UserID as string
    UserID = TBUserID.Text

    Merci de votre aide.

    DeWaRs

  4. #4
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Par défaut
    Tu devrais passer la valeur de cette textbox en parametre du Web Service.
    Le Web Service ne doit pas dépendre d'une quelconque interface (c'est le principe même du service).
    Besoin d'un MessageBox amélioré ? InformationBox pour .NET 1.1, 2.0, 3.0, 3.5, 4.0 sous license Apache 2.0.

    Bonnes pratiques pour les accès aux données
    Débogage efficace en .NET
    LINQ to Objects : l'envers du décor

    Mon profil LinkedIn - MCT - MCPD WinForms - MCTS Applications Distribuées - MCTS WCF - MCTS WCF 4.0 - MCTS SQL Server 2008, Database Development - Mon blog - Twitter

  5. #5
    Membre éclairé Avatar de DeWaRs
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Décembre 2006
    Messages
    291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 291
    Par défaut
    Merci de ta réponse mais je suis toujours dans le flou :s
    Pourrais tu être un peu plus précis ?

    Merci d'avance

    DeWaRs

  6. #6
    Membre éclairé Avatar de DeWaRs
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Décembre 2006
    Messages
    291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 291
    Par défaut
    Hello,

    J'ai finalement utiliser une variable de session pour stocker ma valeur.

    Cordialement.

    DeWaRs

  7. #7
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Mars 2010
    Messages
    366
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations forums :
    Inscription : Mars 2010
    Messages : 366
    Par défaut
    quand tu initialises la variable de session?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème accès Textbox depuis une classe enfant
    Par Moutmouth dans le forum C#
    Réponses: 1
    Dernier message: 31/01/2011, 12h34
  2. acces base postgres depuis eclipse
    Par mealtone dans le forum PostgreSQL
    Réponses: 4
    Dernier message: 03/06/2005, 10h16
  3. Accès serveur WEB depuis l'internet
    Par Ultra-FX dans le forum Réseau
    Réponses: 2
    Dernier message: 26/05/2005, 17h00
  4. [JAR]ouverture de fichier texte depuis executables jar
    Par julien31 dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 01/03/2005, 15h53
  5. [MSDE 2000] Récup champ text depuis proc stockée
    Par Air'V dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 14/12/2003, 19h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo