RadToolTip's RenderControl method - c#

I have an asp.net application which uses the web part framework to allow users to customise their interface. One of the features of this is a catalog of available web parts, one is provided by default, but it can be overriden if you wish to change the layout, etc.
override void RenderCatalogPart(HtmlTextWriter writer, CatalogPart catalogPart)
That, as far as I can tell, is the only way to do it. At the moment I'm creating a panel with all the necessary elements in it, and using the panel's RenderControl method to output it to the htmlwriter. So far, so good. The problem occurs when I try to add a radtooltip to my panel, using the same RenderControl method, and I get the following runtime error:
Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request.
I can see why this might be a problem, since the tooltip presumably uses javascript and has to write it to the page - but the RenderCatalogPart method has no knowledge of which page it's going to be outputting to. Is there any way around this or am I going to have to come up with an alternative?
I've posted this on the telerik website but though I'd ask here as well incase anyone has any ideas.
Thanks.

The Telerik ASP.NET controls require a MS AJAX ScriptManager control. I suppose that's why they want to access the page as well - to get a reference to the ScriptManager. Try setting the tooltip's RegisterWithScriptManager property to false and see if the control renders then.

The issue here is that the ToolTips must be created and added as controls in PreRender, so that it can add it's script to the ScriptManager.
Creating a collection of tooltips in the PreRender() method and then writing them to the httpwriter as shown above in RenderCatalogPart fixes the problem.

Related

Awesomium webcontrol

So I've been trying to use something other than IE for my webcontrol in a side-project of mine (C#, WPF project type) and I was looking around for alternatives and have tried in the past but failed to implement them.
I decided to try again and implement awesomium, however it is still confusing as always and doesn't have any straight forward examples for me to use as a base.
Would someone be able to show me how to implement awesomium for a webview/webcontrol? My vision is to have it navigate to a shoutbox website, and while my application is still open to keep it there (i.e not refresh it so that it doesn't lose anything) as it is being shown in the space of tabitem.
I have used Awesomium, but the last version I used was 1.6.1, and there are some differences between that and the current version - they've actually made things easier.
The documentation says that you should be able to force navigation of the control simply by setting the Source property:
<osm:WebControl Name="webControl"
Source="http://www.google.com/"
/>
If you find the Source property is not bindable then simply revert to using some code behind in the view - subscribe to a property change event from the viewmodel (or from an event broker if you are using one), and change the Source property in response to an event.
I believe, the problem with the Source property is that if you are setting it to the same URI to refresh, it won't refresh because of a bug. It is documented on their github page and their answers page.
As workaround, to refresh your page correctly you need to pass a fake URI first and then your page again to your binding property, like this:
CurrentSource = "FakeUriString".ToUri();
CurrentSource = "http://www.yourpage.com".ToUri();
Keep in mind, my current version of Awesomium is 1.7.4.2 and they may fix this issue in the future as they stated in their issues page.

iframe not Rendering in .NET ReportViewer Web Control

I have a .NET Webform ReportViewer control. When I run it locally everything is fine. But when deployed to a server it won't render. debugging on the browser shows that the iframe that handles everything is simply not present.
this is all in a custom control that was here before my time. So basically when the render method is called the custom control adds the controls to a panel control, then uses the HTMLWriter class so create a div, calls .Render() and then passes in the HTMLwriter. I used string comparison to see if the iframe was somehow being sanitized(for security) by the browser, but it is not. I have verified the server has v 8,9, and 10 of both ReportViewer.Common and ReportViewer.Webform. I have tried referencing all of these in my web.config and msproj references and still no joy. Its the weirdest thing, same microsoft library, 2 different boxes, writes two different HTML strings.
Anyone seen anything like this. I have definitely checked through SO and found most of it has to do with the missing assemblies from the GAC, but I am seeing all of them present. Environment issues are so frustrating!
So it looks like this was an environment issue after all and had nothing to do with the code. The custom control that contained the report viewer control was blocking it from allowing errors to bubble up since it was directly writing the render to HTML. It turned out to be Report Server permissions.

No way to interact with controls through webmethod?

I'm starting to believe there is no way for me to interact with asp controls from within a webmethod. I wouldve thought i could some how accomplish this, by finding the page the webmethod was called from, and from there find and update controls on the page.
But after having an open question for 3 days and numerous google searches, it seems that there is no way for me to do this.
Or is there? I would really appreciate if someone could provide some useful information for me on this matter.
The problem is quite simple from a perspective.
1. I'm calling a webmethod through ajax, this is happening on say page A.
2. After a succesful ajax call, i wish to update an ASP control on page A.
3. The update of the ASP control must happen without a postback hence the ajax.
Is this really impossible?
Also if you know anything about this matter, but you don't understand my question, please have a look at my other active question: Update object on masterpage through ajax webmethod
When you call a webmethod, what happens is quite different compared to a button click for example in asp.net webforms.
The webmethod doesn't construct all the controls as a standard click event does.
So that's why you can't have access to the page controls.
Also, how would this work even if you had that access? Your webmethod only sends back some data, not the entire html code, so there's no way to update a control's value server side, since it has to be rendered in html.
If you want to update the value of a control on the client side (webbrowser), you can only do it via javascript when you receive the result of your webmethod. You only have to find the control by its id, and update its value.
For more information, you can look at this post:
What's the ASP.NET Webservice request lifecycle?
Another way to achieve what you want to do is to use the UpdatePanel. I personally don't like it, but it lets you access all the controls that are inside it, and update their values.
This control takes care of the client side update via javascript (but it actually replaces big parts of html in the page so it might be quite slow)
Calling a web method via AJAX has no impact on the HTML that has already been rendered to the browser.
What you'll need to do is return some information from your web method, and when the AJAX call completes, use jQuery to modify the appearance of the screen using the new information.
If what you're doing in the web method would result in a big change, one that you couldn't easily make happen in jQuery (such as re-rendering a GridView) you might want to look at UpdatePanels.

Should I Use User Controls If I'm Not Going To Reuse The Code?

First of all, I hope I'd get some advice about my practice because based on the very few books I've read, they didn't write much in the aspx page..they just built some controls and used them in the aspx page, so is this approach a good practice ?
here comes my question, I thought using web controls instead of directly writing into .aspx page is better as I could reuse the code, but now I'm creating those controls and I don't think I'll reuse them again or maybe only just one more time.
so do you think it's wise to create a control for the code instead of directly coding in the .aspx page ?
I was also working on a web user control for adding a new item to my db, and then I started planing for the update or edit control..I thought maybe I'd use the same control for both add and edit and start reusing my code, and on my way editing the control to be able to function as both add and edit control, I started with adding properties to the control, then a couple assignments in the Load method, then some checks with if...So I realized maybe a new control would be better!
I don't know, I'm thinking intuitively but I could really use a professional, experienced point of view.
Thanks for your time =)
Sometimes creating a user control, allows you to encapsulate some specific logic and ui elements into a separate class. Even if you are not reusing the control, the final code may be simpler to read and maintain. Take by example a Login control, if you take login related decisions in the user control and make those 'details' hidden in the rest of your code, then the code get simpler and easier to read and mantain!
If you're not going to reuse the code, then you don't want a user control or any other kind of control. Just put the appropriate code and controls onto the page.
If you find later that you do want to reuse it, then you can make a user control out of it.
If you know for sure that you are going to want to use a control (or some slight variation) then creating the user control is a no brainer.
For me, if it occurs to me that I may need similar functionality again in some future project then I will sometimes create a control just because I think it will be useful.

Silverlight - Dynamically creating controls without any postbacks

Can I dynamically create controls in Silverlight without a postback to the server (even an asynchronous one). Does silverlight drag-n-drop requires postback?
I'm asking this because I've an asp.net application where I dynamically create/delete lots of controls. So after the postback I'm getting error with view state stating that the control tree doesn't match the view state tree.
Can I avoid such problems in Silverlight?
everything done in a silverlight control/application happen on the client. web service calls if any happen asynchronously. thats on of the advantages of using silverlight
Yes you can add controls dynamically to pages, without a round-trip to the server.
Drag-drop is also executed client-side.
Think of Silverlight as more like a desktop app, that talks to the server only to get/save data.
Adding controls dynamically in Silverlight is as simple as newing the appropriate control class and inserting it in the render tree (e.g. by adding it to a parent control).
Here is an example: http://asd.murven.com/blog/post/2009/10/16/Silverlight-Adding-controls-dynamically.aspx.
However, I would not suggest switching to Silverlight just to kill this bug. Only if you have a real need for a client-like application instead of a real web application. ASP.NET is suitable for dynamically creating controls as well. Please remember to initialize the control on the server during each postback. If this doesn't help, I would suggest you to submit a description of your problem with some code to help us solve it with you.
Br. Morten
The vast majority of what goes on in Silverlight involves no postback. In fact, I'd say Silverlight represents a completely different mindset. Whenever there IS a postback from Silverlight, it will almost always be asynchronous, and there is no "view state" that the server needs to worry about. In my opinion, it makes ASP.NET look like a joke when it comes to writing web applications.

Categories

Resources