我有一个 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 运行该网站,仍然可以工作。但一旦我发布到我们的生产服务器,它就不再起作用了。
我被难住了——而且还在摆弄它。
如果有人经历过这种情况,请分享。已经研究这个问题几个小时了,但我没有想法。
谢谢你!
更新
- 一些人建议事件处理程序丢失。这实际上是由“Handles”子句在代码隐藏中处理的(
...Handles lb_new.Click
)。
- 手动删除生产文件夹中的项目,然后重新发布。没有喜悦。
- 验证生产文件夹中的文件是新文件。
- 我创建了一个全新的链接按钮——它也无法连接到它的代码隐藏,并且
- 我在标记中添加了 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
- 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
).
- Manually deleted the items in the production folder, then re-published. No joy.
- Verified the files in the production folder are the new ones.
- I created a brand new linkbutton -- it fails to connect to it's code-behind as well
- 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... :-)
发布评论
评论(4)
检查帖子上的 __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.
我遇到了同样的问题,这个帖子给我指出了答案(至少对我来说!)。只需将链接按钮的 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.
我认为你需要定义它的“点击”事件。
(已编辑)
对于 VB.NET:(来自 MSDN 的示例:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.onclick(v=VS.90).aspx)
I think you need to define its "Click" event.
(Edited)
For VB.NET: (Example From MSDN:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.onclick(v=VS.90).aspx)
验证控件正在阻止回发 - 或者至少,删除这些控件似乎已经解决了问题这对我来说没有意义,因为我在页面上有其他控件导致回发,并且它们仍然一直在工作。另外,我填写了正在验证的字段,因此(我能想到的)验证器没有理由阻止回发。不管怎样,感谢大家的想法。
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.