1

Here I am calling the webmethod in a jquery... If I run this code in a normal aspx page then the webmethod gets fired.. But when I use master page and put this code in child page(Default4.aspx) then web method is not being fired. I have used the colorbox jquery plugin. Here When I click on any link a popup will open and display the file content My code is as below...

Default4.aspx

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link rel="stylesheet" href="example1/colorbox.css" type="text/css" />

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>

    <script src="jquery.colorbox.js" type="text/javascript"></script>

    <script type="text/javascript">
            $(document).ready(function(){

                //Examples of how to assign the ColorBox event to elements
                $(".group1").colorbox({rel:'group1'});
                $(".group2").colorbox({rel:'group2', transition:"fade"});
                $(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
                $(".group4").colorbox({rel:'group4', slideshow:true});
                $(".ajax").colorbox();
                $(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344});
                $(".vimeo").colorbox({iframe:true, innerWidth:500, innerHeight:409});

                $(".inline").colorbox({inline:true, width:"50%"});
                $(".callbacks").colorbox({
                    onOpen:function(){ alert('onOpen: colorbox is about to open'); },
                    onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
                    onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
                    onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
                    onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
                });

                $('.non-retina').colorbox({rel:'group5', transition:'none'})
                $('.retina').colorbox({rel:'group5', transition:'none', retinaImage:true, retinaUrl:true});

                //Example of preserving a JavaScript event for inline calls.
                $("#click").click(function(){ 

                    $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
                    return false;
                });


               $("[id$=LinkButton2]").click(function() {
              alert('child');
                $.ajax({
                  type: "POST",
                 url: "Default4.aspx/lnkbtn1",
                  data: "{}",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function(msg) {
                    alert(msg.d);
                    // Replace the div's content with the page method's return.
                    $("#[id$=LinkButton2]").attr('href',msg.d);

                  }
                });

             });
             $(".iframe").colorbox({iframe:true, width:"60%", height:"80%"});
            });
        </script>
    <style type="text/css">
        .arrowlistmenu
        {
            width: 180px; /*width of menu*/
        }
        .arrowlistmenu .headerbar
        {
            font: bold 14px Arial;
            color: white;
            background: black url(media/titlebar.png) repeat-x center left;
            margin-bottom: 10px; /*bottom spacing between header and rest of content*/
            text-transform: uppercase;
            padding: 4px 0 4px 10px; /*header text is indented 10px*/
        }
        .arrowlistmenu ul
        {
            list-style-type: none;
            margin: 0;
            padding: 0;
            margin-bottom: 8px; /*bottom spacing between each UL and rest of content*/
        }
        .arrowlistmenu ul li
        {
            padding-bottom: 2px; /*bottom spacing between menu items*/
        }
        .arrowlistmenu ul li a
        {
            color: #A70303;
            background: url(media/arrowbullet.png) no-repeat center left; /*custom bullet list image*/
            display: block;
            padding: 2px 0;
            padding-left: 19px; /*link text is indented 19px*/
            text-decoration: none;
            font-weight: bold;
            border-bottom: 1px solid #dadada;
            font-size: 90%;
        }
        .arrowlistmenu ul li a:visited
        {
            color: #A70303;
        }
        .arrowlistmenu ul li a:hover
        {
            /*hover state CSS*/
            color: #A70303;
            background-color: #F3F3F3;
        }
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 99%;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

 <div id="Result">
        Click here for the time.</div>

    <p>
        <a runat="server" id="a" class='iframe' href="Uploadedfiles/Education Portal.xlsx.1.html">
            Outside Webpage (Iframe)</a></p>
    <p>
        <a runat="server" id="a1" class='iframe' href="~/Images/Desert.jpg">Image
            (Iframe)</a></p>


        <asp:LinkButton ID="LinkButton2" runat="server"  CssClass="iframe"
       >LinkButton</asp:LinkButton>



</asp:Content>

.Cs

 [WebMethod]
    public static string lstbtn1()
    {

        return "Images/Desert.jpg";
    }
8
  • Kindly add the script files(jquery.min, colorbox) in master pages and make sure is not duplicate. Commented Mar 5, 2013 at 5:54
  • ya i have already added this files to my master page Commented Mar 5, 2013 at 5:56
  • you mean to say i have to add this script file in master page and not in default4.aspx (in my case)?? Commented Mar 5, 2013 at 6:01
  • @Babu....yes also make sure you dont have any duplicate js. Commented Mar 5, 2013 at 6:03
  • I have added webservice and the webmethod get fired now but the image is not displaying in the popupwindow Commented Mar 5, 2013 at 6:11

1 Answer 1

1
[WebMethod]
public static string lstbtn1()
{

    return "Images/Desert.jpg";
}

try like this

Sign up to request clarification or add additional context in comments.

Comments

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.