asp:linkbutton 在生产中不起作用

发布于 2024-12-02 07:12:24 字数 1243 浏览 0 评论 0 原文

我有一个 asp:linkbutton,如下所示:

<asp:LinkButton ID="lb_new" runat="server" ForeColor="White">New Item</asp:LinkButton>

Protected Sub lb_new_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lb_new.Click
    ViewState("ItemID") = "0"
    Dim myURL As String
    myURL = String.Format("D002.aspx?e={0}&i={1}", ViewState("EventID"), ViewState("ItemID"))
    Response.Redirect(myURL)
End Sub

直到最近,它都发挥了应有的作用。但由于某种原因,它已停止在生产中运行。据我所知,它根本没有连接到它的代码隐藏(我尝试修改它以简单地更改页面上一个文本框中的文本,但它也失败了)。如果我通过 Visual Studio 运行该网站,仍然可以工作。但一旦我发布到我们的生产服务器,它就不再起作用了。

我被难住了——而且还在摆弄它。

如果有人经历过这种情况,请分享。已经研究这个问题几个小时了,但我没有想法。

谢谢你!

更新

  1. 一些人建议事件处理程序丢失。这实际上是由“Handles”子句在代码隐藏中处理的(...Handles lb_new.Click)。
  2. 手动删除生产文件夹中的项目,然后重新发布。没有喜悦。
  3. 验证生产文件夹中的文件是新文件。
  4. 我创建了一个全新的链接按钮——它也无法连接到它的代码隐藏,并且
  5. 我在标记中添加了 Onclick= 。考虑到隐藏代码中的 Handles 子句,这应该不是必需的。不管怎样,点击仍然失败。

...仍在努力

UPDATE2

删除了页面上所需的字段验证器,并且它可以工作。这对我来说没有意义,因为我在页面上有其他控件导致回发,并且它们仍然一直有效。另外,我填写了正在验证的字段,因此(我能想到的)验证器没有理由阻止回发。

现在我只需要弄清楚如何在没有所需字段验证器的情况下在页面上进行验证。

...使困惑... :-)

I've got an asp:linkbutton as follows:

<asp:LinkButton ID="lb_new" runat="server" ForeColor="White">New Item</asp:LinkButton>

Protected Sub lb_new_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lb_new.Click
    ViewState("ItemID") = "0"
    Dim myURL As String
    myURL = String.Format("D002.aspx?e={0}&i={1}", ViewState("EventID"), ViewState("ItemID"))
    Response.Redirect(myURL)
End Sub

Up until recently, it has functioned as it should. But for some reason, it has stopped working in production. As far as I can tell, it's not connecting to it's code-behind at all (I tried modifying it to simply change the text in one of the text boxes ont he page, and it fails that as well). Still works if I run the website through visual studio. But as soon I publish to our production server, it no longer works.

I'm stumped -- and still fiddling with it.

If anyone has experienced this, please share. Have been on this for a couple hours now, and am out of ideas.

Thank you!

UPDATE

  1. The event handler has been suggested as missing by a couple of folks. This is actually handled in the code-behind by the 'Handles' clause (...Handles lb_new.Click).
  2. Manually deleted the items in the production folder, then re-published. No joy.
  3. Verified the files in the production folder are the new ones.
  4. I created a brand new linkbutton -- it fails to connect to it's code-behind as well
  5. I added an Onclick= to the mark-up. This shouldn't be necessary, considering the Handles clause in the code-behind. Regardless, the click still fails.

...still plugging away at it

UPDATE2

Removed the required field validators on the page, and it works. This does not make sense to me, because I had other controls on the page causing postbacks, and they still worked the whole time. Also, I had the fields that were being validated filled-in, so no reason (I can think of) that the validators would have been preventing the postback.

Now I just have to figure out how to do validation on the page without the required field validators.

...confused... :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深空失忆 2024-12-09 07:12:24

检查帖子上的 __EVENTTARGET 和 __EVENTARGUMENT 变量;这些应该与触发回发的按钮中的值匹配。这至少是第一个线索...

您是否升级了一些第三方 DLL 或从 .NET 3.5 升级到 .NET 4.0 或类似的东西?

HTH。

Check the __EVENTTARGET and __EVENTARGUMENT variables on the post; these should match the values from the button that triggered the postback. That's at least the first clue...

Did you upgrade some third party DLL or upgrade from .NET 3.5 to .NET 4.0 or something like tha too?

HTH.

差↓一点笑了 2024-12-09 07:12:24

我遇到了同样的问题,这个帖子给我指出了答案(至少对我来说!)。只需将链接按钮的 CausesValidation 属性设置为 false,单击事件就会忽略页面上任何验证器的状态而触发。我没有在点击事件或回发中执行任何需要任何验证的操作,因此我可以忽略它。如果您也是如此,那么这很可能是您的解决方案。

I was having this same problem and this thread pointed me to the answer (for me at least!). Just set the CausesValidation property of the linkbutton to false and the click event will fire ignoring the state of any validators on the page. I'm not doing anything in the click event or postback that requires any validation so it's fine for me to ignore it. If the same is true for you, this could well be your solution.

清风挽心 2024-12-09 07:12:24

我认为你需要定义它的“点击”事件。

<asp:LinkButton ID="lb_new" runat="server" ForeColor="White" OnClick="lb_new_Click">New Item</asp:LinkButton>

(已编辑)
对于 VB.NET:(来自 MSDN 的示例:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.onclick(v=VS.90).aspx)

<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>LinkButton Example</title>
<script language="VB" runat="server">

      Sub LinkButton_Click(sender As Object, e As EventArgs) 
         Label1.Text = "You clicked the link button"
      End Sub

   </script>

</head>
<body>

   <form id="form1" runat="server">

      <h3>LinkButton Example</h3>

      <asp:LinkButton id="LinkButton1" 
           Text="Click Me" 
           Font-Names="Verdana" 
           Font-Size="14pt" 
           OnClick="LinkButton_Click" 
           runat="server"/>

      <br />

      <asp:Label id="Label1" runat="server" />

   </form>

</body>
</html>

I think you need to define its "Click" event.

<asp:LinkButton ID="lb_new" runat="server" ForeColor="White" OnClick="lb_new_Click">New Item</asp:LinkButton>

(Edited)
For VB.NET: (Example From MSDN:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.onclick(v=VS.90).aspx)

<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>LinkButton Example</title>
<script language="VB" runat="server">

      Sub LinkButton_Click(sender As Object, e As EventArgs) 
         Label1.Text = "You clicked the link button"
      End Sub

   </script>

</head>
<body>

   <form id="form1" runat="server">

      <h3>LinkButton Example</h3>

      <asp:LinkButton id="LinkButton1" 
           Text="Click Me" 
           Font-Names="Verdana" 
           Font-Size="14pt" 
           OnClick="LinkButton_Click" 
           runat="server"/>

      <br />

      <asp:Label id="Label1" runat="server" />

   </form>

</body>
</html>
晨与橙与城 2024-12-09 07:12:24

验证控件正在阻止回发 - 或者至少,删除这些控件似乎已经解决了问题这对我来说没有意义,因为我在页面上有其他控件导致回发,并且它们仍然一直在工作。另外,我填写了正在验证的字段,因此(我能想到的)验证器没有理由阻止回发。不管怎样,感谢大家的想法。

Validation controls were preventing a postback -- or at least, removing those controls seems to have solved the problem This does not make sense to me, because I had other controls on the page causing postbacks, and they still worked the whole time. Also, I had the fields that were being validated filled-in, so no reason (I can think of) that the validators would have been preventing the postback. Anyway, thanks to everyone for all the ideas.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文