-1

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... :-)

AakashM
  • 62,551
  • 17
  • 151
  • 186
Chains
  • 12,541
  • 8
  • 45
  • 62
  • are there any other controls on the page which should be doing something? – Tim B James Aug 30 '11 at 17:49
  • Try deleting all the project and files on production and re-publishing it – rlb.usa Aug 30 '11 at 17:51
  • Also, check and see if the files on your production server are actually the new, changed files, or if they are still the old files. – rlb.usa Aug 30 '11 at 17:52
  • Missing an OnClick event handler. – James Johnson Aug 30 '11 at 17:58
  • @James -- actually, no -- the code-behind uses the 'Handles' clause. Anyway, I tried doing it through mark-up as well (with an explicit call to onclick=), but still no joy. – Chains Aug 30 '11 at 18:14
  • @rlb.usa -- thanks for the ideas -- tried them all, but still nothing. – Chains Aug 30 '11 at 18:15
  • @Tim -- yes -- there are other controls. I've got req. validators, for one, which I will try removing to see if that could be the cause. BTW -- the req. validators are not firing (which is good) because I have the required fields filled-in. Otherwise, I've got other controls (checkboxes, etc.) which cause postbacks, still working. – Chains Aug 30 '11 at 18:19

4 Answers4

1

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.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
1

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.

EsemUK
  • 11
  • 1
0

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>
KhanZeeshan
  • 1,410
  • 5
  • 23
  • 36
0

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.

Chains
  • 12,541
  • 8
  • 45
  • 62