Load a custom server control from another custom server control - c#

I have two custom server controls in a ASP.NET page,
one builds a chart, the other one plays the builded chart.
so my problem is to load the player when the chart is built.
so i send the file to the builder and now ii want just to load it
gChartPlayer Player = new gChartPlayer();
Player.XML_FILE = ChartFile;
something like Player.Load(),
can someone help me??

Question isn't really clear but if you want to decide when to load a usercontrol you can use LoadControl http://msdn.microsoft.com/en-us/library/c0az2h86(v=vs.100).aspx

You can use Add Method
Code : this.Controls.Add
Link : http://msdn.microsoft.com/en-us/library/aa277578(v=vs.60).aspx

Related

ASP.Net Class References a Control from ASPX Form

So, I've seen many discussions that are in this area, but it seems like they are mostly discussing Windows Forms, or they don't get around to answering this specific scenario enough to point me in the right direction.
Exactly what I need to do (Generic Example):
HTML (fragment.aspx)
<div id="html_fragment_1" runat="server">Contents</div>
<div id="html_fragment_2" runat="server">Contents</div>
...
Code Behind (fragment.aspx.cs)
Fragments fragment = new Fragments();
fragment.return_fragment( AN INSTANCE THAT REFERS TO html_fragment_N );
Class (Fragments.cs)
public void return_fragment ( AN INSTANCE THAT REFERS TO html_fragment_N ) {
string html = INSTANCE.html_fragment_N;
// DO SOMETHING WITH html
HttpContext.Current.Response.Write(html);
}
The reason I need to do this is that every aspx form on my site needs to be manipulated in the same way by Fragments.return_fragment(), where the content for several DIVs need to be read from the Form and arranged into an XElement to be returned.
Instead of doing the manipulation in the CodeBehind for every page, I'd rather have each Form use Fragments.return_fragment() so that it saves effort implementing a new Form page, and the code can be changed easily without having to change it in each Form.
Looks like you want your app's Global.asax file:
http://msdn.microsoft.com/en-us/library/1xaas8a2(v=vs.71).aspx
Look at your app's page events here as a place to specify things that should happen on every page request.

Re-using another page section

I have created a web page that I use as a small dashboard to hold issue or no issue. It works great. The page uses an .aspx and .aspx.cs. I would like to be able to reuse the information on this page on other pages. My site already uses master pages and I have not been able to find an easy way to include this information.
How can I use an include from a page that has coding in the code behind easily?
Typically you use Web User Controls for this.
Web User Controls allow you to package up other controls into one that you can drop onto multiple pages. They are great for common UI items such as address entries, dashboards, etc. Basically anything that needs to be the same across multiple pages.
At the risk of seeming very obvious - do you mean usercontrols. These will allow you to reuse chunks of functionality across your site.
I guess this question falls into two categories: User Controls, and Code Reuse. Not sure which one you are after.
User Controls
If you are talking about the controls on your page you will want to create a common user control.
Code Reuse
You need to create a common class (whether it is static or not depends on how you intend to use it) and define functions within that class.
For instance, lets say you have a page that you want to print "Hello World!" on any aspx/.cs page.
You could do this
public static class MyClass
{
public string PrintHelloWorld()
{
return "Hello World!";
}
}
Then you call it from any of your pages like so:
MyClass.PrintHelloWorld();
Right click on the project > Add New Item...
Select User Control (.ascx)
Put your markup & code behind there.
Then you add that control in any other page (includding other controls [although I wouldn't recommend that])
It sounds like you may want to create an ascx User Control.
http://msdn.microsoft.com/en-us/library/ie/2x6sx01c.aspx

Can't find the function body in ASP.NET

I recently started working on a project that has been in development for some time now. The problem is this - in the web site page, a have a frame (amongst 4 others) in a frameset which contains the SVG map object (the whole site is GIS based). Also, in the same frame, there is a icon for opening the form in which user can choose a number of filters, and after he presses a button, the map refreshes and the area of influence around some key points on the map are drawn.
What i need to do is to open that form in a new (popup) window and not in the same frame where the map is. I did that this way:
onclick="window.open('zi.aspx','form1','width=700,height=500,left=350,top=100')"
This works fine. But then, when i enter the filters and hit Generate button, i get this error:
'parent.frames.map' is null or not an object
with the reference to zi.aspx. Now i know that this error is because i changed the form from opening in the same frame as map to opening it in a popup window, but i just can't find anywhere in the code where can i modify it. Before my changes, the code was just this:
onclick="showZi();"
and that is the function i can't find anywhere. Any ideas? How can i make this work, to make a map with filters drawn after the user has chosen appropriate ones from the popup window form? I should mention that this image link is in the ASP.NET table, with standard runat="server" command.
Okay, so you're opening a new window from javascript. Your problem is that you're trying to access the parent window by using the 'window.parent' property. This is wrong, you'll need to instead use 'window.opener' property. E.g.:
window.opener.frames.map

Create a RibbonControl in code-behind

I'm working on a PowerPoint Add-In project.
I'm trying to create a RibbonToggleButton in code-behind but I can't do it the way I thought,
RibbonToggleButton toggleButton = new RibbonToggleButton();
Is it possible to create RibbonControls in code-behind and not the RibbonDesigner or RibbonXML?
According to the docs:
You can create a RibbonToggleButton at
run time by using the
CreateRibbonToggleButton method of the
RibbonFactory object.
It looks like you get at the RibbonFactory via the RibbonBase.Factory property.
You may also want to look through this walk-through.

SharePoint AJAX C# web part - visual layout of UpdatePanel controls

I'm creating a SharePoint web part in C# that is using an UpdatePanel for some AJAX magic. Everything is working fine, but I'd like to know how to lay out my controls visually (without using SharePoint Designer). I just have two dropdownlists, some labels, a button, and a textbox. I am creating them within the overridden CreateChildControls. Thanks!
add a container panel around your controls and give it a class. Add the panel to the UpdatePanel's container. Add all other controls to the new Panel's Controls.
You can now use css to do your styling, using the container panel's CssClass as reference.
in code:
protected override CreateChildControls()
{
// .. creation of updatepanel, say upd1
Panel container = new Panel{CssClass = "webpartContainer"};
upd1.ContentTemplateContainer.Controls.Add(container);
container.Controls.Add(dropdown1); // etc. etc.
}
The Css:
.webpartContainer
{
/* if needed add some style here also */
}
.webpartContainer select
{
/* add style */
}
.webpartContainer .specificClass
{
/* give controls a class of their own in CreateChildControls
if controls of the same type need different styling
(i.e. you have more than 1 select that need to look different) */
}
there are a couple of ways you can lay them out. you can add a Table object and add rows, cells, etc. and add your controls to the cells.
Alternately, you can override the RenderContents method and output HTML directly to the write that is passed in as a parameter. If you do this method (its probably less work and more efficient then using the Table objects), you should use a StringBuilder to build your HTML then output the results to the writer. This method should gain you some performance.
Sadly, there is no visual WYSIWIG editor for this method.
Unfortunately, there is no visual designer for web parts that are created programmatically.
You can use a user control and the SmartPart web part from codeplex to gain advantage of the visual designer for .ascx user controls.
You can use ASCX files in web parts.. just load it from your webpart class in CreateChildControls like so:
var control = Page.LoadControl("/_CONTROLTEMPLATES/yourproject/your.ascx");
Controls.Add(control);
This way you can use the normal way with Visual Studio to layout your webpart. Much nicer than building HTML in code which is a pain to say the least.
(this is also much better than using SmartPart which causes issues with the trustlevel and deployment)

Categories