ASP.Net Treeview: Strange postback behavior - asp.net

I have a ASP.NET treeview populated with custom treenodes (ExtensionRangeTreeNode subclassed from TreeNode).
On postback the treeview is populated with TreeNodes, not my custom treenode class.
What's up with this?
Thanks,
BP

This forum entry may answer the question :
Basically, it is said a custom treeview control has to be used. CreateNode function must be overriden to instanciate the right TreeNode type. Here, it would be ExtensionRangeTreeNode instead of "CustomTreeNode".
public class CustomTreeView : TreeView
{
protected override TreeNode CreateNode()
{
return new CustomTreeNode(this, false);
}
}
Of course, you will have to add the ExtensionRangeTreeNode(Treeview treeview, bool isRoot) constructor signature to your current ExtensionRangeTreeNode implementation.

Without looking at your particular code, I can only assume that you custom TreeNode is not using ViewState. This would explain why it is not getting populated on postback.

DoesExtensionRangeTreeNode fully handle saving itself to the viewstate fully? If so, can you cast the returned nodes to that type?

Related

dialogPostRun method in RunBaseReport

I have a RunBaseReport which contains overrided dialog method where I'm adding couple of my controls. One of those controls is a combobox.
Controls enabled() property should be changed when I'm modifying combobox.
So basically I need to know when the value of my dfReportType dialog field changes.
public Object dialog(Object dialog)
{
DialogRunbase dialog = dialog;
;
//adding my combobox
dfReportType = dialog.addFieldValue(typeid(ReportType), ReportType:DefaultType);
//adding some other controls here
return dialog;
}
According to many articles that I found I need to override dialogPostRun Method and do something like this:
public void dialogPostRun(DialogRunbase dialog)
{
super(dialog);
dialog.dialogForm().formRun().controlMethodOverload(true);
dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}
But unfortunately I don't have this method in RunBaseReport class.
Which should be there according to msdn .
Are there any other workarounds?
I'm currently on AX 2012 but I still looked at it. I have the method available in the context menu, but not on the first column. I have to go over "Plus..." to find the method in the second column.
Well, there is no dialogPostRun method in Report object that inherits RunBaseReport, but we have this method in Class that inherits RunBaseReport.
So that was my mistake. I used report object instead of class.
If you want to make custom dialog for the report but you also want to use all default controls you should:
Create class
Inherit RunBaseReport
Override dialog, getFromDialog etc.
Override lastValueElementName method
public identifiername lastValueElementName()
{
//just put name of your report object
return reportStr(YourReportName);
}
Don't forget to add main() method if you going to make call from menuItem.

How to activate another button using click event of certain button in MS Dynamics AX?

I'm creating a new form in Axapta.
How can I make a Show-->Line View to be activated by clicking on New--> Item?
Should I do this by X++ override methods or it is possible not to use code?
I think it can only be done with code. Override your datasource's create() method and then call the button clicked() method. Note that to call directly the button's Auto declaration propery need to be set to Yes.
For instance in a SalesTable form you could overwrite SalesTable.create() method :
void create(boolean append = true)
{
SalesTable newSalesTable;
EditDetailsButton.clicked();
// rest code goes here
}

ITemplate, the reason for leaving InstantiateIn(Control container)

I'm implementing the ITemplate interface in ListView control. If i realize it for ItemTemplate in my custom class, everything will be OK. I mean, the runtime will invoke InstantiateIn when i use
ListView.ItemTemplate = new CustomClass();
CustomClass :ITemplate
{
public void InstantiateIn(Control container)
{
HtmlTable table = CreateHeader();
container.Controls.Add(table);
}
...
}
But i want to do the same with ListView.LayoutTemplate. In this case, the runtime invokes InstantiateIn only one time, but every next update it leaves my method. What is the reason for it?
Layout template says how the root container does look like, it is not per item thing.
I have to change my LayoutTemplate after clicking different buttons.
And My LayoutTemplate has a header for the whole ListView. I have to change it, it depends on button.
Also i have two custom classes with implementations of ITemplate (one for ItemTemplate and one for LayoutTemplate). I am going to realise the folowing behaviour:
1). If i click Button1
ListView.ItemTemplate = new CustomItemClass1();
ListView.LayoutTemplate = new CustomLayuotClass1();
2). If i click Button2
ListView.ItemTemplate = new CustomItemClass2();
ListView.LayoutTemplate = new CustomLayuotClass2();
But i can't see my header of LayoutTemplate more, then one time.

Flex extending ComboBox

I created a class CustomCombo.as that extends ComboBox. What is happening is that the CustomCombo combobox is showing as being editable. I do not want this and I cant find the properties to set the editable to false.
I also tried setting the combobox's textInput.editable control to false, but to no avail.
Any help would be greatly appreciated.
CustomCombo.as
package custom {
import spark.components.ComboBox;
public class CustomCombo extends ComboBox {
public function CustomCombo() {
super();
// this.editable = false; //<-- THIS DOESNT WORK ***Access of possibly undefined property editable through a reference with static type custom:CustomCombo
// this.textInput.editable = false; //<-- THIS DOESNT WORK ***Cannot access a property or method of a null object reference
}
}
}
After rummaging through the Flex 4 API I found that they suggest to use the DropDownList control. From what I can see is that they removed the editable property from the ComboBox control in Flex 4, but I may be wrong.
I implemented DropDownList and that solved my problem.
I see that you're using spark and not mx. The editable property I referred to is applicable only to mx based list. In spark, ComboBox extends DropDownListBase and is editable by default.
The ComboBox control is a child class of the DropDownListBase control. Like the DropDownListBase control, when the user selects an item from the drop-down list in the ComboBox control, the data item appears in the prompt area of the control.
One difference between the controls is that the prompt area of the ComboBox control is implemented by using the TextInput control, instead of the Label control for the DropDownList control. Therefore, a user can edit the prompt area of the control to enter a value that is not one of the predefined options.
For example, the DropDownList control only lets the user select from a list of predefined items in the control. The ComboBox control lets the user either select a predefined item, or enter a new item into the prompt area. Your application can recognize that a new item has been entered and, optionally, add it to the list of items in the control.
The ComboBox control also searches the item list as the user enters characters into the prompt area. As the user enters characters, the drop-down area of the control opens. It then and scrolls to and highlights the closest match in the item list.
So ideally, you should be using DropDownList in this case.
You're getting null error when trying to access textInput from the constructor because it hasn't been created yet. In mx based controls (Flex-3), you can access it from the creationComplete handler; I'm not quite sure how to do it for spark based controls.
Update: I think I've figured out how to access skin parts in spark (though you might wanna use the DropDownBox instead). You have to override the partAdded method.
override protected function partAdded(partName:String, instance:Object):void
{
super.partAdded(partName, instance);
if (instance == textInput)
{
textInput.editable = false;
}
}
There's one catch though: it may not work in this case. The source code of ComboBox.as says that
the API ignores the visual editable and selectable properties
So DropDownList it is!
Initial answer, posted for mx ComboBox.
This shouldn't happen as the default value of the editable property is false.
Try explicitly setting the value to false from the constructor.
public function CustomCombo() {
super();
this.editable = false;
}

asp.net tree css adapter selectedNode is null?

I just switched to using the CSS Adapters for my TreeView control on one my ASPX pages. Now, for some reason, I cannot use the SelectedNode method except in my OnClick() event. ALL other events show that the SelectedNode is NULL. I am currently using a bunch of non-visible labels to store tree info everytime someone clicks on a node. Very, very, very wrong way to use this control. What is the secret to getting the control in code behind when CSS Adapters are enabled?
The adapter for the TreeView control does have some viewstate handling but you are right the selected node property is null on postback.
If you hover over the root node the status bar on the browser will show something like:
javascript:__doPostBack('controlid', 'eventargument');
//or
javascript:__doPostBack('tv', 'srootnodevalue\\childnodevalue');
You can catch the event argument in the code behind which describes the node you are accessing and its value as a string like 'node\value'.
if (Request.Form["__EVENTTARGET"] != null && Request.Form["__EVENTARGUMENT"] != null)
{
if (Request.Form["__EVENTTARGET"].Equals("tv")) //tv is my treeview control id, and the first parameter in __doPostBack()
Tv_SelectedNodeChanged(Request.Form["__EVENTARGUMENT"]);
}
protected void Tv_SelectedNodeChanged(string argument)
{
//process the argument string 'srootnodevalue\childnodevalue'
}
The treeview viewstate seems aware of the selected node by the adapter's representation of it as class="AspNet-TreeView-Leaf AspNet-TreeView-Selected" when it renders.
Still, there may be a nicer way of doing this...

Resources