【问题标题】:How to check if button was click in page load如何检查按钮是否在页面加载中单击
【发布时间】:2012-11-25 18:00:33
【问题描述】:

我有一个按钮,我不想在我的页面加载中导致这个 if 命令。

If Page.IsPostBack Then
        ViewState(2) = TreeView1.SelectedNode.ValuePath
        ViewState(5) = TextBox1.Text
       ''Where I would like to put another if command or whatever else is possible to check if the buttong was clicked''
        If ViewState(2) = ViewState(1) And ViewState(5) = ViewState(4) Then
            nodecount = ViewState(3)
            nodecount = nodecount + 1
            ViewState(3) = nodecount
            If nodecount > 0 Then
                MsgBox("Please select another option or different number of data points")

            End If

        Else
            nodecount = 0
            ViewState(3) = nodecount
        End If
    End If

我尝试设置一个公共属性以更改如果单击按钮但 page.ispostback 先被调用然后子调用。

【问题讨论】:

  • 不是真的加上没有回答的事实。
  • 来自 Kratz 的上述链接中的第一个答案确实有效 - 只需在 If Page.IsPostBack 中调用 getPostBackControlID 函数,然后将输出与按钮的 id 进行比较。

标签: asp.net vb.net events button


【解决方案1】:

我不确定我是否完全理解您的问题。如果您尝试运行一段代码,为什么不在 btnSomeButton.Click 事件中执行,为什么在 Page_Load 事件中执行。

【讨论】:

  • 我认为他的问题是相反的,他在 PageLoad 中有代码,如果单击按钮,他不想运行。
  • 是的,因此视图状态
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-10
  • 1970-01-01
  • 2017-04-30
相关资源
最近更新 更多