首页 > 解决方案 > 调用函数背后的代码并传递参数

问题描述

我有 asp.net 文本框,我在其中通过 __postback 调用函数背后的代码,但我也想传递正在调用 __postback 函数的文本框的文本。这是我的文本框。

       <asp:TextBox Width="400px" ID="txtExtraRooms" MaxLength="3" 
        onkeypress="__doPostBack(this.name,'OnKeyPress');" runat="server" 
       Visible="false"></asp:TextBox>

我的代码在我想输入 id="txtExtraRooms" 的文本框的文本后面

      Dim ctrlName As String = Request.Params(Page.postEventSourceID)
      Dim args As String = Request.Params(Page.postEventArgumentID)
     // here I want text of text box with id "txtExtraRooms"
    If ((ctrlName = txtExtraRooms.UniqueID) _
                AndAlso (args = "OnKeyPress")) Then
          TextBox2_OnKeyPress(ctrlName, args)
    End If

标签: asp.netvb.net

解决方案


在 asp.net 中,您可以在表单对象中检查 2 个主要字段,它们是 __EVENTTARGET:引发回发事件的控件

__EVENTARGUMENT:通过的参数

要阅读它们,您可以使用:

 Dim eventArgument As String = IIf(Me.Request("__EVENTARGUMENT") = Nothing, 
 String.Empty, Me.Request("__EVENTARGUMENT"))

有关更多详细信息,您可以查看 https://forums.asp.net/t/1252181.aspx?Retreiving+Argument+from+_doPostBack+in+VB


推荐阅读