0

I have a Jquery dialog box in my website. This dialog box is meant for getting user comments. At present, I'm using the following code to execute the Javascript function and is working fine:

**<a href="#dialog" name="modal">Rate this</a>**

<div id="dialog" class="window"></div>
<div id="mask"></div> 

The Javascript code which it calls as follows:

 $(document).ready(function() {

        //select all the a tag with name equal to modal

        $('a[name=modal]').click(function(e) {
            //Cancel the link behavior
            e.preventDefault();
            //Get the A tag
            var id = $(this).attr('href');

            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Set heigth and width to mask to fill up the whole screen
            $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

            //transition effect     
            $('#mask').fadeIn(1000);
            $('#mask').fadeTo("slow", 0.8);

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            //Set the popup window to center
            $(id).css('top', winH / 2 - $(id).height() / 2);
            $(id).css('left', winW / 2 - $(id).width() / 2);

            //transition effect
            $(id).fadeIn(2000);

        });

    });

    //if close button is clicked

    $("input[id$='btnClose']").click(function(e) {
                   e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
    });

Since href does not have server side click event, I need to call the javascript using the link button. I tried several ways but failed to get the actual result.

To Conclude I need to change this call **<a href="#dialog" name="modal">Rate this</a>** to a Link button so that I can trap the click event.

Ranjith
  • 1
  • 1
  • this should be working. even if it doesn't have a server side click event but you don't need server side manipulation. the dialog model is to be shown through jQuery at the client side. do you get any errors? – neebz May 01 '11 at 12:32
  • It is working perfectly fine. But I need to call this using Link Button in asp. In my website, only registered users are allowed to comment on a post. Using Href call, I cannot do that. I need a link button so that I can check whether the user is a registered user or not. – Ranjith May 01 '11 at 12:34
  • so you want to check at the server whether he/she is allowed to rate it, if yes then run the above code to show the model? correct? – neebz May 01 '11 at 12:37
  • Well, you are absolutely right. – Ranjith May 01 '11 at 12:39
  • By using a Link Button I can do that. If the user is not a registered member then he should be redirected to Login.aspx page. Using HREF, I cannot do that. – Ranjith May 01 '11 at 12:43

1 Answers1

0

You can do this using the RegisterStartupScript which allows you to run Javascript at the end of a server side call. An example can be found here > http://www.dotnetcurry.com/ShowArticle.aspx?ID=200

Saying that I would strongly recommend that you should try manipulating the link even before the user clicks i.e. when the Page is loading instead of converting the anchor tag into a Linkbutton.

When the page is loading, you should check at that time whether the requesting client is a registered user or not. If he is then show the same **<a href="#dialog" name="modal">Rate this</a>** and add the rating form inside the

<div id="dialog" class="window">//Rating stuff goes here</div>

In case you see that the user is not registered, then you can either the hide the link or change the modal div to show, you are not registered, please click here for registration.

Hope it make sense.

neebz
  • 11,465
  • 7
  • 47
  • 64
  • At present, I doing the same thing. At the time of Page Load it checks whether the user is Registered or not. If he is not registered then the HREF become disabled. – Ranjith May 01 '11 at 12:55
  • But I feel, If the user is not registered he should automatically forward to Login page. Thats why I'm insisting on Link button. – Ranjith May 01 '11 at 12:56
  • I am afraid that won't be possible as ASP.NET has to go to server side to see if the user is registered or not. And as you need to show up your dialog after that, you have to handle this whole procedure yourself. – neebz May 01 '11 at 12:58
  • Thank you nEEbz for your suggestions. I think your last advise is good. I will make the modal div to show, saying to register. – Ranjith May 01 '11 at 13:00