讓我們說你有靜態方法,您想要訪問下拉列表中選擇的值文本框值和一些其他控件值..我的問題是,我總是第一次選擇下拉列表即使我選擇在下拉菜單中的任何值訪問控制值在靜態或asp.net中的共享方法
我做了什麼我創建下拉列表的屬性,則獲得的Page_Load事件的值,那麼這個值傳遞到靜態方法
Partial Public Class stocklist
Inherits System.Web.UI.Page
'Static or shared Property'
Private Shared _make As DropDownList
Public Shared Property MAKE() As DropDownList
Get
Return _make
End Get
Set(ByVal value As DropDownList)
_make = value
End Set
End Property
'Page Load'
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'ddlMake is the dropdownlist and MAKE is a Property'
MAKE = ddlMake
End Sub
'Static or shared Web Method'
<WebMethod()> _
Public Shared Function Select_Search() As SearchParameters()
Dim JSON As New List(Of SearchParameters)()
Dim dtst As New DataTable()
Dim myList As New dsStockTableAdapters.newSTOCK_LISTTableAdapter()
dtst = myList.GetData(MAKE.SelectedValue, "0", "0", "0", "0", DisplayType, "", "", "", "Any", "", "", "", "", "", 0, "", "", 0, "")
Try
For Each rdr As DataRow In dtst.Rows
Dim SRCH As New SearchParameters()
SRCH.CHASSIS_NO = rdr("CHASSIS_NO").ToString()
SRCH.MODEL = rdr("MODEL").ToString()
SRCH.color = rdr("color").ToString()
SRCH.TRANSMISSION = rdr("TRANSMISSION").ToString()
SRCH.DOOR = rdr("DOOR").ToString()
SRCH.MAKE = rdr("MAKE").ToString()
SRCH.Image1 = rdr("Image1").ToString()
SRCH.MODEL_DESCRIPTION = rdr("MODEL_DESCRIPTION").ToString()
JSON.Add(SRCH)
Next
Catch
Finally
End Try
Return JSON.ToArray()
End Function
End Class
現在「做」屬性的值總是顯示第一個被選中的值爲0的感染,我在dropdownlist中選擇了另一個值,但它總是顯示在調試時第一個值爲「0」。
如何在靜態方法中訪問dropdownlist的選定值???
喜@karl安德森我知道如何通過Ajax的參數值,但我需要做的是在codebhind ..我剛纔問到我是用點問題共享方法是我現在更新 –
很長@SiddiqBaig - 更新的答案包括使用'Session'緩存通過服務器端代碼存儲選定值的備選方案。 –