【问题标题】:How to control dropdownlist auotpostback in asp.net?如何控制asp.net中的下拉列表自动回发?
【发布时间】:2016-06-23 19:34:42
【问题描述】:

我有一个带有自动回发和更新面板的下拉列表,它可以正常工作, 但我的页面中还有其他带有自动回发功能的控件。 我需要控制页面何时自动回发但下拉列表不是自动回发做一些事情,如下所示:

     If is not Page.autopostback then
    'do something

else if is not MyDropdownlist.autopostback then    
    ' do something different    
    End if

我可以用这个:

If is not Page.autopostback then
End If

但我不能这样做:

If is not MyDropdownlist.autopostback then
End If

那么我该怎么做呢?希望我的解释对您有所帮助,谢谢。

【问题讨论】:

  • 你能详细解释一下你想要达到的目标吗?
  • 对不起,我解释错了,我想做一些代码,但只有当页面是自动回发但下拉列表不是自动回发时
  • 可能您使用 Page.IsPostback 属性进行页面回发并检查下拉列表的选定值。不知道你为什么需要这样的东西。解释清楚的逻辑。

标签: asp.net vb.net dropdown ispostback


【解决方案1】:

__EVENTTARGET 请求表单变量具有导致回发发生的控件名称。你可以查询这个控件的名字,为所欲为。

例如,

If IsPostBack Then
    Dim postBackControlId As String = Request.Form("__EVENTTARGET")
    If Not String.IsNullOrEmpty(postBackControlId) Then
        If postBackControlId = "DropdownList1" Then
            ' the postback happened due to DropdownList1

        Else
            ' the postback happened due to some other control.

        End If
    End If
End If

【讨论】:

  • 非常感谢您的解释,它工作正常,正是我想要的:-D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多