如何在asp.net中使用webmethod [英] how to use webmethod in asp.net

查看:112
本文介绍了如何在asp.net中使用webmethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络表单上有一个用户控件,如下所示:

http://s8.postimg.org/dmcydrv3p/sample.png [ ^ ]



我选择程序年份,类别类别,类别和位置组然后单击搜索,它应该返回一个集合其中包含下拉列表中相应所选项的programyearID,categorytypeID和positionGroupID,并将其传递给已定义为获取特定认证ID的web方法。



接口

I have a user control on my web form which is as follows in the following link..
http://s8.postimg.org/dmcydrv3p/sample.png[^]

I select the program year, category type , category and position group and then click search, it should return a collection which contains the programyearID, categorytypeID and positionGroupID for the corresponding selected items in the dropdownlist and pass it on to a webmethod which is already defined to get a specific certificationID.

Interface

Namespace SI.Certification.UserControl

Public Interface IUserSearchResultList
Property DataSource() As User.Learning.Business.HR.UserCollection
ReadOnly Property List() As User.Web.UI.WebControls.PagedRepeater
End Interface 
End Namespace





这是我的usercontrol1.vb的代码





here is this the code for my usercontrol1.vb

Public Class curriculum_search
    Inherits System.Web.UI.UserControl
    Implements IUserSearchResultList

  Private _dataSource As UserCollection

  Public Property DataSource As UserCollection Implements UserControl.IUserSearchResultList.DataSource
        Get
            Return _dataSource
        End Get
        Set(value As UserCollection)

        End Set
    End Property

    Public ReadOnly Property List As PagedRepeater Implements UserControl.IUserSearchResultList.List
        Get
            Return ctlListControl
        End Get
    End Property

 #Region  "Public Properties"
 Public Property ProgramYearID() As Int32
        Get
            If Me.ShowProgramYearSearch Then
                If Me.lstProgramYear.SelectedValue = 0 Then
                    Return Integer.MinValue
                Else
                    Return Me.lstProgramYear.SelectedValue
                End If
            Else
                If ViewState("ProgramYearID") Is Nothing Then
                    Return Integer.MinValue
                Else
                    Return ViewState("ProgramYearID")
                End If
            End If
        End Get
        Set(ByVal Value As Int32)
            If Me.ShowProgramYearSearch Then
                Me.lstProgramYear.SelectedValue = Value.ToString()
            End If
            ViewState("ProgramYearID") = Value
        End Set
    End Property

 Public ReadOnly Property CategoryTypeID() As Int32
        Get
            If Me.lstCategoryType.SelectedValue = 0 Then
                Return Integer.MinValue
            Else
                Return Me.lstCategoryType.SelectedValue
            End If
        End Get
    End Property

 Public ReadOnly Property CategoryID() As Int32
        Get
            If Me.lstCategory.SelectedValue = 0 Then
                Return Integer.MinValue
            Else
                Return Me.lstCategory.SelectedValue
            End If
        End Get
    End Property

 Public Property PositionGroupID() As Int32
        Get
            If Me.ShowPositionCodeSearch Then
                If Me.lstPositionGroup.Selected = -1 Then
                    Return Integer.MinValue
                Else
                    Return Me.lstPositionGroup.Selected
                End If
            Else
                If ViewState("PositionGroupID") Is Nothing Then
                    Return Integer.MinValue
                Else
                    Return ViewState("PositionGroupID")
                End If
            End If
        End Get
        Set(ByVal Value As Int32)
            If Me.ShowPositionCodeSearch Then
                Me.lstPositionGroup.Selected = Value.ToString()
            End If
            ViewState("PositionGroupID") = Value

        End Set
    End Property

Public Property ShowPositionCodeSearch() As Boolean
        Get
            If ViewState("ShowPositionCodeSearch") Is Nothing Then
                Return True
            Else
                Return ViewState("ShowPositionCodeSearch")
            End If
        End Get
        Set(ByVal Value As Boolean)
            ViewState("ShowPositionCodeSearch") = Value
            If Not Value Then
                spnPositionGroup.Visible = False
            Else
                spnPositionGroup.Visible = True
            End If
        End Set
    End Property

 Public Property ShowProgramYearSearch() As Boolean
        Get
            If ViewState("ShowProgramYearSearch") Is Nothing Then
                Return True
            Else
                Return ViewState("ShowProgramYearSearch")
            End If
        End Get
        Set(ByVal Value As Boolean)
            ViewState("ShowProgramYearSearch") = Value
            If Not Value Then
                spnProgramYear.Visible = False
            End If
        End Set
    End Property
   #End Region

   #Region "Events"
    Public Event Submit(ByVal sender As Object, ByVal e As System.EventArgs)
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load

        If Page.IsPostBack = False Then
            If spnCategoryType.Visible = True Then
                BindCertificationCategoryTypeCollection()
            'method to bind the category collection
            End If
            If spnProgramYear.Visible = True AndAlso Me.ShowProgramYearSearch Then
                BindProgramYearCollection(GetProgramYearCollection())
            'method to bind the porgram year collection
            End If
            If spnPositionGroup.Visible = True AndAlso Me.ShowPositionCodeSearch Then
            End If
            lstPositionGroup.DefaultToPrimary = False
        End If
    End Sub

    Public Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlSearch.SearchClick
        RaiseEvent Submit(sender, e)
    End Sub





这是我必须使用的web方法我的usercontrol传递参数





This is the webmethod I have to use in my usercontrol to pass the parameters

_ Public Function GetCertificationLevelsList(ByVal programYearId As Integer, ByVal PositionGroupId As String, ByVal CategoryId As String) As User.Department.Application.Curriculum.Items Dim items As User.Department.Application.Curriculum.Items = User.Department.Application.Curriculum.CategoryCollection.GetCategoryLevelsList(programYearId, PositionGroupId, CategoryId) items.Sort() Return items End Function





我被困在这里,请继续进行帮助。谢谢



I am stuck here, pls help to proceed further. Thanks

推荐答案

在方法名称上面添加[WebMethod]

使用system.web.services名称空间添加
add [WebMethod] above method name
add using system.web.services name space


除了使用[WebMehtod]属性外,还将该方法标记为静态。
Apart from using the [WebMehtod] attribute mark the method as static.


这篇关于如何在asp.net中使用webmethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆