Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 按钮控制不点火_Asp.net_Vb.net - Fatal编程技术网

Asp.net 按钮控制不点火

Asp.net 按钮控制不点火,asp.net,vb.net,Asp.net,Vb.net,我的问题解释起来有点复杂,请耐心听我说。我有两个按钮控制。在页面加载中,我想知道是哪个按钮在页面加载中创建了回发。通过研究,我在下面找到了这个片段,它的工作原理与预期相符。下面是我在点击按钮时发生的事件场景 1. Click the button does a postback 2. Runs the function below and tell me the id of the button 3. Runs the clicked event handlers for th

我的问题解释起来有点复杂,请耐心听我说。我有两个按钮控制。在页面加载中,我想知道是哪个按钮在页面加载中创建了回发。通过研究,我在下面找到了这个片段,它的工作原理与预期相符。下面是我在点击按钮时发生的事件场景

   1. Click the button does a postback
   2. Runs the function below and tell me the id of the button
   3. Runs the clicked event handlers for that button

     Protected Sub btnCalc_Click(ByVal sender As Object, ByVal e As EventArgs) Handles  btnCalc.Click
          ' Do this
     End Sub
当我单击第二个按钮时,问题出现了,它执行步骤1和2,但从未执行步骤3。通过测试,我发现它只在单击第一个按钮时执行1、2和3。我不知道为什么会这样

     Function GetPostBackControlName() As String

      Dim control As Control = Nothing
      Dim ctrlname As String = Page.Request.Params("__EVENTTARGET")

    If ctrlname <> Nothing AndAlso ctrlname <> [String].Empty Then
        control = Page.FindControl(ctrlname)
    Else
        Dim ctrlStr As String = [String].Empty
        Dim c As Control = Nothing

        For Each ctl As String In Page.Request.Form

            c = Page.FindControl(ctl) 

           If TypeOf c Is System.Web.UI.WebControls.Button Then
                control = c
                Exit For
           End If

        Next

    End If

    Try
        Return control.ID.ToString
    Catch
        Return ""
    End Try

    End Function
函数GetPostBackControlName()作为字符串 变暗控制为控制=无 Dim ctrlname As String=Page.Request.Params(“事件目标”) 如果ctrlname为Nothing,并且ctrlname[String]。为空,则 控件=Page.FindControl(ctrlname) 其他的 Dim ctrlStr As String=[String]。空 尺寸c作为控制=无 对于Page.Request.Form中的每个ctl作为字符串 c=页面FindControl(ctl) 如果c的类型为System.Web.UI.WebControl.Button,则 控制=c 退出 如果结束 下一个 如果结束 尝试 返回控件.ID.ToString 抓住 返回“” 结束尝试 端函数
是否有任何理由不直接将按钮连接到事件处理程序,并使用
sender
参数获取单击的按钮?它到底是为了什么。。。至于为什么它不工作的问题,听起来好像如果2在工作,你得到了正确的ID,那么你的问题是第3步,你似乎没有向我们展示代码。是的b/c我有动态表,我不想每次回发都重建。这会减慢我的阅读速度。当我在调试器中单步执行ID时,它会找到该ID,但不会触发最后一次单击事件handler@Will如果您只想重新加载页面的一部分,请考虑VisualStudio附带的微软Ajax UpDeaPeNeL控件。您正在使用哪个版本的Visual Studio?您还应该回顾过去的问题,并根据需要将其标记为已回答。是否有任何理由不直接将按钮连接到事件处理程序,并使用
sender
参数来获取单击的按钮?它到底是为了什么。。。至于为什么它不工作的问题,听起来好像如果2在工作,你得到了正确的ID,那么你的问题是第3步,你似乎没有向我们展示代码。是的b/c我有动态表,我不想每次回发都重建。这会减慢我的阅读速度。当我在调试器中单步执行ID时,它会找到该ID,但不会触发最后一次单击事件handler@Will如果您只想重新加载页面的一部分,请考虑VisualStudio附带的微软Ajax UpDeaPeNeL控件。您正在使用哪个版本的Visual Studio?您还应该回顾您过去的问题,并根据情况将其标记为已回答。