Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Monday, March 26, 2012

Installting AjaxExtensions

Hi Friends,

I have been working with ajax now since last 3 months. I have applied in one project and works fine. I am trying to using it in another place and trying to use it in another project. Unfortunately i am not able to apply ajax successfully. I have run the setup file. I installed AjaxExtensions, i tried to test it on one page by putting a normal button inside updatepanel, to see if it is getting refreshed. But on the pageload itself i see javascript error ' Sys' is undefined. I believe its the error from Register Assembly?

I have included all the necessary details in my web config file also.

I dont know where am i doing wrong? Any suggestions would be appreciated.

Thanks

Menon

Did you start with a new website using the Ajax-enabled Website template? Or are you just trying to add some Ajax to a previous web app? If it's the latter, you need to make some changes to your web.config, in addition to installing the extensions.

http://www.asp.net/learn/ajax-videos/video-81.aspx


http://www.asp.net/AJAX/Documentation/Live/InstallingASPNETAJAX.aspx

Configure your AJAX like this

http://www.asp.net/AJAX/Documentation/Live/ConfiguringASPNETAJAX.aspx

Intellisense!

Hello Everyone,

I am trying to get my feet with the Atlas UI controls.

I could not get the intellisense working for the Sys.UI controls. Am I doing something wrong or is there no support currently for intellisense?

Regards,

Hi,

nothing wrong, there's no support for intellisense at the moment.


Thanks Garbin...

Saturday, March 24, 2012

Internet Explorer Mobile & ATLAS

Hi all,

I have a webservice and ASP.NET ATLAS enabled, and working with IE6. There is not ATLAS controls, it is very simple call from javascript, passing 3 arguments.

I am tying to make it works in Internet Explorer Mobile in a Smartphone with Windows Mobile 5.0, but when I press the button, nothing happens...

In theory, Explorer Mobile supports HTML 4.01 CSS and Extensible HTML (XHTML), and XMLHTTP Request...

Have any try this or something with similar scenario?

Thanks in advance

David

I don't believe the mobile version of internet explorer supports the xmlhttprequest object or has any AJAX support for that matter.

Please, see this bloghttp://blogs.msdn.com/iemobile/archive/2005/11/15/493200.aspx

If IE Mobile supports AJAX and this sentence
xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
, I can't undestand why ATLAS will not support IE Mobile....

This is the function inside WebResource.axd generated by ATLAS that creates XMLHTTPRequest object

window.XMLHttpRequest = function() {
var progIDs = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ];

for (var i = 0; i < progIDs.length; i++) {
try {
var xmlHttp = new ActiveXObject(progIDs[i]);
.....

Very similar no? I think that is imperative that ATLAS works for IE Mobile...


hello.

i really don't understand much about mobile devices...is there any sniffer that can capture the traffic between the browser and the server? (something like fiddler, that is)

Internet Explorer Settings

I'm working on an application which we're trying to use some basic Atlas features in. When running our application in Visual Studio 2005 and when we access it on the production IIS server from our computers everything works fine. The problem is our clients have hardened systems (we can't even see what options are enabled/disabled in Internet Explorer) and when they try to use our application, the Atlas does not work, it does a full post-back/refresh. I also test the Atlas Control Toolkit demo site on their system and the CascadingDropDown controls didn't even populate. Has anyone seen this before or have any idea what Internet Explorer options need to be enabled in order for Atlas to work correctly? I also don't think it's an Ajax problem because Telerik controls work fine on their system, Atlas is the only problem. Thanks a lot!

Thanks,

RobBump...

Wednesday, March 21, 2012

Is it possible to "redirect"/URLrewrite ScriptResource.axd?

Hi,

I'm currently working on a project where the client is using a Third-party tool for handling authentication to the website. This means problem because we cannot exclude more files than Default.aspx in the root of the website. The rest of the "unsecure" files needs to be in a special folder. If I look at the source for Default.aspx I see the following (which I understand is AJAX resources?):

<script src="/MySite/WebResource.axd?d=..." type="text/javascript"></script>
<script src="/MySite/WebResource.axd?d=..." type="text/javascript"></script>
<script src="/MySite/ScriptResource.axd?d=..." type="text/javascript"></script>
<script src="/MySite/ScriptResource.axd?d=..." type="text/javascript"></script>

I need to include this resources from another URL. Like this:

<script src="http://pics.10026.com/?src=/MySite/unsec/WebResource.axd?d=..." type="text/javascript"></script>
<script src="http://pics.10026.com/?src=/MySite/unsec/WebResource.axd?d=..." type="text/javascript"></script>
<script src="http://pics.10026.com/?src=/MySite/unsec/ScriptResource.axd?d=..." type="text/javascript"></script>
<script src="http://pics.10026.com/?src=/MySite/unsec/ScriptResource.axd?d=..." type="text/javascript"></script>

Is this possible to do?

regards // Magnus

Hi,

I have tested it with the following code:

Overriding Page.Render and replace the string.

<%@. Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text;
}
protected override void Render(HtmlTextWriter writer)
{
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
base.Render(htw);
string s = sw.ToString();
s = s.Replace("/AJAXEnabledWebSite3/WebResource.axd", "/AJAXEnabledWebSite3/Secure/WebResource.axd");
writer.Write(s.Replace("/AJAXEnabledWebSite3/ScriptResource.axd", "/AJAXEnabledWebSite3/Secure/ScriptResource.axd"));

}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

ThenI received "sys is undefined" error,I think it is because there is no WebResource.axd created in that sub folder, So how to tell ASP.NET to create WebResource.axd in that folder rather than at the root? See following for answer:

AJAX's script handler is performing path check. Hence it is blocking our trick:

Declaring Type: System.Web.Handlers.ScriptResourceHandler
Assembly: System.Web.Extensions, Version=1.0.61025.0

private static void CheckPath(string path)
{
if (!string.Equals(path, VirtualPathUtility.ToAbsolute("~/ScriptResource.axd"), StringComparison.OrdinalIgnoreCase))
{
Throw404();
}
}

To workaround this further, we can:

1. With IIS, create the "Secure" folder under the root directory of our web application (e.g. "C:\Inetpub\wwwroot\AJAXEnabledWebApplication\Secure").

2. Use IIS Configuration Tool to create an child Application for the "Secure" node:

IIS 7.0 Beta: Add a Web Application
http://technet2.microsoft.com/windowsserver2008/en/library/7450f8c5-8d46-4bb2-bd59-4e6ff23df3201033.mspx

The purpose of this is to workaround the virtual path check mentioned above.

3. Open the Web.Config of the application and configure the machine key:

<system.web>
<machineKey
validationKey="0000000000000000000000000000000000000000"
decryptionKey="0123456789012345"
validation="SHA1"/>

This makes the encryption/decryption mechanism consistent between our root application and child application.

4. Apply the code change mentioned previously.

This should work.

This should work.

Best Regards,

Is it possible to add a ScriptManager to a page dynamically?

As per the title, is it possible to add a script manager to a page from code?

I have it working OK if the UpdatePanel is also created in code (explicitly after the script manager is created) but not if the UpdatePanel is defined in the aspx template. In that case, if I put my code in "OnInit", the page raises an exception saying that "the Script manager needs to be added (to the page's control tree) before the UpdatePanel", whereas if I move the code to "OnPreInit" then the controls collection is not even created yet.

In other words, adding the Script Manager "OnPreInit" is too early but adding it "OnInit" is too late IF the UpdatePanel is defined in the aspx.

The reason I'm asking is that it would be nice to be able to write controls that could detect if the Page they are hosted in has a Script Manager (or proxy?) and if not, and if they need to use AJAX, then the control can add one, theus removing this dependancy and "knowledge of the implementation" from the client using the control.

Any ideas?

Many thanks

I use a simple workaround-- add a property that says UseAJAX (boolean), and in the XML documentation for the control I say that if the control is on a page with a ScriptManager, or in an UpdatePanel, to set this value to true.

Then the control takes this into account when instantiating and building the control structure, as well as when registering scripts.


OK thanks, that would be OK - obviously this is something you've already come across and worked around.

I did have some ideas on these lines myself, like having an IAjaxControl interface that had a method like "EnableAjax()" that would create & append the UpdatePanels to the control - one of the reasons being that the UpdatePanels, once created and added to the control tree CANNOT be moved so if the client wants to take the control and move it to another part of the tree then it will cause an exception. Having the method, rather than a property, gives the client some control as to WHEN to trigger the creation of the Ajax components (ideally after the control tree is "set in stone").

With hindsight, I think I like your idea of a simple boolean property (but defined in the IAjaxControl interface) and always create the UpdatePanels in the OnLoad (if the boolean is true) rather than beforehand - hopefully then the control tree is final and we are safe to do it, and the GUI designer can support the boolean property withought the need for coding from the client.

I felt the interface was needed for scenarios like where a different control CONTAINED your Ajax enabled control - it too would then need to support the property (and pass it down to your control it was containing).


Did you find a solution (Like you, I try the OnInit and the PreOnInit) ?

All my pages inherits the same class (let's say PageAncestry). I want to add the scriptmanager with code in PageAncestry so all my pages will automatically be able to use ajax.


After some google search, I finally found a solution on this page http://www.capdes.com/2007/02/microsoft_office_sharepoint_se.html

Add the ScriptManager in the PreInit at the HtmlForm first position :

Private Sub Page_PreInit(ByVal poSender As Object, ByVal poArguments As System.EventArgs) Handles Me.PreInit

' Get current ScriptManager if exist
Dim oScriptManagerAjax As ScriptManager = ScriptManager.GetCurrent(Me)
' If not exist
If oScriptManagerAjax Is Nothing Then
' Create one
oScriptManagerAjax = New ScriptManager
' Get page form
Dim oForm As HtmlForm = Me.Form
' If form present
If Not IsNothing(oForm) Then
' Add it at first position
oForm.Controls.AddAt(0, oScriptManagerAjax)
Else
' Manage if not (impossible to use Ajax)
End If
End If


End Sub


Hmm, from what I was saying:

"whereas if I move the code to "OnPreInit" then the controls collection is not even created yet."

and yet, in "PreInit" you have code:

oForm.Controls.AddAt(0, oScriptManagerAjax)

Are you sure thius works? According to my original post "oForm.Controls.Add" should have raised an exception as the "Controls" collection is not yet created. Are you sure your code works?

My page also uses a MasterPage - does yours? Does that make a difference (i wonder??)

I'll give it a try tomorrow. Thanks for the post :)


Yes it's working for me.

I don't have a master page, so I don't know if it's working with.

The most important thing is theControls.addat(0, it put the ScriptManager before all other controls define in the form (even the one in design). It's not working if you use only Controls.add


I'm pretty sure that "Controls.AddAt(0..." is what I was using before - as I said though, I believe the "Controls" collection was null at PreInit.

Anyway, I will try again and post my results :)


No mate, this just doesn't work, not in C# anyway.

The isssue is as before but I was mistaken, it's not the Control collection that is not created, it is the Form object itself.

Here is my ASPX Template:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Page2.aspx.cs" Inherits="Page2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> Page 2<br /> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

And here is my code behind:

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partialclass Page2 : Page{protected override void OnPreInit(EventArgs e) {// Pop a script manager on the page if one does not yet exist. ScriptManager scriptManager = ScriptManager.GetCurrent(this);if (scriptManager ==null) { scriptManager =new ScriptManager(); HtmlForm form =this.Form;if (form !=null) form.Controls.AddAt(0, scriptManager); }base.OnPreInit(e); }protected void Button1_Click(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToLongTimeString(); }}

As you see here, if "form" is null we can't add the script manager, and this.Form IS null at "PreInit":

if

(form !=null)
form.Controls.AddAt(0, scriptManager);

The only way I could get this to work is doing it in the "Onint" where the ScriptManager is created first and then the UpdatePanel created IN CODE afterwards (NOT defined in the aspx). Unfortunately, defining the Update Panel in the aspx means that "Oninit" is too late to add the script manager, but "PreInit" is too early as the form is not yet created.

Please tell me I'm wrong about this - how have you got this to work? I don't get it. Can you post your ASPX & VB code?



Not works!!!

Obviously the code is in the OnInit andnot in OnPreInit at http://www.capdes.com/2007/02/microsoft_office_sharepoint_se.htmlSmile

I think the msdn documentation not correct about the preinit event, this is an excerpt of my offline msdn library (seeit online):

PreInit

Use this event for the following:

Check theIsPostBack property to determine whether this is the first time the page is being processed.


Yes stmarti, although I think the documentation is (technically) correct in that you can CREATE controls at OnPreInit but you CANNOT add them to your Form, as it does not yet exist!

If you do this in OnPreInit:

Label label =newLabel();
label.Text ="Hello PreInit world";
this.Controls.Add(label);

and you'll see that the label ends up rendering AFTER ALL HTML MARKUP!!!! (ie was added to the control tree FIRST, then the Form was Added AT(0) with all real content then added to the form - leaving your poor Label "out in the cold".

So if the Form is not yet created at OnPreInit, I can't see how the VB code posted above could work.


Just tested this:

Private Sub Page_PreInit(ByVal poSender As Object, ByVal poArguments As System.EventArgs) Handles Me.PreInit

' Get current ScriptManager if exist
Dim oScriptManagerAjax As ScriptManager = ScriptManager.GetCurrent(Me)
' If not exist
If oScriptManagerAjax Is Nothing Then
' Create one
oScriptManagerAjax = New ScriptManager
' Get page form
Dim oForm As HtmlForm = Me.Form
' If form present
If Not IsNothing(oForm) Then
' Add it at first position
oForm.Controls.AddAt(0, oScriptManagerAjax)
Else
' Manage if not (impossible to use Ajax)
End If
End If

End Sub

And it works.... only when you havealreadya scriptmanager in the aspx. Obviously this code in real do nothing special because:

- if you have already a scriptmanager on the page the code does nothing, and your page is just fine...

- if you have not a scriptmanager in the aspx, the following code

' Add it at first position
oForm.Controls.AddAt(0, oScriptManagerAjax)

neverwill be executed because oForm is null in preinitSmile! Anyway your page will throw exception and cry for a scriptmanager...


VR2:

Yes stmarti, although I think the documentation is (technically) correct in that you can CREATE controls at OnPreInit but you CANNOT add them to your Form, as it does not yet exist!

You are right. Technically it's correct. The doc (at least this entry in msdn) suggest preinit for creating dynamic controls, and init for setting control properties. This is not true for the form's controls, would be nice a remark about it in the future.


I try your C# code and it's not working :(

But I found the difference with my vb code :) (I can't post it, it's included in a bigger class)

I use FindControl to search the Form !

Just change the OnPreInit in your code by this one and it's workingBig Smile
protected override void OnPreInit(EventArgs e) { ScriptManager scriptManager = ScriptManager.GetCurrent(this);if (scriptManager ==null) { scriptManager =new ScriptManager(); Control oControl =this.FindControl("Form1");if (oControl !=null) { oControl.Controls.AddAt(0, scriptManager); } }base.OnPreInit(e); }

It works!!! Like thisBig Smile:

protected override void OnPreInit( EventArgs e )
{
HtmlForm form1 = ( HtmlForm )this.FindControl( "Form1" );

ScriptManager temp = new ScriptManager( );
temp.EnablePageMethods = true;

form1.Controls.AddAt( 0, temp );

base.OnPreInit( e );
}

Great work gbarry! The problem solved and the answere for:

Is it possible to add a ScriptManager to a page dynamically?

is:yes! Yes