How to programmatically add a LinkItem to a LinkItemCollection - episerver

I know the question sounds simple but it's actually tricky.
We have a page (CoursePage) that is cloned first before setting its properties at runtime.
PageData clone = existingCoursePage.CreateWritableClone();
coursePage = (CoursePage)clone;
// set properties....
// RelevantCourseInformationCollection is a LinkItemCollection
coursePage.RelevantCourseInformationCollection.Add(new LinkItem { Href = "google.com", Text = "Google" });
and I'm getting a null LinkItemCollection.

It seems likely that your existing page does not currently have any items in the RelevantCourseInformationColletion. If this is the case, the property will be null and you will have to assign it a new LinkItemCollection instance before trying to add any LinkItems.
coursePage.RelevantCourseInformationCollection = new LinkItemCollection();
coursePage.RelevantCourseInformationCollection.Add(new LinkItem { Href = "google.com", Text = "Google" });
Or if you prefer the shorthand:
coursePage.RelevantCourseInformationCollection = new LinkItemColletion { { new LinkItem { Href = "google.com", Text = "Google" } } };

Related

React - when document open in new tab change the name of this new tab

I need to open document in a new tab in the browser and change the name of this tab
I wrote this code:
const blobUrlDocs = URL.createObjectURL(blob);
var newWindow = window.open(blobUrlDocs, "_blank");
newWindow.document.title = data.D_NAME;
return newWindow;
but the namews tab has not changed
I try wrote it in onload function :
newWindow.onload = function () {
newWindow.document.title = data.D_NAME;
return newWindow;
};
But the name of the tab only changed when the document was loaded.
What should I do so that the name of the document remains even after loading the document?

How to get Selected Listbox Items using devexpress in winforms app?

I am trying to get selected item text. I used this below code
MessageBox.Show(listBoxColumnHeaders.SelectedItems);
Output
Devexpress.XtraEditors.BaseListboxControl+SelectedItemCollection
But my text is Country
Update
I add listbox items from another class. That class called FilterColumnHeader using below code
FilterControl fc = Application.OpenForms.OfType<FilterControl>().SingleOrDefault();
List<FilterColumnHeader> headers = new List<FilterColumnHeader>();
while (rd.Read())
{
headers.Add(new FilterColumnHeader { typeOfHeader = rd["type"].ToString(), columnHeadersName = rd["AsHeading"].ToString() });
}
fc.listBoxColumnHeaders.DisplayMember = "columnHeadersName";
fc.listBoxColumnHeaders.ValueMember = "typeOfHeader";
fc.listBoxColumnHeaders.DataSource = headers;
Now When I try to print using this below code,
MessageBox.Show(""+ listBoxColumnHeaders.SelectedItems[0].ToString());
It is showing in message box like below
`ProjectName.FilterColumnHeader`
The SelectedItems property returns a collection of selected objects. All you need to do is to cast the required object to your type:
var filterColumnHeader = (FilterColumnHeader)listBoxControl.SelectedItems[0];
I don't know if you found an answer but this works for me :
StringBuilder list = new StringBuilder();
foreach(var item in listBoxColumnHeaders.SelectedItems)
{
list.AppendLine(item as string);
}
MessageBox.Show(list.ToString());

Navigation Experimental - Replace NavigationHeader Title Within a Scenes View

I'm trying to update the NavigationHeader title (along with left and right components) from a specific scene's view.
Example:
User navigates to profile view
Get data from server
Call redux action to update the navigation header with the username
My current approach is not working too well. I'm trying to use the NavigationStateUtils to replace the scene with an updated version of itself. This works if my view is the first one in the stack. However, if I try adding the call to update nav header on a route that isn't the first, it will freeze because the navigation hasn't finished it's animation.
I could try adding a timeout on the call, but it seems hacky to come up with a delay that makes sense globally.
case UPDATE_NAV_HEADER: {
const tabs = state.get('tabs')
const tabKey = tabs.getIn(['routes', tabs.get('index')]).get('key')
const scenes = state.get(tabKey).toJS()
const route = scenes.routes.slice(-1)[0]
var leftComponent = null
if (action.payload.leftComponent) {
leftComponent = action.payload.leftComponent
} else if (route.navLeftComponent) {
leftComponent = route.navLeftComponent
}
var rightComponent = null
if (action.payload.rightComponent) {
rightComponent = action.payload.rightComponent
} else if (route.navRightComponent) {
rightComponent = route.navRightComponent
}
const newScene = NavigationStateUtils.replaceAt(
scenes,
route.key,
{
key: route.key,
title: action.payload.newTitle ? action.payload.newTitle : route.title,
navLeftComponent: leftComponent,
navRightComponent: rightComponent,
shouldRenderHeader: "shouldRenderHeader" in route ? route.shouldRenderHeader : true,
shouldRenderTabBar: "shouldRenderTabBar" in route ? route.shouldRenderTabBar : true
}
)
return state.set(tabKey, fromJS(newScene))
}

How do you properly set a custom profile property in DNN?

I'm trying to save a custom property to an existing user profile in DNN 7, but the profile property is not getting set. I must be understanding something incorrectly.
So, how do you properly set a custom profile property in DNN?
UserInfo.Profile.SetProfileProperty("key","value")
// I expect this to return "value", but it's always ""
var value = UserInfo.Profile.GetProfileProperty("key");
// Even if I save it...
ProfileController.UpdateUserProfile(UserInfo);
// It always returns ""
var savedValue = UserInfo.Profile.GetProfileProperty("key");
Note: I also tried InitialiseProfile but that didn't change the behavior.
Here is how I am accessing a propertyvalue from a property in a module base class I have for a client.
public string SomeKey
{
get
{
var ppd = UserInfo.Profile.GetProperty("SomeKey");
if (ppd.PropertyValue == string.Empty)
{
var SomeKeyValue = "blah"
//update the user's profile property
UserInfo.Profile.SetProfileProperty("SomeKey", SomeKeyValue);
//save the user
DotNetNuke.Entities.Users.UserController.UpdateUser(PortalId, UserInfo);
//retrieve again
return SomeKey;
}
string returnValue = ppd.PropertyValue ??
(String.IsNullOrEmpty(ppd.DefaultValue) ? String.Empty : ppd.DefaultValue);
return returnValue;
}
}

Problem with WPF perfomance

I have form which has many tabs. Every tab has many controls textboxes, comboboxes, datagrids and e .t.c. I bind form to one data source in such way
this.DataContext=MyClassInstance
But with this way my form opening very slow. about one minute.
When I comment above code, form opens very quickly. All My controls I bound to the class properties in XAML. Please tell me the way to bind every tab when it's activated, or bind controls in background thread or any other idea which can help me to speed up my form.
Thanks in advance.
I think the problem lies in your class instance you are binding to.
When the xaml is bound to the class, all the getters of the bound properties are fired. If each getter accesses the database to get some data, this can take a while.
I think you should really review your design here, and think about asynchronously fetching your data.
I agree with Gerrie.
I'm suggesting the following:
When you start your application, you automatically open one tab i guess. Load only that tab, don't care about the others. This should start your project much faster.
The thing you do for the other tabs is load them when clicked for the first time. When the user for example is interested in tab 5, the only ones loading will be the initial tab at startup, and tab 5 when clicked by the user. all other tabs will not be loaded, which will decrease startup time.
Hope the idea is clear to you and will help your application.
I found why my form open so slow. I use about 20 XMLDataProvider object in form. and this providers were iteract with xml file. When I comment code below everything working fast. Thank everyone for help
//relatives_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_RelativeList" };
//education_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_EducationList" };
//requalification_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_RequalificationList" };
//jobHistory_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_JobHistoryList" };
//rank_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_RankList" };
//tradeUnion_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_TradeUnionList" };
//election_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_ElectionList" };
//judgeHistory_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_JudgeHistoryList" };
//tempWork_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_TempWorkList" };
//inquire_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_InquireList" };
//bulleten_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_BulletenList" };
//reprimand_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_ReprimandList" };
//certificate_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_CertificateList" };
//course_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_CourceList" };
//incentive_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_IncentiveList" };
//btrip_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_BtripList" };
//vacation_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_VacationList" };
//pass_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_PassList" };
//language_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_LanguageList" };

Resources