How can I get carousel on page at Umbraco? - slider

I want to create a carousel, firstly I create a nested content then I added it on my homepage but when I called, it's not working.
#{
string carouselId = "mainCarousel";
IEnumerable<IPublishedContent> carousel = Model.Value<IEnumerable<IPublishedContent>>(carouselId); }
I got error like this object reference not set to an instance of an object. I tried many things but I failed to reach on solve. Btw I'm using v8.1.12.

I fixed this problem with this code;
var page = Umbraco.Content(Guid.Parse("eea1803b-f093-42f6-8483-b27df3323c2d"));
var carousel = page.Value<IEnumerable<IPublishedElement>>("mainCarousel");

Related

Set dataSource of ListView programmatically

I'm trying to update a windows 8 application from the Developer Preview to the Consumer Preview. It seems there's been a few changes. This code used to work:
var myDataSource = new WinJS.UI.ArrayDataSource(array)
var basicListView = WinJS.UI.getControl(document.getElementById("basicListView"));
basicListView.dataSource = myDataSource;
Now, there is no WinJS.UI.getControl method and no ArrayDataSource. This is my code:
var dataList = new WinJS.Binding.List(array);
var list = document.getElementById("basicListView");
list.itemDataSource = dataList.dataSource;
but it does nothing (except add a property to a DOM element that is ignored). Any ideas what I'm missing?
Got it. To get the control you now use the winControl property of the element:
var list = document.getElementById("basicListView").winControl;
Setting the itemDataSource works a treat.

Reload carousel items

I need to reload the items from my carousel (I clicked on an item and a panel gets destroyed, then when I try to go back, I need to rebuild the carousel)
For this I am removing the items of the carousel by doing:
var len = cards.length;
for(var c = 0; c < len;c++)
this.myCarousel[0].items.remove(cards[0]);
then I set the cards again and set the carousel items again:
this.myCarousel[0].items.append(cards);
this.doLayout();
but after doing this, the cards dont get set right, they just get written on top of each other, no carousel effect gets done. Also the cards start being drawn under the carousel's toolbar, instead of starting below the toolbar.
The first time when I load the cards it works perfectly (when I build the carousel from scratch), but if I delete the previous cards and add them again, they don't get displayed properly, I hope someone can help me.
Thank you in advance
Do the adding and removing on the carousel itself as it has methods to do this:
this.myCarousel.removeAll();
var items = [];
for (...) {
items.push(<item def>);
}
this.myCarousel.add(items);
this.carousel.doLayout(); // Force the carousel to re-render
this.myCarousel.scrollToCard(0); // This will send the user back to the first card
If the user was at a different card when you run the above (say, if you put this into an orientation check) then you should return them to the correct card like so:
var curIndex = this.myCarousel.items.items.indexOf(this.myCarousel.layout.activeItem);
// Now do removing and adding
this.myCarousel.scrollToCard(this.myCarousel.items.items[curIndex]);
You have to use the index as the item will be removed.
id should only be used for debugging. There are better ways to resolve a component than use id that can get you into trouble.

Problems with adding/removing ContentPanes in AccordionContainer

I'm a complete newbie at Dojo, and Adobe AIR, which is my target. I'm
trying to put some panes into an AccordionContainer like so:
var mainview = dijit.byId("mainview");
var rand = randomString();
var widg = gtd_create_entry_widget(rand)
air.trace(mainview);
air.trace(widg);
mainview.addChild(widg);
"mainview" is my AccordionContainer, and gtd_create_entry_widget() is:
function gtd_create_entry_widget(id) {
var entry = new dijit.layout.ContentPane();
entry.attr("id",id);
entry.attr("title","title "+id);
return entry;
}
The pane shows up in the container, with the correct id and title, and
no errors, however, if I try to add another pane, the next one shows
up too, but I get the error:
TypeError: Result of expression '_7' [undefined] is not an object.
I get the same error if I run
var mainview = dijit.byId("mainview");
mainview.destroyDescendants();
and also, only one pane is destroyed at a time, and I understand this
method should destroy all the children.
I can include full project code if required.
Thanks a lot
Garry
I'm not exactly sure if this is going to fix your problem, but you're supposed to use dijit.layout.AccordianPane (http://www.dojotoolkit.org/api/dijit/layout/AccordionPane.html) with the AccordianContainer.

dojox flvideo widget destroy in AJAX

When using dojox.av.FLVideo widget, I have encountered a problem where I can't destroy the widget manually. In simple logic:
1st AJAX call
[Retrieves a partial page A with video]
var videoDiv = document.createElement('div');
videoDiv.id = "vid";
mainContent.appendChild(videoDiv);
var newVideo = new dojox.av.FLVideo({initialVolume:.7, mediaUrl:'video/sample.flv', autoPlay:true, isDebug:true}, "vid");
//video plays and everything looks fine
2nd AJAX call [Get another partial page B to replace the video]
var oldVideo = dijit.byId('vid');
oldVideo.destroy(); //should destroy this widget but doesn't
For some reason this widget is not destroyed, causing a problem because by the time we go back to perform AJAX call and try to page A and video again, it throws the id already exists exception.
I also tried other funcions such us destroyRecursive(), disconnect() but none of them worked, does anyone know where the problem is?
Cheers
Peter
Try this:
var oldVideo = dijit.byId('vid');
oldVideo.destroy();
delete oldVideo;

problem with RegisterClientScriptBlock

i have to run following javascript through one of my method. But its not running
Whats wrong with the code.
private void fillGrid1()
{
GridView1.DataSource = myDocCenter.GetDsWaitingForMe(Session["UserID"].ToString());
HiddenField1.Value = { myDocCenter.GetDsWaitingForMe(Session["UserID"].ToString()).Tables[0].Rows.Count).ToString();
GridView1.DataBind();
String csname1 = "PopupScript1";
String csname2 = "ButtonClickScript1";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
{
StringBuilder cstext2 = new StringBuilder();
cstext2.Append("<script type=\"text/javascript\"> ");
// You can add JavaScript by using "cstext2.Append()".
cstext2.Append("var count = document.getElementById('ctl00_ContentPlaceHolder1_HiddenField2');");
cstext2.Append("var count = '100';");
cstext2.Append("document.getElementById('sp2').innerHTML = count;");
cstext2.Append("script>");
cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);
}
}
Your script tag is not properly closed.
Change
cstext2.Append("script>");
to
cstext2.Append("</script>");
On top of what adamantium said, your JS looks a bit strange. You seem to declare and set the count variable twice - did you mean to do this.
Following that, best thing to do, render the page then view source. is your JS getting rendered to the page? try and stick an alert in there... is it firing?
> cstext2.Append("var count =
> document.getElementById('ctl00_ContentPlaceHolder1_HiddenField2');");
I would use the ClientID property here. HiddenField2.ClientID
RegisterClientScriptBlock emits the script just after the <form> tag openning. Browser executes this script just after the tag openning as well but referenced elements are not processed yet at this time - browser cannot find them.
RegisterStartupScript method emits the script just before the <form> tag ending. Nearly all page elements are processed by the browser at this place and getElementById could find something.
See http://jakub-linhart.blogspot.com/2012/03/script-registration-labyrinth-in-aspnet.html for more details.