In C# page i am getting TreeViewId.SelectedNode.Depth, while in javascript when i am trying to get depth of same treeView i am not getting the depth.
var treeViewData = window["<%=TreeViewMerchantId.ClientID%>" + "_Data"];
if (document.getElementById(treeViewData).selectedNodeID.value != "")
{
var selectedNode = document.getElementById(treeViewData).selectedNodeID.value;
var text = selectedNode.innerHTML;
var Depth = selectedNode.depth;
var Lable = selectedNode.level;
}
Related
In C# viaGeckoFx, I have not found a method to find all attributes of an element.
To do this, I made a JavaScript function. Here is my code
GeckoWebBrowser GeckoBrowser = ....;
GeckoNode NodeElement = ....; // HTML element where to find all HTML attributes
string JSresult = "";
string JStext = #"
function getElementAttributes(element)
{
var AttributesAssocArray = {};
for (var index = 0; index < element.attributes.length; ++index) { AttributesAssocArray[element.attributes[index].name] = element.attributes[index].value; };
return JSON.stringify(AttributesAssocArray);
}
getElementAttributes(this);
";
using (AutoJSContext JScontext = new AutoJSContext(GeckoBrowser.Window.JSContext)) { JScontext.EvaluateScript(JStext, (nsISupports)NodeElement.DomObject, out JSresult); }
Do you have others suggestions to achieve this in C# (with no Javascript)?
The property GeckoElement.Attributes allows access to an elements attributes.
So for example (this is untested and uncompiled code):
public string GetElementAttributes(GeckoElement element)
{
var result = new StringBuilder();
foreach(var a in element.Attributes)
{
result.Append(String.Format(" {0} = '{1}' ", a.NodeName, a.NodeValue));
}
return result.ToString();
}
I've searched and I can't find any documentation on how to create a Group Page in the sitefinity API. I know how to create a page programmatically.
var pageDataId = Guid.NewGuid();
PageManager manager = PageManager.GetManager();
PageData pageData = null;
PageNode pageNode = null;
// Get the parent node Id
if (parentPageNodeId == Guid.Empty)
{
parentPageNodeId = SiteInitializer.CurrentFrontendRootNodeId;
}
PageNode parent = manager.GetPageNode(parentPageNodeId);
// Check whether exists
var initialPageNode = manager.GetPageNodes().Where(n => n.Id == pageId).SingleOrDefault();
if (initialPageNode != null)
{
return;
}
// Create the page
pageData = manager.CreatePageData(pageDataId);
pageData.HtmlTitle = pageName;
pageData.Title = pageName;
pageData.Description = pageName;
pageData.Culture = Thread.CurrentThread.CurrentCulture.ToString();
pageData.UiCulture = Thread.CurrentThread.CurrentUICulture.ToString();
pageNode = manager.CreatePage(parent, pageId, NodeType.Standard);
pageNode.Page = pageData;
pageNode.Name = pageName;
pageNode.Description = pageName;
pageNode.Title = pageName;
pageNode.UrlName = Regex.Replace(pageName.ToLower(), #"[^\w\-\!\$\'\(\)\=\#\d_]+", "-");
pageNode.ShowInNavigation = true;
pageNode.DateCreated = DateTime.UtcNow;
pageNode.LastModified = DateTime.UtcNow;
// Check whether home page
if (isHomePage)
{
SystemManager.CurrentContext.CurrentSite.SetHomePage(pageId);
}
manager.SaveChanges();
// Publish
var bag = new Dictionary<string, string>();
bag.Add("ContentType", typeof(PageNode).FullName);
WorkflowManager.MessageWorkflow(pageId, typeof(PageNode), null, "Publish", false, bag);
}
This creates a regular page. I've tried changing the NodeType from standard to NodeType.Group and leaving the rest of the code as is. However this throws an exception "The current page is not standard page." I've looked for pageNode properties to make the page a group page rather than a regular page but I can't find any. If anyone knows how to do this I would really appreciate it.
the exception is probably being thrown because you are attempting to create PageData for the created Group node. I believe that Group nodes do not have page data, but rather serve only to group other page nodes.
try removing the creation and assignment of the pageData to the PageGroup.Page property, and that should allow you to save the created page node.
Also if you install the sitefinity SDK there's a SampleUtilities class in the resources folder that has a lot of helper methods for creating pages, templates, etc that serves as a great reference point for working with the API.
I hope this is helpful!
This is some code that might help you:
// Define our new view
var templateIconView = new TemplateIconView { ID = TemplateIconViewControlId };
var pageManager = PageManager.GetManager();
pageManager.Provider.SuppressSecurityChecks = true;
// Get the root
var parentNode = pageManager.GetPageNode(SiteInitializer.SitefinityNodeId);
// Check whether exists
var initialPageNode = pageManager.GetPageNodes().SingleOrDefault(n => n.Id == AdditionalToolsPageId);
if (initialPageNode != null) {
pageManager.Delete(initialPageNode);
pageManager.SaveChanges();
}
var homePageNode = pageManager.GetPageNodes().SingleOrDefault(n => n.Id == HomePageId);
if (homePageNode != null) {
pageManager.Delete(homePageNode);
pageManager.SaveChanges();
}
// Create the Group Page Node
var groupPageNode = pageManager.CreatePage(parentNode, AdditionalToolsPageId, NodeType.Group);
groupPageNode.Name = "KonstruiTools";
groupPageNode.Description.SetString("Konstrui Tools", true);
groupPageNode.Title.SetString("Konstrui Tools", true);
groupPageNode.UrlName = Regex.Replace("Konstrui Tools", #"[^\w\-\!\$\'\(\)\=\#\d_]+", "-").ToLower();
groupPageNode.ShowInNavigation = true;
groupPageNode.DateCreated = DateTime.UtcNow;
groupPageNode.LastModified = DateTime.UtcNow;
pageManager.SaveChanges();
// Create the actual page PageData
var pageData = pageManager.CreatePageData(HomePageId);
pageData.HtmlTitle = "Configure Template Icons";
pageData.Title = "Configure Template Icons";
pageData.Description = "Configure Template Icons";
pageData.Culture = Thread.CurrentThread.CurrentCulture.ToString();
pageData.UiCulture = Thread.CurrentThread.CurrentUICulture.ToString();
pageData.EnableViewState = true;
pageData.EnableViewStateMac = true;
// Add our control to the page with default permissions
var control = pageManager.CreateControl<PageControl>(templateIconView, Constants.VALUE_DEFAULT_BACKEND_PLACEHOLDER);
pageManager.SetControlDefaultPermissions(control);
pageData.Controls.Add(control);
// Assign the Default Backend Template
pageData.Template = pageManager.GetTemplate(SiteInitializer.DefaultBackendTemplateId);
// Create the actual page PageNode
var pageNode = pageManager.CreatePage(groupPageNode, HomePageId, NodeType.Standard);
pageNode.Page = pageData;
pageNode.Name = "ConfigureTemplateIcons";
pageNode.Description = "Configure Template Icons";
pageNode.Title = "Configure Template Icons";
pageNode.UrlName = Regex.Replace("Configure Template Icons", #"[^\w\-\!\$\'\(\)\=\#\d_]+", "-").ToLower();
pageNode.ShowInNavigation = true;
pageNode.DateCreated = DateTime.UtcNow;
pageNode.LastModified = DateTime.UtcNow;
pageNode.RenderAsLink = true;
pageManager.SaveChanges();
// Publish
var bag = new Dictionary<string, string>();
bag.Add("ContentType", typeof(PageNode).FullName);
WorkflowManager.MessageWorkflow(HomePageId, typeof(PageNode), null, "Publish", false, bag);
pageManager.Provider.SuppressSecurityChecks = false;
This creates a grouppage inside the backend on rootlevel, wich holds another page with a control.
Here is what I ended up doing. It will create a group page under another group page which is exactly what I needed for my requirements.
var pageId = Guid.NewGuid();
PageManager manager = PageManager.GetManager();
PageNode pageNode = null;
//Find the modules section which will serve as the
//parent page.
string pageTitle = ConfigurationManager.AppSettings["ModulesSection"].ToString();
//Gets the actual Modules page.
var modulesNode = SitefinityHelper.GetPageNode(pageTitle);
if (modulesNode.Id == Guid.Empty)
{
modulesNode.Id = SiteInitializer.CurrentFrontendRootNodeId;
}
PageNode modulesPage = manager.GetPageNode(modulesNode.Id);
// Check whether exists
var initialPageNode = manager.GetPageNodes().Where(n => n.Id ==
pageId).SingleOrDefault();
if (initialPageNode != null)
{
return false;
}
//Creates the page under the Modules section as a Group Page.
pageNode = manager.CreatePage(modulesPage, pageId, NodeType.Group);
pageNode.Name = newModule.Name;
pageNode.Description = newModule.Description;
pageNode.Title = newModule.Name;
pageNode.UrlName = Regex.Replace(newModule.Name.ToLower(), #"[^\w\-\!\$\'\(\)\=\#\d_]+", "-");
pageNode.ShowInNavigation = true;
pageNode.DateCreated = DateTime.UtcNow;
pageNode.LastModified = DateTime.UtcNow;
manager.SaveChanges();e here
You can create Group page using fluent API. It's easy way given in fluent API
App.WorkWith()
.Page()
.CreateNewPageGroup()
.Do(x => x.Title = "Testpage2")
.Do(x => x.Name = "Testpage2")
.Do(x => x.UrlName = "testpage2")
.SaveChanges();
I am trying to replace some text using HtmlAgilityPack in Html string and placing ASP.net user controls but I am getting lower case in output html. Any Idea how to get original case output.
Code :
public static string ConvertPageTitlesToCMSTitle(string htmlstring, string themeSlug)
{
var htmlDoc = new HtmlAgilityPack.HtmlDocument()
{
OptionOutputOriginalCase = true,
OptionWriteEmptyNodes = true
};
htmlDoc.LoadHtml(htmlstring);
var stPageTitleTags = htmlDoc.DocumentNode.SelectNodes("//stpagetitle");
foreach (var stPageTitleTag in stPageTitleTags)
{
var pageTitle = Strings.StripHTML(stPageTitleTag.InnerText);
pageTitle = pageTitle.Trim();
var pageId = CreateUpdateContentPageInDb(pageTitle, themeSlug, null, null);
var widgetControl = string.Format("<widget:PageTitleDisplay runat=\"server\" PageId=\"{0}\" Editable=\"True\" />", pageId);
htmlDoc.DocumentNode.InnerHtml = htmlDoc.DocumentNode.InnerHtml.Replace(stPageTitleTag.OuterHtml, widgetControl);
}
return htmlDoc.DocumentNode.OuterHtml;
}
As a workaround you could create a text node instead of HTML node. See:
foreach (var stPageTitleTag in stPageTitleTags)
{
var pageTitle = Strings.StripHTML(stPageTitleTag.InnerText);
pageTitle = pageTitle.Trim();
var pageId = CreateUpdateContentPageInDb(pageTitle, themeSlug, null, null);
var widgetControl = string.Format("<widget:PageTitleDisplay runat=\"server\" PageId=\"{0}\" Editable=\"True\" />", pageId);
// creating a text node
var widget = htmlDoc.CreateTextNode(widgetControl);
// replacing <sppagetitle> node with the new one
stPageTitleTag.ReplaceChild(widget, stPageTitleTag);
}
This should get the output you want.
I have the latest version of telerik (2013) but I am with the following problem, I need to change the value of a radnumerictextbox using javascript (client side), but after I set a value using JQuery or javascript regular control changes value because daa format, follows the control and js code:
<telerik: RadNumericTextBox id = "txtValor" runat = "server" EnableEmbeddedSkins = "false" Height = "15px" Skin = "Corporate" Width = "90%">
<NumberFormat DecimalSeparator="," DecimalDigits="2" />
</ telerik:RadNumericTextBox>
I try this
$(idCampo).val(_valorTotal.replace(".", ","));
$(nomeCampo).text(_valorTotal.replace(".", ","));
when running a postback the mask is lost, for example:
2000.55 = 200,055.00
And also tried this:
$(idCampo).val(parseFloat (_valorTotal));
$(idCampo).text(_valorTotal.replace (".", ""));
when executed the value is shown without masks, but when generated the postback event is placed usually
2000.55 = 2.000,55
Would have some event to update fields in the mask? Would otherwise not have tried to set a value in control?
you need a function java script
use my script :)
function Moneda(formato) {
var num = formato;//parseFloat("40000.51239");
var cadena = ""; var aux;
var cont = 1,m,k;
if(num<0) aux=1; else aux=0;
num=num.toString();
for(m=num.length-1; m>=0; m--){
cadena = num.charAt(m) + cadena;
if(cont%3 == 0 && m >aux) cadena = "." + cadena; else cadena = cadena;
if(cont== 3) cont = 1; else cont++;
}
cadena = cadena.split(".").join(",");
var separacion = "";
var quitarDobleComa = cadena.search(",,");
separacion = cadena.substring((quitarDobleComa+2),cadena.length);
separacion = separacion.split(",").join("");
var formatoPunto = cadena.substring(0,quitarDobleComa);
var final = formatoPunto +"."+ separacion;
return final;
}
I use the AsyncUpload
<telerik:RadAsyncUpload runat="server" ID="rada_attach" OnClientFileUploaded="onClientFileUploaded"
MultipleFileSelection="Disabled" InitialFileInputsCount="1" MaxFileInputsCount="1"
Width="100%" />
function onClientFileUploaded(radAsyncUpload, args) {
var row = args.get_row(),
inputName = radAsyncUpload.getAdditionalFieldID("TextBox"),
inputType = "text",
inputID = inputName,
input = createInput(inputType, inputID, inputName),
label = createLabel(inputID),
br = document.createElement("br");
row.appendChild(br);
row.appendChild(input);
row.appendChild(label);
}
function createInput(inputType, inputID, inputName) {
var input = document.createElement("input");
input.setAttribute("type", inputType);
input.setAttribute("id", inputID);
input.setAttribute("name", inputName);
return input;
}
I want to access the textbox (which created dynamically) in .cs.
How to do that ?
The Full Answer :
var $ = $telerik.$;
function onClientFileUploaded(radAsyncUpload, args) {
var $row = $(args.get_row());
var inputName = radAsyncUpload.getID("TextBox");
var inputType = "text";
var inputID = inputName;
var input = createInput(inputType, inputID, inputName);
var label = createLabel(inputID);
$row.append("<br/>");
$row.append(label);
$row.append(input);
}
function createInput(inputType, inputID, inputName) {
var input = '<input type="' + inputType + '" id="' + inputID + '" name="' + inputName + '" />';
return input;
}
function createLabel(forArrt) {
var label = '<label for=' + forArrt + '>info: </label>';
return label;
}
foreach (UploadedFile UF in rada_attach.UploadedFiles)
{
if (UF.GetFieldValue("TextBox") != null)
{
OBJ.File_name = UF.GetFieldValue("TextBox");
}
else
{
OBJ.File_name = UF.GetName();
}
In my opinion documentation is well clear. Check the Description tab on page you refer on. You can access value of dynamic textboxes with code below on postback:
if (rada_attach.UploadedFiles.Count > 0) {
for (var index = 0; index < rada_attach.UploadedFiles.Count; ++index) {
var textBoxValue = rada_attach.UploadedFiles[index].GetFieldValue("TextBox");
}
}
BTW, this scenario is well-dcoumented here: Adding Information to Uploaded Files
You need to check the Request.Form values (that were in the posted form) on postback and perform a check on all the fields that were posted back.
I am guessing that you won't know the name/id of the textbox if it was created on the client-side dynamically? Note that it would be the name of the form field that the Request object in .cs would see.
Only once you have posted back can you access that value in the .cs