asp.net - 调用函数背后的代码并传递参数
问题描述
我有 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.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
推荐阅读
- c - int* 值不持有任何值
- python - 下面的2段代码有什么区别
- visual-studio-code - 下载的 Javascript:Vscode 无法识别 'let' 和 'const'
- java - 如何获取节点机器的平台名称和浏览器名称 - selenium grid - Java
- c# - 将业务逻辑与控制器的依赖关系解耦的正确方法
- reactjs - React Router v6.0.0-beta0 - 使用 TransitionGroup 和 CSSTransition 动画路由转换
- reactjs -
with changed path not working - actions-on-google - 使用 Webhook Fulfillment 的 Google Actions 错误:查询代理端点时出错
- visual-studio-code - 在 VS Code 中重复最喜欢的建议
- python - 如何在计算过程中(或之前)停止超操作?- Python