asp:linkbutton not functioning in production
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 Str开发者_StackOverflow社区ing
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... :-)
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.
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.
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>
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.
精彩评论