I have Asp.net Repeater (with checkboxes) within Jquery dialog. I wish to Bind repeater, everytime the Jquery dialog box is loaded.
In order to do so, I have a [webmethod], that would be called everytime dialog pop-up button be clicked.
However, since the webmethod is a static method, I cannot access Repeater. It thows an error:"an object reference is required for the nonstatic field,method or property."
Can someone suggest me how (and if possible) to pass the Repeater iteself as a parameter from Jquery side?
If you want to use repeater in your case, put the repeater is a separate aspx page and in the dialog container add an iframe and call the dialog like this-
That means everytime you reassign the iframe source to get a refresh.
Second:
You can add a update panel within the dialog container and have a hidden button with click event which rebinds the repeater. An on the click of the dialog oppner fire the click event of the button.
Third:
You should not use repeater when you are using static method for getting the data. You can build the data dynamically like below-
I tried the first method you suggested. Everything works great except that when I close dialog and re-open the dialog, the page (2nd page containing repeater) is never refreshed.
This worked was just PERFECT. Thanks for your help!!!
Although, I am now curious what difference does it make by adding iframe dynamically. In other words, why did it not behave the same way when the iframe was already defined within the div. I was, anyways, setting iframe src attribute at the time of opening
the dialog. ( I am really new to Jquery stuff )
If you assign a source to iframe. Then it caches the response. So, again if you reassign the same source then it just takes the previously cached response. Thats why for dynamic iframe its always a new iframe so retriving the data everytime.
Thanks & Regards
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
AnjumNagpal
Member
46 Points
60 Posts
Accessing asp.net method from Jquery.
Jan 29, 2012 11:56 PM|LINK
I have Asp.net Repeater (with checkboxes) within Jquery dialog. I wish to Bind repeater, everytime the Jquery dialog box is loaded.
In order to do so, I have a [webmethod], that would be called everytime dialog pop-up button be clicked.
However, since the webmethod is a static method, I cannot access Repeater. It thows an error:"an object reference is required for the nonstatic field,method or property."
Can someone suggest me how (and if possible) to pass the Repeater iteself as a parameter from Jquery side?
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Accessing asp.net method from Jquery.
Jan 30, 2012 05:15 AM|LINK
You cannot access ASP.Net controls in Static methods. Other solution is load your repeater using jQuery AJAX a similar example is here for GridView
http://www.aspsnippets.com/Articles/Bind-Dataset-to-ASPNet-GridView-using-jQuery-AJAX.aspx
Contact me
asteranup
All-Star
30184 Points
4906 Posts
Re: Accessing asp.net method from Jquery.
Jan 30, 2012 06:22 AM|LINK
hi,
You can try few things here-
First:
If you want to use repeater in your case, put the repeater is a separate aspx page and in the dialog container add an iframe and call the dialog like this-
http://forums.asp.net/p/1655362/4310704.aspx/1?Re+jquery+dialog
That means everytime you reassign the iframe source to get a refresh.
Second:
You can add a update panel within the dialog container and have a hidden button with click event which rebinds the repeater. An on the click of the dialog oppner fire the click event of the button.
Third:
You should not use repeater when you are using static method for getting the data. You can build the data dynamically like below-
http://forums.asp.net/p/1724719/4615531.aspx/1?Re+append+raw+html
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
AnjumNagpal
Member
46 Points
60 Posts
Re: Accessing asp.net method from Jquery.
Jan 31, 2012 08:55 PM|LINK
Thanks Anup Das Gupta ,
I tried the first method you suggested. Everything works great except that when I close dialog and re-open the dialog, the page (2nd page containing repeater) is never refreshed.
Here's my code:
$(document).ready(function() {
$( "#btnOpenDialog").live('click', function() {
$("#dialog").dialog({ modal: true, title: 'Dialog', width: 400, height: 700 });
$("#dialog").parent().appendTo('form');
$("#iFrame1").attr("src", "repeater.aspx");
return false ;
});
});
<div class="mcePaste" id="_mcePaste" style="position: absolute; width: 1px; height: 1px; overflow: hidden; top: 0px; left: -10000px;"></div>asteranup
All-Star
30184 Points
4906 Posts
Re: Accessing asp.net method from Jquery.
Feb 01, 2012 11:29 AM|LINK
Hi,
You can try this script-
<script type="text/javascript"> $(document).ready(function() { $("#anc").click(function() { $.fx.speeds._default = 1000; $("#divId").empty().append( $("<iframe>").attr({ "src": "http://www.google.com", "width": "100%", "height": "100%", "marginwidth": "0", "marginheight": "0", "scrolling": "auto", "title": "Dialog Title", "frameborder": "0" })); $("#divId").dialog({ show: "blind", hide: "explode", modal: true, height: 300, width: 700 }); return false; }); }); </script> <div id="divId" title="Dialog Title" style="width: 600px; height: 400px"> </div>Or you can simply add the url with some dummy querystring with some value as random.
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
AnjumNagpal
Member
46 Points
60 Posts
Re: Accessing asp.net method from Jquery.
Feb 01, 2012 04:21 PM|LINK
Anup,
This worked was just PERFECT. Thanks for your help!!!
Although, I am now curious what difference does it make by adding iframe dynamically. In other words, why did it not behave the same way when the iframe was already defined within the div. I was, anyways, setting iframe src attribute at the time of opening the dialog. ( I am really new to Jquery stuff )
asteranup
All-Star
30184 Points
4906 Posts
Re: Accessing asp.net method from Jquery.
Feb 01, 2012 04:55 PM|LINK
Hi,
If you assign a source to iframe. Then it caches the response. So, again if you reassign the same source then it just takes the previously cached response. Thats why for dynamic iframe its always a new iframe so retriving the data everytime.
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
AnjumNagpal
Member
46 Points
60 Posts
Re: Accessing asp.net method from Jquery.
Feb 02, 2012 05:37 PM|LINK
Thanks again.