locked
Does the AutoCompleteExtender ServiceMethod have to be a Shared function? RRS feed

  • Question

  • User-196219249 posted

    I need to access the value of a radio button list control to dictate the data being return back from sql statement.

    I learned that I cannot access my radiobuttonlist control from the AutoCompleteExtender method because the function is shared.

    Is there another way NOT to use a Public Shared Function when calling the ServiceMethod within the AutoCompleteExtender?

    Thanks in advance

    Monday, August 7, 2017 8:12 PM

Answers

  • User2103319870 posted

    I learned that I cannot access my radiobuttonlist control from the AutoCompleteExtender method because the function is shared.

    You can use the session to access the value from RadioButtonList in a webmethod.

    Assign the value to session

     Session("RadioButtonlistval") = RadioButtonList1.SelectedValue

    and then access it like given below

     <System.Web.Script.Services.ScriptMethod>
        <System.Web.Services.WebMethod(EnableSession:=True)>
        Public Shared Function YourMethodName() As String
            'Get the selected value from dropdownlist here
            Dim selectedValue As String = HttpContext.Current.Session("DropdownVal").ToString()
        End Function

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 7, 2017 9:08 PM
  • User2103319870 posted

    Another option is to use Shared Variable.You can declare a Shared variable in code behind and then assign the RadioButtonList value to Shared variable. You will be able to access the Shared variable inside your Shared Method.

    Private Shared selectedval As String
        'Declare a Static Variable
        Public Shared Property strSeleccted() As String
            Get
                Return selectedval
            End Get
            Set
                selectedval = Value
            End Set
        End Property
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Me.IsPostBack Then
    
                'Assign the value to static variable
                strSeleccted = RadioButtonList1.SelectedValue
            End If
        End Sub
    

    You can access the variable like below

     <System.Web.Script.Services.ScriptMethod>
        <System.Web.Services.WebMethod(EnableSession:=True)>
        Public Shared Function YourMethodName() As String
            'Access the shared variable inside method
            Dim selectedValue As String = strSeleccted
        End Function

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 7, 2017 9:14 PM

All replies

  • User2103319870 posted

    I learned that I cannot access my radiobuttonlist control from the AutoCompleteExtender method because the function is shared.

    You can use the session to access the value from RadioButtonList in a webmethod.

    Assign the value to session

     Session("RadioButtonlistval") = RadioButtonList1.SelectedValue

    and then access it like given below

     <System.Web.Script.Services.ScriptMethod>
        <System.Web.Services.WebMethod(EnableSession:=True)>
        Public Shared Function YourMethodName() As String
            'Get the selected value from dropdownlist here
            Dim selectedValue As String = HttpContext.Current.Session("DropdownVal").ToString()
        End Function

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 7, 2017 9:08 PM
  • User2103319870 posted

    Another option is to use Shared Variable.You can declare a Shared variable in code behind and then assign the RadioButtonList value to Shared variable. You will be able to access the Shared variable inside your Shared Method.

    Private Shared selectedval As String
        'Declare a Static Variable
        Public Shared Property strSeleccted() As String
            Get
                Return selectedval
            End Get
            Set
                selectedval = Value
            End Set
        End Property
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Me.IsPostBack Then
    
                'Assign the value to static variable
                strSeleccted = RadioButtonList1.SelectedValue
            End If
        End Sub
    

    You can access the variable like below

     <System.Web.Script.Services.ScriptMethod>
        <System.Web.Services.WebMethod(EnableSession:=True)>
        Public Shared Function YourMethodName() As String
            'Access the shared variable inside method
            Dim selectedValue As String = strSeleccted
        End Function

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 7, 2017 9:14 PM
  • User-196219249 posted

    Great! That will work!

    Thanks!

    Tuesday, August 8, 2017 3:46 PM