0

I have a formview attached to a gridview so that when I click select on a record on my gridview, the record populates in the gridview. Now I want to open the formview in a lightbox, but I am running into trouble.

here is my javascript class:

    $('.lightbox').click(function () {
            $('.backdrop, .box').animate({ 'opacity': '.50' }, 300, 'linear');
            $('.box').animate({ 'opacity': '1.00' }, 300, 'linear');
            $('.backdrop, .box').css('display', 'block');
        });

here is my HTML:

    <asp:TemplateField HeaderText="Select">
    <ItemTemplate>
    <asp:LinkButton ID="LinkButton3" CommandArgument='<%# Eval("num") %>' CommandName="Select" runat="server" Text="Select" /> 
    </ItemTemplate>
    </asp:TemplateField>

How to add the javascript class "lightbox" to the linkbutton?

1 Answer 1

1

ASP.NET controls have a CssClass property you can write to, which translates into a class HTML attribute.

<asp:LinkButton ID="LinkButton3" ... CssClass="lightbox" />
Sign up to request clarification or add additional context in comments.

2 Comments

This works! But now the lightbox appears and closes immediately by the postback necessary to populate the formview. is there a way around the postback issue?
Keep in mind what a LinkButton is. Its purpose is to do a postback. You can kill the postback by adding a return false; to the end of your click handler, but doing that will stop the server code from executing. Lightboxes generally are accomplished using straight javascript, so you should probably look for a pure javascript solution, and make a manual AJAX call if necessary to retrieve the data needed for the lightbox.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.