ShieldUI will not accept updated attributes - c#

I have the following code:
protected void SetChartToItem(Item item)
{
ShieldChart1 = new ShieldChart();
ShieldChart1.Width = Unit.Percentage(100);
ShieldChart1.Height = Unit.Pixel(400);
ShieldChart1.CssClass = "chart";
ShieldChart1.PrimaryHeader.Text = item.name;
ShieldChart1.TooltipSettings.AxisMarkers.Enabled = true;
ShieldChart1.TooltipSettings.AxisMarkers.Mode = ChartXYMode.XY;
ShieldChart1.TooltipSettings.AxisMarkers.Width = new Unit(1);
ShieldChart1.TooltipSettings.AxisMarkers.ZIndex = 3;
ChartAxisX axisX = new ChartAxisX();
axisX.Title.Text = "Times";
ShieldChart1.Axes.Add(axisX);
ChartAxisY axisY = new ChartAxisY();
axisY.Title.Text = "Prices";
ShieldChart1.Axes.Add(axisY);
ShieldChart1.Axes.SetDirty();
}
And the following code:
<shield:ShieldChart ID="ShieldChart1" Width="700px" Height="380px" runat="server" OnTakeDataSource="ShieldChart1_TakeDataSource" CssClass="chart">
<PrimaryHeader Text="TestHeader"></PrimaryHeader>
<ExportOptions AllowExportToImage="true" AllowPrint="false" />
<Axes>
<shield:ChartAxisX>
<Title Text="Time"></Title>
</shield:ChartAxisX>
<shield:ChartAxisY>
<Title Text="Price"></Title>
</shield:ChartAxisY>
</Axes>
<DataSeries>
<shield:ChartLineSeries DataFieldY="Volume" DataFieldX="Timer" CollectionAlias="Volume">
<Settings EnablePointSelection="true">
<PointMark>
<ActiveSettings>
<PointSelectedState DrawWidth="4" DrawRadius="4" />
</ActiveSettings>
</PointMark>
</Settings>
</shield:ChartLineSeries>
<shield:ChartLineSeries DataFieldY="Price" DataFieldX="Timer" CollectionAlias="Price">
<Settings EnablePointSelection="true">
<PointMark>
<ActiveSettings>
<PointSelectedState DrawWidth="4" DrawRadius="4" />
</ActiveSettings>
</PointMark>
</Settings>
</shield:ChartLineSeries>
</DataSeries>
</shield:ShieldChart>
When I call SetChartToItem, it looks like it works when I watch it go through step by step, but when the page renders there are no changes to the actual ShieldChart. More information that might help is when I remove the line ShieldChart1 = new ShieldChart(); then the entire ShieldChart will disappear instead.

I believe there are two ways to try and address this.
One would be to recreate the chart, as demonstrated in this sample:
https://demos.shieldui.com/aspnet/rangebar-chart/related-charts
You can check out the asp.net tab.
Another alternative would be to recreate the controls collection (and clear it before this) in a nested panel, which hosts the chart. Then, on a specific event, you can recreate the chart, clear the controls collection of the container and add the new instance.

It took me 3 months, but I figured out what the problem was. I was causing some of the chart to build itself in the 'Page_Load' function. The solution to this was to make sure everyone was done only if the page is a postback page, which is not included in my code above but fixed the issue for me.

Related

C# WinForm chart data wont display

So I'm having a really weird problem in C# WindForm. I've tried to create a chart. In the area where the chart itself should exist, the problem is that it displays no data. It just looks like that:
That's my code:
int questionsAmount = setData.questionsAmount;
var dates = new List<DateTime>();
foreach(var item in setData.dates)
{
dates.Add(Convert.ToDateTime(item));
}
int[] records = setData["records"].ToObject<int[]>();
Series series = new Series("records");
series.Points.DataBindXY(dates, records);
series.ChartType = SeriesChartType.Spline;
chart = new Chart();
chart.Name = set.title;
chart.Series.Add(series);
chart.Series["records"].SetDefault(true);
chart.Series["records"].Enabled = true;
chart.BackColor = SystemColors.Highlight;
Controls.Add(chart);
Refresh();
Any help would be much appreciated. Thanks!
Hmm.. First, because we cannot read the entire code, I cannot sure the data generating process is working well. As your picture, the chart control is added. Maybe you can add breakpoint on "series.Points.DataBindXY(dates, records);" and check whether the data is ready or not.
FYI, another probable issue is you need to do UI operation in main thread (UI thread) if you didn't.
Hope these can help you.

Is it possible to render a user control inside of a generic handler (ashx)?

There might be a better way to get the result I'm looking for. Basically I have a page that dynamically loads content into a div using jquery.load().
So far it works great for static content, but now I have a repeater that I want to be able to include in this content. So I wanted to use a generic handler (maybe a webservice) to dynamically generate the rendered html of the user control and insert (or append, or load) it into the div.
So far I've had no luck.
Initially I tried this method
UCPeople ucPeople = new UCPeople { RoleType = (roleType.ToLower() == "board" ? RoleTypes.Board : RoleTypes.Executive) };
TextWriter myTextWriter = new StringWriter();
HtmlTextWriter myWriter = new HtmlTextWriter(myTextWriter);
ucPeople.RenderControl(myWriter);
return myTextWriter.ToString();
Which just returns an empty string.
So then I tried adding the control to a page instance, and it still came out blank.
Then I tried to load the userconrol into the new page instance with this.
var page = new Page(){ViewStateMode = ViewStateMode.Disabled };
UCPeople ucPeople = (UCPeople)page.LoadControl("~/our-company/people/UCPeople.ascx");
That seemed to get further, but the usercontrol throw an error because it's not in a form.
When I checked the form was null for that page. So I figured I needed to create an instance of the page, and I tried it two different ways.
var p2 = (Page)PageParser.GetCompiledPageInstance("~/our-company/people/peopleTest.aspx",
"~/our-company/people/peopleTest.aspx", context);
var p = (Page)System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath("~/our-company/people/peopleTest.aspx", typeof(Page));
Both still yielded a null form.
I'm out of ideas. Any suggestions?
Thanks.

ConfirmButtonExtender not working when adding to control collection at runtime

I am trying to add a ConfirmButtonExtender to my controls collection within a custom control at runtime but can not figure out why the extender will not wire to the button that is being added to the controls collection in the same CreateChildControls method. I did a simple test and added a button explicitly to an aspx page and then creating the extender dynamically in the PreRender of the the .cs file of that page and it still did not work. It seems that the only way to get this to work is to have the actual tags on the .aspx page.
Am I missing something?
protected virtual void CreateChildControls(System.Resources.ResourceManager rm)
{
valValidationSummary = new ValidationSummary();
valValidationSummary.ID = "valValidationSummary";
valValidationSummary.ShowSummary = true;
valValidationSummary.HeaderText = rm.GetString("ValidationSummary");
valValidationSummary.CssClass = "error";
btnGetRates = new LocalizedButton();
btnGetRates.ID = "btnGetStats";
btnGetRates.TextResource = rm.GetString("SubmitButton");
btnGetRates.Text = rm.GetString("SubmitButton");
btnGetRates.CssClass = "inputfield";
btnGetRates.Click += new System.EventHandler(OnSubmitButton_Click);
btnConfirmation = new ConfirmButtonExtender();
btnConfirmation.ID = "rfBtnSubmit_Confirm";
btnConfirmation.ConfirmText = rm.GetString("BAUConfrimation");
btnConfirmation.TargetControlID = "btnGetStats";
this.Controls.Add(btnConfirmation);
this.Controls.Add(valValidationSummary);
this.Controls.Add(btnGetRates);
}
Dumb mistake, I was not rendering the control.

Why does my table have no content in ASP.NET?

I have built a table in a class GetData.cs
public Table BuildTable()
{
Table tButtons = new Table();
TableRow tRow = new TableRow();
TableCell tCell = new TableCell();
long lColumn = 0;
long lPreviousColumn = 0;
long lRow = 0;
long lPreviousRow = 0;
long lLanguage = 0;
long lPreviousLanguage=0;
OpenConnection();
ButtonData();
Int32 lRowOrd = aReader.GetOrdinal("RowNumber");
Int32 lColOrd = aReader.GetOrdinal("ColumnNumber");
Int32 lLangOrd = aReader.GetOrdinal("Language");
Int32 lLabelOrd = aReader.GetOrdinal("Label");
while (aReader.Read())
{
lRow = IsDbNull(aReader,lRowOrd);//first get our column number
lColumn = IsDbNull(aReader,lColOrd);//first get our column number
lLanguage = IsDbNull(aReader,lLangOrd);//first get our column number
if (lPreviousRow != lRow)//we have a new row
{
if (lPreviousRow != 0)//then we are working on one and need to save it before moving on
{
tButtons.Rows.Add(tRow);//add the new row to the table
}
lPreviousRow = lRow;//remember the value for next time
tRow = new TableRow();
tRow.Visible = true;
//*******put the category titles in here somewhere
}
if (lPreviousColumn != lColumn)//we have a new column
{
if (lPreviousColumn != 0)//then we are working on one and need to save it before moving on
{
tRow.Cells.Add(tCell);//add the new cell to the row
}
lPreviousColumn = lColumn;//remember the value for next time
//*******add the cell colors
if (lPreviousLanguage != lLanguage)//we have a new column
{
lPreviousLanguage = lLanguage;//remember the value for next time
tCell.Text = IsDbNull(aReader,lLabelOrd,"");
//*******add the languages to properties
}
tCell = new TableCell();
tCell.Visible=true;
}
}
CloseConnection();
tButtons.Visible=true;
return tButtons;
}
In my Default.aspx.cs page I have
GetData Buttons = new GetData();//create a reference to the class
ButtonTable = Buttons.BuildTable();
OutPut.Text = ButtonTable.Rows.Count.ToString();
In Default.aspx
<asp:Table runat="server" ID="ButtonTable" />
<asp:Label runat="server" ID="OutPut" />
Output shows 4 rows, but table is empty.
<table id="ButtonTable" border="0"></table>
What am I doing wrong?
What the heck am I missing?
Apparently, a lot. In your markup, you have declared an instance of a System.Web.UI.WebControls.Table. In your instance of the Page class, this will have a variable name of "ButtonTable". It will also be automatically added to the Page.Controls collection. When the page is going to be rendered, the Controls collection will be iterated and rendered in turn.
In your default.aspx.cs code, you're simply pointing your ButtonTable reference to a different Table control - but you're not affecting the Page.Controls collection. When render time comes, it is the (blank) Table defined in the markup that will be rendered - not the result of your BuildTable call.
All of this is a fairly long winded "you're doing it wrong". The answer to why you want your table building code in a separate class would shed some light on the "right way". But - and I mean no offense - I think you need to study the basics behind ASP.NET before you go any further.
That being said, the most immediate fix (but likely not what you really want) is to add the table to the Controls collection so that it gets rendered:
GetData Buttons = new GetData();//create a reference to the class
ButtonTable = Buttons.BuildTable();
this.Controls.Add(ButtonTable);
OutPut.Text = ButtonTable.Rows.Count.ToString();
Note that it will render separately from your markup defined ButtonTable, and so will be placed after the Output label. That is because it was added after the Output label.
I really suggest you:
Run it line by line in the debugger to see what's going on
Refactor it, the code is hard to read. Adding more comments won't solve that.
Consider what you want to achieve and check if it can fits to databind to a control like ListView.
That said, your code:
GetData Buttons = new GetData();
ButtonTable = Buttons.BuildTable(); // this is what's wrong
OutPut.Text = ButtonTable.Rows.Count.ToString();
Just assigning the control in the page it's not the way to do it. Either add the returned table to the controls collection, or change BuildTable to receive the table it will load the info into. Never directly assign to the control of the asp.net page, once I had to debug code with some very strange issues and a developer had assigned null to a control (not to a property of the control) which messed up during the asp.net render cycle.
ButtonTable = Buttons.BuildTable();
What do you do in there here?

Adding new items to WPF Ribbon via Code

I'm using the WPF Office Ribbon, and I have a content view that I would like to have add new items to the ribbon when that view becomes active. I have code that adds a new RibbonCommand as well as a new RibbonButton to the group I want, but nothing happens when I add it. However, if I add a new group with the button, it comes up fine and is bound correctly. Is there some method to get it to update that I'm missing? I've tried UpdateLayout() and it does not work either. I'd really like to try and avoid rebuilding all the groups everytime the view changes.
Works:
public void InjectItems(IView view)
{
var ribbonCommands = ProcessRibbonCommands(view.GetViewModel().Tasks, view.GetType());
var group = new RibbonGroup();
group.Command = new RibbonCommand() { LabelTitle = "Group Test" };
foreach (RibbonCommand command in ribbonCommands)
{
shell.MainRibbon.Resources.Add(command.Name, command);
group.Controls.Add(new RibbonButton { Command = command });
}
shell.MainRibbon.SelectedTab.Groups.Add(group);
}
Doesn't Work:
public void InjectItems(IView view)
{
var ribbonCommands = ProcessRibbonCommands(view.GetViewModel().Tasks, view.GetType());
var group = shell.MainRibbon.SelectedTab.Groups[0]; //I have a default group, will fix later
foreach (RibbonCommand command in ribbonCommands)
{
shell.MainRibbon.Resources.Add(command.Name, command);
group.Controls.Add(new RibbonButton { Command = command });
}
}
I'm assuming you're using the Microsoft Ribbon CTP from the OfficeUI site.
As part of the licensing agreement there are a number of style guidelines that you are expected to follow. One of them is that you don't add/remove contents of the Ribbon based on your current view.
from the doc:
Controls displayed in a group MUST NOT change as a result of selection. If a control is not active, the
control MUST be grayed out, rather than removed from the group. This provides a more predictable
experience and prevents the layout of controls on the Ribbon from changing and distracting users.
that being said, it sounds like a Context tab is exactly what you're looking for. These can be disabled and enabled but the actual contents of the tab don't change.
This is the code to create a context tab in XAML:
<!--Context Groups-->
<r:Ribbon.ContextualTabGroups>
<!--Piece Contextual Group-->
<r:RibbonContextualTabGroup x:Name="grpPieceContext" Label="Piece Tools">
<r:RibbonTab Label="Piece Information" Name="tabPieceContextInfo">
<r:RibbonGroup Name="grpPieceDetails" Command="{StaticResource PieceInformationGrpCommand}">
<r:RibbonLabel x:Name="lblPieceTag"/>
<r:RibbonTextBox Name="txtPieceDescription" Command="{StaticResource PieceNameTextboxCommand}"
TextChanged="txtPieceDescription_TextChanged" MaxLength="32"/>
<r:RibbonLabel x:Name="lblPieceLocation"/>
</r:RibbonGroup>
</r:RibbonTab>
</r:RibbonContextualTabGroup>
</r:Ribbon.ContextualTabGroups>
you can then active and de-active the tab via this code:
if (!this.grpPieceContext.IsActive)
{
this.grpPieceContext.IsActive = true;
this.grpPieceContext.Color = Colors.Orange;
}
where orange is the color that sits in behind the context group.
Hope this helps
I ended up just deleting and recreating the group and entire tab if necessary.

Categories