First off, I am still very new to Umbraco, but I was able to get quite a bit done so far, but I have run into a problem.
I am trying to use jquery to make ajax calls back to a method on a page. I was able to successfully get it to work outside of Umbraco. The problem is when I create a new content page in Umbraco, I need the ability to create a custom web method so that one of my controls can request the information I need using jquery. So basically, I need to be able to add to the codebehind of the content page. How can I do this? Also, same question for a master page.
If you create an asp.net Usercontrol and then create a Macro using that usercontrol, you can add the usercontrol to either a template or within a richtexteditor and therfor get access to the code behind of the usercontrol. If you go down the richteteditor route, you need to select a checkbos within the Macro to allow it to be used in the editor.
When you post back to a web method, you have to post back to the page. You cannot post back to the user control. Does the way you mention allow you to add a method to the code behind of the page?
I am not sure I followed what you said. When I add the macro to the richtexteditor, it says that it cannot be rendered because it contains script. If I go into html edit mode, it just has the text saying that it cannot be rendered because it contains script. Btw, my usercontrol does have javascript in it. Am I following the steps you mentioned correctly?
I don't think we're getting closer. Have read your two posts and still a bit confused what you're trying to achieve. You said, you've got it working outside umbraco. Care to share that? It would be much easier for us people to help you with something that is more practical. (If you can't show the code because of... whatever) then just get us some fake code that shows how/where/what's used for.
So basically, PopulateFriends is a javascript function that is called by a button click. This makes a call into CallCurrentPageMethod which a function that gets the current page and then calls CallPageMethod. The WebMethod GetFriends gets called and the html code is returned to the client without a full postback. The problem is that with Umbraco creating my pages, I cannot figure out how to write the WebMethod GetFriends located in the default.aspx. I have other options such as posting back to a page I did create instead of trying to post back to the current page I am on, but I prefer to post back to the current page I am on. Is it possible to do this with Umbraco?
I don't know if that would work in Umbraco, or how you'd do it. One question would be whether you could put the WebMethod in a usercontrol rather than a web page, and if so, that would probably work.
Alternatively, you put the Webmethod in another aspx page, or maybe an asmx page and call it bypassing Umbraco. To do this, you need to add the address of the page to umbracoreservedurls in your web.config file
I've successfully used jQuery to make AJAX calls to "hidden" pages in Umbraco. With hidden pages I mean pages in Umbraco that are not visible in any navigation and are not ment to be viewed as standalone pages by the user - the are just used to serve other pages with snippets of content. The template of these pages is basically just a macro/XSLT-script that fetches the data from Umbraco that I want to use and makes the necessary formatting.
...on the main page you'll see a series of small orange icons followed by headlines (in Swedish). "Bostäder" means "Housing". Click on that headline and you'll see a long row of images of houses appear. All the images and the text below them is loaded from Umbraco using AJAX. Then I use an early prototype of a scrolling script that I've made to make the row of images scrollable (Smooth Div Scroll).
The hidden page that delivers the content for the housing category can be found here:
If you look at the source of that page you'll see that there's no head or body tag or something like that, just a long HTML code snippet. In this example I wanted to receive the data in HTML-format, but I guess you could make the XSLT-script return any type of data - XML, plain text and I even think you could make it return data in Json format if you wanted.
This solution works! The only drawback is that you get pages that are not really pages. They serve more as data providers for other pages. In most cases, this is fine though.
However using Base is another option (http://umbraco.org/documentation/books/introduction-to-base). Base was written by Per a few years ago and is used in this forum (I think) for all processing of the ajax calls server side.
Content codebehind editing
First off, I am still very new to Umbraco, but I was able to get quite a bit done so far, but I have run into a problem.
I am trying to use jquery to make ajax calls back to a method on a page. I was able to successfully get it to work outside of Umbraco. The problem is when I create a new content page in Umbraco, I need the ability to create a custom web method so that one of my controls can request the information I need using jquery. So basically, I need to be able to add to the codebehind of the content page. How can I do this? Also, same question for a master page.
If you create an asp.net Usercontrol and then create a Macro using that usercontrol, you can add the usercontrol to either a template or within a richtexteditor and therfor get access to the code behind of the usercontrol. If you go down the richteteditor route, you need to select a checkbos within the Macro to allow it to be used in the editor.
HTH
Tom
When you post back to a web method, you have to post back to the page. You cannot post back to the user control. Does the way you mention allow you to add a method to the code behind of the page?
I am not sure I followed what you said. When I add the macro to the richtexteditor, it says that it cannot be rendered because it contains script. If I go into html edit mode, it just has the text saying that it cannot be rendered because it contains script. Btw, my usercontrol does have javascript in it. Am I following the steps you mentioned correctly?
Jonathan,
I don't think we're getting closer. Have read your two posts and still a bit confused what you're trying to achieve. You said, you've got it working outside umbraco. Care to share that? It would be much easier for us people to help you with something that is more practical. (If you can't show the code because of... whatever) then just get us some fake code that shows how/where/what's used for.
Looking forward to your examples.
Cheers,
/Dirk
OK sure. So there is several components. The first is the default.aspx page
Note the [WebMethod()] in the default.aspx.cs page
The second part is the javascript side of it.
and
So basically, PopulateFriends is a javascript function that is called by a button click. This makes a call into CallCurrentPageMethod which a function that gets the current page and then calls CallPageMethod. The WebMethod GetFriends gets called and the html code is returned to the client without a full postback. The problem is that with Umbraco creating my pages, I cannot figure out how to write the WebMethod GetFriends located in the default.aspx. I have other options such as posting back to a page I did create instead of trying to post back to the current page I am on, but I prefer to post back to the current page I am on. Is it possible to do this with Umbraco?
Sorry about that post. That is not how it looked in the editor. Regretfully there is no edit button to change it.
Jonathan,
I don't know if that would work in Umbraco, or how you'd do it. One question would be whether you could put the WebMethod in a usercontrol rather than a web page, and if so, that would probably work.
Alternatively, you put the Webmethod in another aspx page, or maybe an asmx page and call it bypassing Umbraco. To do this, you need to add the address of the page to umbracoreservedurls in your web.config file
HTH
Tom
Hi Jonathan!
I've successfully used jQuery to make AJAX calls to "hidden" pages in Umbraco. With hidden pages I mean pages in Umbraco that are not visible in any navigation and are not ment to be viewed as standalone pages by the user - the are just used to serve other pages with snippets of content. The template of these pages is basically just a macro/XSLT-script that fetches the data from Umbraco that I want to use and makes the necessary formatting.
If you go to this page:
http://www.arosarkitekter.se/sv/arkitektur
...on the main page you'll see a series of small orange icons followed by headlines (in Swedish). "Bostäder" means "Housing". Click on that headline and you'll see a long row of images of houses appear. All the images and the text below them is loaded from Umbraco using AJAX. Then I use an early prototype of a scrolling script that I've made to make the row of images scrollable (Smooth Div Scroll).
The hidden page that delivers the content for the housing category can be found here:
http://www.arosarkitekter.se/sv/arkitektur/bostader
If you look at the source of that page you'll see that there's no head or body tag or something like that, just a long HTML code snippet. In this example I wanted to receive the data in HTML-format, but I guess you could make the XSLT-script return any type of data - XML, plain text and I even think you could make it return data in Json format if you wanted.
This solution works! The only drawback is that you get pages that are not really pages. They serve more as data providers for other pages. In most cases, this is fine though.
/Thomas Kahn
I usually go with Thomas' approach.
However using Base is another option (http://umbraco.org/documentation/books/introduction-to-base). Base was written by Per a few years ago and is used in this forum (I think) for all processing of the ajax calls server side.
Cheers,
Chris
also meant to say....
Using MS Ajax stuff usually makes for heavy weight pages and is generally a bit ugly.
Have a look at the widgetframework (http://our.umbraco.org/projects/widgetframework) package for full examples on using jQuery with Umbraco.
is working on a reply...