0

So I have a table that has a linkbutton at the top of each column header. The linkbutton sorts the table by using commandname="sort". When I click one of these buttons the page does a post back with the desired results. However, if I click on a link in the page that opens a jquery colorbox, instead of activating the javascript it redirects to a blank pages.

 $(document).ready(function () {
    $('.ManageImages').colorbox({ inline: true, innerwidth: 504, innerheight: 530, href: "#create-image-manager-dialog", escKey: false, overlayClose: false, onCleanup: function(){
        postbackWithModal();
    }});        
});
...
...
...
<th><asp:LinkButton runat="server" CommandName="Sort" CommandArgument="ItemNumber" CssClass="table-link-sorter">SKU</asp:LinkButton></th>
...
...
...
<asp:LinkButton CssClass="ManageImages" ID="ManageImages" runat="server" OnClientClick="SetImageSKU(this);" Text="Image Management" PostBackUrl="#" />

If I click on the linkbutton with the postbackurl of #, it redirects me to a blank page instead of calling the jquery I have in the supplied javascript. Anyone know of a work around for this?

yaegerbomb
  • 1,154
  • 4
  • 22
  • 37
  • My guess is that the linkbutton doing the sort is doing a partial post back? This would cause the page to not call the supplied ready functions? But this is a huge guess and I don't know enough about asp to answer this myself. – yaegerbomb Apr 26 '12 at 14:46

2 Answers2

1

Try below code. If you only want to run javascript.

<asp:LinkButton Text="Image Management" runat="server" PostBackUrl="javascript:void(0)" OnClientClick="SetImageSKU(this);" CssClass="ManageImages" ID="ManageImages" CausesValidation="false"/>

that should do it. If you want to run javascript and code behind then change it to OnClientClick="return SetImageSKU(this);" and send true or false from SetImageSKU so when it will return true, Link button will cause postback.

hope it helps.

Kamran Pervaiz
  • 1,861
  • 4
  • 22
  • 42
  • This doesn't cause the page to redirect but it also doesn't cause the colorbox to open up. It just kind of sits there. Thanks for the suggestion though. – yaegerbomb Apr 26 '12 at 15:44
  • try adding an alert box in the SetImageSKU and see if it runs the javascript at all or not? – Kamran Pervaiz Apr 26 '12 at 15:48
  • Yes the SetImageSKU does run. What I just did was took out that colorbox code in the ready function and put it int he setimagesku function. That way at the end of the setimagesku function the colorbox pops up. Thanks for putting me in the right direction! – yaegerbomb Apr 26 '12 at 16:09
0

Just guessing...change to: OnClientClick="SetImageSKU(this);return false;" Also wonder if the Postback url is even needed.

Much better would be to do this with an HTML anchor which will keep asp from writing code for you.

KennyZ
  • 907
  • 5
  • 11
  • Gave this a go but had no luck. I tried changing the onclicksettings. Then removing the postbackurl. Just causes a postback on the page without it doing anything. Thanks for the suggestion though. – yaegerbomb Apr 26 '12 at 15:46