English 中文(简体)
如何将物体从一个子到另一个子
原标题:How do i get the object from one sub to the other sub
  • 时间:2012-01-13 03:12:49
  •  标签:
  • vb.net

What i am trying to do is to get the intGuestID1 from page_load to be used in bth_add area Because i am trying to get the ID when it has been clicked from another form to frmAddFollowUp so i tried to request it from the page_load as when i request from the add button, it only gives me the number 0 instead of the id from the previous form.

Partial Class frmAddFollowUp
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles   Me.Load

    Dim objCDBFeedback As New CDBFeedback
    Dim objCDBDepartment As New CDBDepartment

    Dim intGuestID1 As Integer
    Dim arrList As New ArrayList





    If Page.IsPostBack = False Then
        intGuestID1 = Request.QueryString("id")

        arrList = objCDBDepartment.getAllDepartmentDropDownList
        lstDepartment.DataSource = arrList
        lstDepartment.DataTextField = "DepartmentName"
        lstDepartment.DataValueField = "Department"
        lstDepartment.DataBind()



    End If

End Sub

Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    Dim CheckBoolean As Boolean = True
    Dim objCDBFeedback As New CDBFeedback
    Dim objCFeedback As New CFeedback

    If txtStaffName.Text = "" Then
        lblValidateStaffName.Text = "*Please enter Staff Name."
        CheckBoolean = False
    Else

        lblValidateStaffName.Text = ""
    End If

    If txtFollowUpSummary.Text = "" Then
        lblValidateFollowUpSummary.Text = "*Please enter Follow up summary."
        CheckBoolean = False
    ElseIf txtFollowUpSummary.Text.Contains(" ") Then
        txtFollowUpSummary.Text = txtFollowUpSummary.Text.Replace(" ", "  ")
    Else
        lblValidateFollowUpSummary.Text = ""
    End If

    If txtAmount2.Text = "" Then
        lblValidateAmount2.Text = "*Please enter the Amount or put in NIL if there is no amount."
        CheckBoolean = False
    Else
        lblValidateAmount2.Text = ""
    End If

    If CheckBoolean = False Then

        If txtStaffName.Text.Contains("  ") Then
            txtStaffName.Text = txtStaffName.Text.Replace("  ", " ")
        End If
        If txtFollowUpSummary.Text.Contains("  ") Then
            txtFollowUpSummary.Text = txtFollowUpSummary.Text.Replace("  ", " ")
        End If

    Else
        Dim intNumOfRecordsAffected As Integer
        objCFeedback.GuestId = intGuestID1
        objCFeedback.Feedback = txtFollowUpSummary.Text
        objCFeedback.Department = lstDepartment.SelectedItem.Value
        objCFeedback.StaffName = txtStaffName.Text

        objCFeedback.Amount = txtAmount2.Text

        intNumOfRecordsAffected = objCDBFeedback.addNewFollowUp(objCFeedback)
        Response.Redirect("frmIncident.aspx")
    End If

End Sub
问题回答

You may either specify ByRef parameter type or use Function that returns reference of an object. In your code-snippet, you may declare variable at class-level (fields) so you may use them in different event handlers/sub.

in ID1是一个私人成员变量。 这将使你能够利用这两项职能中的这一变量。

该法典是否编纂? 我看不到在BtnAdd_Click中宣布的GuestID1号,这应当犯错。

2. 宣布私人成员变数后加上以下文字:

Partial Class frmAddFollowUp 
Inherits System.Web.UI.Page 

Private _intGuestID1 as Integer   The _ prefix is just a naming convention that is used for class member variables, if you don t like it, you can remove it. 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles   Me.Load 

页: 1 Load方法,去除Dim intGuestID1 ,因为你不再需要宣布这一点。 最后,在座任何地方,见于tGuestID1, 改称_intGuestID1。

此外,可能重新证明这一点的一些途径是,只产生一种可推崇以下事实的阅读财产:你从金库中重新获得。 见以下例子:

Private ReadOnly Property GuestID1() as Int32
Get
   Return Request.QueryString("id") 
End Get
End Property

这样做的好处之一是在使用之前对价值进行任何检查,例如,其实际数量在请求中储存。 学历(“id”),或者用户可以接触由这种补贴所代表的实体,或者你可以想到的。 当你这样做时,你就不得不改变对嘉宾ID1的所有提及。





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签