Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I have gridview with link buttons on my page. If values are there linkbutton will be enable otherwise it will disable. If i click on link button, opening the values in jquery fancybox using javascript. My problem is if I click on disabled link button, even then also fancy box is opening with previous values. How can I over come this problem. Please help me...

Below is my Gridview code...

XML
 <ItemTemplate>                                                                    
<div style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: <asp:LinkButton  runat="server" CssClass="modalbox" ID="lnkEmailFailed" Text='<%#Bind("EmailSentFailed")%>'
 önClick='<%# String.Format("javascript:return fnUserDetailsPopup(\"0}\",\"1}\")",Eval("FileID"),"EmailFailed")%>'>
</asp:LinkButton>
</div>
</ItemTemplate>


Script:

C#
function fnUserDetailsPopup(id,type) {
    $('.modalbox').fancybox
    (
    {
        'padding': 4,
        'width': 600,
        'height': 300,
        'scrolling': 'no',
        'type': 'iframe',
        'href': '../PopUps/UserCreadtedDetails.aspx?BulkFileId=' + id + '&type=' + type
    }
    );
    return false;
}
Posted
Updated 30-May-13 2:11am
v2

1 solution

That happens because you have asked the popup to open everytime irrespective of the link is disabled or not.
To prevent this just add a check before opening the popup.
While calling pass the id/element to know which link button called it. And in the function, check if that link is disabled or not. I have not checked this code. It should work, but do use firebug and make adjustments if it doesn't work.
javascript:return fnUserDetailsPopup(\"0}\",\"1}\", this)",Eval("FileID"),"EmailFailed

JavaScript
function fnUserDetailsPopup(id,type,elem) {
    $('.modalbox').fancybox(
    {
      if($(elem).attr("disabled") != "disabled")
      {
        'padding': 4,
        'width': 600,
        'height': 300,
        'scrolling': 'no',
        'type': 'iframe',
        'href': '../PopUps/UserCreadtedDetails.aspx?BulkFileId=' + id + '&type=' + type
      }
    });
    return false;
}


Hope this helps!
 
Share this answer
 
Comments
NaVeN Kumar 31-May-13 0:58am    
Hello Ankur,

I tried as you suggested but even then also fancybox is opening.
Ankur\m/ 1-Jun-13 8:47am    
Use firebug (or similar tools) and debug the javascript. See why it is not opening.
NaVeN Kumar 31-May-13 1:14am    
I have disable link buttons in GridView if value is not present. When i click on disabled linkbutton script is also not firing.
Ankur\m/ 1-Jun-13 8:48am    
Are you using onClientClick event? That should still fire.
NaVeN Kumar 3-Jun-13 4:45am    
Yes I am using onclientclick event... Script is not firing as they were disabled.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900