Showing posts with label reference. Show all posts
Showing posts with label reference. Show all posts

Wednesday, March 28, 2012

Extender TargetControlId not sufficient enough to reference controls not in NamingContaine

Through reflection i see OnPreRender searches for a TargetProperty's TargetControl via its TargetControlID.
It only searches in NamingContainer of the Control this Extender is contained in.
I need ExtenderProperty to take both a NamingContainer and a TargetControlID so I can extend objects directly
on the page when this Extender may appear in a subcontrol.
Are ther plans to support extending Controls outside of the parent's NamingContainer space?
protectedoverridevoidOnPreRender(EventArgs e){base.OnPreRender(e);if ((this.._page;" href="http://links.10026.com/?link=http://www.aisto.com/roeder/dotnet/Default.aspx?Object=4">_page ==null) && (this.Page !=null)) {this.._page;" href="http://links.10026.com/?link=http://www.aisto.com/roeder/dotnet/Default.aspx?Object=6">_page =newPageWrapper(this.Page); }ScriptManagermanager1 =ScriptManager.GetCurrent(this.._page;" href="http://links.10026.com/?link=http://www.aisto.com/roeder/dotnet/Default.aspx?Object=12">_page);if (manager1 ==null) {thrownewInvalidOperationException("You must have a ScriptManager to use an ExtenderControl."); }Controlcontrol1 =this.NamingContainer;using (" href="http://links.10026.com/?link=http://www.aisto.com/roeder/dotnet/Default.aspx?Object=16">IEnumerator<T>enumerator1=this. Microsoft.Web.UI.ExtenderControl.TargetProperties { ... }" href="http://links.10026.com/?link=http://www.aisto.com/roeder/dotnet/Default.aspx?Object=17">TargetProperties. System.Collections.ObjectModel.Collection.GetEnumerator();" href="http://links.10026.com/?link=http://www.aisto.com/roeder/dotnet/Default.aspx?Object=18">GetEnumerator()) {while ( enumerator1 // Local Variable">enumerator1.MoveNext()) {Tlocal1 = enumerator1 // Local Variable">enumerator1..get_Current();" href="http://links.10026.com/?link=http://www.aisto.com/roeder/dotnet/Default.aspx?Object=20">get_Current();Controlcontrol2 =control1.FindControl(local1.TargetControlID);if (control2 !=null) {IScriptControlcontrol3 =manager1.RegisterControl(control2);control3.RegisterBehavior(this);continue; }thrownewInvalidOperationException(string.Format(CultureInfo.InvariantCulture,"Target control with ID '{0}' could not be found for extender '{1}'.",newobject[] {local1.TargetControlID,this.ID })); } }}

The Toolkit doesn't actually run this code - we have an override that will also search for controls at the page level.

Even if the extenders took a NamingContainer property, it doesn't fix the problem. NamingContainers can be nested, so you could end up in the same situation where you can't find the naming container.

In the May 4th release of the Toolkit, we added a "ResolveTargetControlID" event that you can handle to do these types of resolutions yourself. The if the extender can't locate the Control referenced by TargetID, this event will fire and you can return the control instance.

Monday, March 26, 2012

Exposing Web Services defined in class libraries

I have a class library (or will have) that defines a bunch of web services. I can reference Atlas if necessary. How do I expose all these web services to Atlas via IIS/ASP.Net. In other words, I do *not* want the code for my web services to be in the web project, I want them to be in an external project and optimally just included with a single line for all services, or a line per service if necessary.

Thanks.

All you need to do is to add your assembly as a reference to the web project and then add it to the ScriptManager service reference as following:

 <atlas:ScriptManager ID="ScriptManager1" runat="server" > <Services> <atlas:ServiceReference Type="namepsace.typename" /> </Services></atlas:ScriptManager>

Replace the bold text with the type name of your web service.


Seems that this has changed since way back when... How do I reference a service in a class library now? How do I then hook it up to an extender, e.g. an AutoCompleteExtender?

Thanks.

Execute JS Code onload and on partial postback

Hi All,

I have a ScriptManager tag that contains a script reference to a JS file; "test.js." Test.js contains a function that needs to be executed on the application's loadand on a partial postback.

The reason that it needs to be executed on the application's load event is because if I execute it just using RegisterStartupScripts the script isn't present on the page yet because it is being controlled by Atlas.

So, I create a wrapper function for statement on the fly and I register it to execute on the application's load event. I.e. "Sys.Application.load.add(wrapperFunction);"

That works great the first time through when the page is loaded because the application's load event fires. However, how do I get the same execute statement to fire on a partial postback? The only workaround I have right now is to get a handle to the current ScriptManager and test to see if it is InPartialRenderingMode. If so, I don't do the add to load code, but I just register a startup script instead.

Is there a nicer, easier, cleaner way of doing this.

Thx!!Hi,

I think I have a decent workaround for the moment. My example I was providing was a bit simplistic in comparison with what I actually need to do. I actually needed to completely change what JavaScript commands were executed and their parameters for each time a server side control was loaded. Having said that, the best way I've come up with so far is test on the backend if my ScriptManager is in PartialRenderingMode and handle it accordingly. If it isn't, I use the load event and attach a delegate to execute. If it is, I just execute a the function that was to be the delegate. It's not the prettiest code, but it works reliably and can be repeated for other controls.

Thanks for your help on this.

I need to do the same thing. How did you get it done?

I have a myfuncs.js in the script manager.

I want to call a function in the js file after a updatepanel psotback.

I can not find a good way to fire it. I thought Application.Load would do it but the page only gets loaded once.

and ideas?


I kind of do what I described a few posts back.

I test to see if the control's ScriptManager is in PartialRenderingMode and if so, I just emit the JavaScript straight to the client using the ClientScriptManager.RegisterStartupScript method. If it is not in PartialRenderingMode, I wrap my JavaScript in a function and add it to the Sys.Application.load event and then emit the whole code block to the client again using the RegsiterStartupScript method.

Ex of what it would look like on the client.

function WrappedFunction() {
var x = new Array();
x.push(1);
}

Sys.Application.load.add(WrappedFunction);

OR

var x = new Array();
x.push(1);

HTH

hello.

since the file is already loaded, how about adding an event handler to the propertychanged event and check? there you could check the property that's changedand if it's the inPostBack property and its value is false, you know that you've just finished loading the page. btw, why can't you use the registerstartupscript method? i don't understand what you mean when you say that the script is being controlled by atlas...


Hi.

By "script is being controlled by atlas" I mean that the script file is registered with the ScriptManager.

I.e.
<atlas:ScriptManager ...>
<scripts>
<atlas:ScriptReference path="test.js" ...>
</ ..>
</..
The reason that the script needs to be registered with Atlas is that the function I need to execute on startup and postback has code within it that relies upon the Atlas Sys namespace and therefore must be loaded after the Atlas scripts have been loaded otherwise it'll throw an error complaining it doesn't know what Sys is. (The statement also relies on user input which is the reason it needs to get reexecuted on postback.)

It is my understanding that the page processes any <script ...> tags including any startup scripts first; then loads the Atlas scripts; then loads the scripts that are defined within the ScriptManager Scripts tag.

So, if I just use the RegisterStartupScript method and my scripts are registered with the ScriptManager, my startup statement will execute before the Atlas files (and my custom js file) have been loaded and throw an exception. My code needs to wait for the Atlas files and my custom js file to load before executing so instead, I add the startup statement to a function and add it to the Sys.Application.load event delegate as an event handler. This way it'll wait until Atlas has loaded before executing.

This works fine for the load, but one of the function's parameters is based upon user input and the function needs to be reexecuted whenever the page is postbacked.

The first time through the code looks like

function wrapperFunction () { testFunction (''); }
Sys.Application.load.add (wrapperFunction);

But, on postback the same part of the code would look like

function wrapperFunction () { testFunction('30111'); }
Sys.Application.load.add (wrapperFunction);

Of course, the second code block doesn't do anything on postback because the load event has already fired. To accomplish the same thing on postback the code would just look like:

testFunction ('30111');

as the test.js file where testFunction lives has already been registered and now can be accessed through startup scripts.

(All code blocks are registered to execute on startup.)

I'm not really seeing how I can do what you suggested and add an event to the PageRequestManager as my function call needs to change based upon user input.

So I can test for InPartialRenderingMode in code behind and modify the startup JavaScript accordingly (which is what I'm currently doing), but it seems that there needs to be an event that covers both loading initially and loading after a postback. Emitting a pure JavaScript function call works for postbacks and attaching to the load event of the Application works for loading initially, but I'd like to be able to write one piece of code that works for both cases.

Phew ... I hope that's at least partially clear.

Thx for any and all help.

hello.

yes, now i understand.

handling the propertychanged of the pagerequestmanager is the only way i know to handle the end of partial postback.

what you could do is inject a global variable with the value that you need to pass to your jscript function; since the registerXXX inserted method will be called before the event being fired, you can be sure that the global variable will allways be correctly set up.


To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal

Wednesday, March 21, 2012

Errors after Installing RC1 and the Dec CTP

Getting this one again: The type or namespace name 'UI' does not exist in the namespace 'Microsoft.Web' (are you missing an assembly reference?)

The following that I have checked:

1.) Made sure the System.Web.Extensions.dll was in the bin folder

2.) Copied and renamed the Web_CTP.config file to web.config and added it to my project

Anyone else hit this?

Make sure the dlls are in the GAC
Dropped them in the GAC, still no love.

Rick

Last step I know, check your web.confighttp://alpascual.com/blog/al/archive/2006/10/24/Manually-upgrading-from-Atlas-to-ASP.NET-2.0-Ajax.aspx


Little more information:

Created a new website for kicks on the same machine using the Ajax CTP Template. Works fine. Did a diff on the two web.config files and the only difference was:

<buildProviders>
<add extension="*.asbx" type="Microsoft.Web.Preview.Services.BridgeBuildProvider"/>
</buildProviders>

Took this out because it can only be placed in the top level of the site. Is there a problem with using this web.config file or adding AJAX specific settings in a folder below the root? I originally had all of this stuff in the top level web.config file, but was causing the problems described above so moved it ot the folder in which my ajax code was located.


It sounds like your referencing "Microsoft.Web" in your code somewhere (markup or code behind). The namespacing has all changed, so you'll need to modify all your existing references accordingly.
No references to that NS anywhere...
No references to that NS anywhere...
hello.

you're?talking?about?a?top?web.confg?file...are?you?saying?that?your?app?is?a?subdir?of?another?web?app??if?so,?then?you?should?make?sure?that?your?top?web?app?is?configured?to?use?asp.net?2.0?and?the?ajax?entries?should?be?put?in?that?top?condig?file.

another thing you should do: check for the scriptresourcehandler. make sure it's on your web?.config file. if this still doesn't solve your problem, use fiddler to see what you're getting from the server and then let us know.
MS changed the namespace in RC1 to System.Web.Extensions, this might be your problem. I had old statements in web.config from Beta 2 for Microsoft.Web.Extensions. I changed it to System and wham, it works. Give it a whirl.