Showing posts with label beta. Show all posts
Showing posts with label beta. Show all posts

Wednesday, March 28, 2012

Page.ClientScript.RegisterStartupScript in Ajax beta 2

----Code in Module (app_code) folder

Public Sub ShowMessage(ByVal msg As String, ByVal ObjPage As Page)

Try
Dim RegKeyname As String = "infmsg"
If ObjPage.ClientScript.IsStartupScriptRegistered(RegKeyname) Then

RegKeyname = RegKeyname & Now.GetHashCode.ToString("x")
Else
RegKeyname = "infmsg"
End If

ObjPage.ClientScript.RegisterStartupScript(ObjPage.GetType, RegKeyname, String.Format("alert('{0}');", msg), True)


Catch ex As Exception

End Try

End Sub

----------

I used to call this function from any of my asp.net Pages to display an alert message this worked till atlas july ctp now it doenst seem to work in ajax beta 2.

Note : This worked in Normal Pages as well as Pages having an Update panel

Any one any clue ... how to get it back to work

Hi Asifsolkar

I think you should use ScriptManger'sRegisterStartupScript method. There was change between CTP and BETA versions of ASP.NET AJAX ext.

(seehttp://ajax.asp.net/docs/mref/8b90a607-02c9-3c22-6cec-4628c98ccd25.aspx )

Have a nice day

Milo

Monday, March 26, 2012

PageMethods is undefined

When using the July CTP, I was able to use the PageMethods defined in my web page with no problems.

After loading the beta 1.0 release, I get the error "PageMethods is undefined" when attempting to use WebMethods from my page.

The "Change from the CTP" docs mention that this has been changed to use static page methods and that it's supposed to be easier now. It would be very helpful to see a working sample using PageMethods in the most recent beta release.

Anyone have a working sample?

Ken

hello.

here's a quick test i've written

<%@. Page Language="C#" %>
<%@. Import namespace="LivroAtlas"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
[System.Web.Services.WebMethod]
public static Aluno[] ObtemAlunos()
{
Aluno[] alunos = new Aluno[]{
new Aluno( "João", 15 ),
new Aluno( "Rita", 16 ),
};

return alunos;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="manager" />
<input type="button" value="invocar método da página" onclick="handle()" />
</form>
<script type="text/javascript">
function handle()
{
PageMethods.ObtemAlunos( handleCallback);
}
function handleCallback( res )
{
for( var i = 0; i < res.length; i++ )
{
alert( res[i].Nome + "-" + res[i].Idade );
}
}
</script>
</body>
</html>


Thanks very much, Luis.

I had missed that page methods are now required to be static.

Ken


Could someone please bring back the old PageMethods, when it could access the page control's value, that was great.

hello.

use updatepanels for that and set the childrenastrigger to false so that you don't send back html to the client. there's no need to have pagemethods without them being static.can anyone provide a good scenario where non-static page methods are really the only way to go?


I'm actually using the PageMethod object so that when a user presses an image button, it calls a server side method that pulls values out of session state as well as control values and then makes a call to a back end software that does some processing for our application and returns an object that we then load into a treeview. However, you are not able to reference Session variables from static methods neither are you able to reference controls. This is my example...do you think i'm doing it wrong or do I have a valid scenario?

hello.

how about using an updatepanel or a web method? you do say that you need to refresh the UI...btw, i do think that you can access session state from a static method:

<%@. 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">
[System.Web.Services.WebMethod]
public static int O()
{
HttpContext ctx = HttpContext.Current;
ctx.Session["i"] = Convert.ToInt32(ctx.Session["i"]) + 1;
return Convert.ToInt32( ctx.Session["i"] );
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

if (!this.IsPostBack)
{
HttpContext ctx = HttpContext.Current;
ctx.Session["i"] = 0;
}
}
</script
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="manager" />
<div>
<input type="button" runat="server" id="bt" onclick="handleClick()" />
</div>
</form>
<script type="text/javascript">
function handleClick()
{
PageMethods.O(function(res){ alert( res ); });
}

</script>
</body>
</html>

that sample simple returns an int. maybe you can adapt it so that it returns what you need.


This is odd, but I can't seem to get PageMethods to call when the WebMethod is in a codefile. I didn't have a problem with that before. Any thoughts? The exact same code works fine if the WebMethod is part of C# embedded on the page in script tags as Luis has done. I really prefer it the way I had it before, as I prefer using codefiles.

"C#"-->"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> [System.Web.Services.WebMethod] public static string Test() { return "Success"; }</script><html xmlns="http://www.w3.org/1999/xhtml" >"Head1" runat="server"> "form1" runat="server"> "server" ID="manager"> "button"value="invocar método da página" onclick="handle()"> "text/javascript"> function handle() { PageMethods.Test(handleCallback); } function handleCallback( res ) { alert( res ); }

On the other hand, it doesn't work like this:

"C#" AutoEventWireup='false' CodeFile="Default.aspx.cs" Inherits="_Default"-->"-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >"Head1" runat="server"> "form1" runat="server"> "server" ID="manager"> "button"value="invocar método da página" onclick="handle()"> "text/javascript"> function handle() { PageMethods.Test(handleCallback); } function handleCallback( res ) { alert( res ); }using System;using System.Data;using System.Configuration;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 _Default : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e) { } [System.Web.Services.WebMethod]public static string Test() {return"Success"; }} 

There is a bug in the beta build that prevents codebehind page methods from working, just incase requiring static methods weren't already going to make them useless enough..Wink... you have to include them in the aspx file if you want to use them...

See this post for more detailhttp://forums.asp.net/thread/1435443.aspx


hello.

jkolbo is right ony about one thing: there's a bug in the beta build and you can't put them in the code beahind file.

regarding the second part, i will not repeat myself and try to explain (once more) why the old instance page methods sucks...this time, i'll just say why the new static methods are good for. in previous releases, if you didn't want to use page methods due to the performance penalties associated with them, you'd have to use web services. static page methods lets you get the some thing without having to develop webservices


Hi,

Just because someone doesn't want to develop webservices is not a compelling reason to take away the functionalities of the old PageMethods. Performance was still better than a complete postback(which is what most of the internet is using). There should atleast be an alternative. Now we got 2 very similiar methods that do the same thing as oppose to 2 distinct methods that do different things.


Hello.

mnn888:

Performance was still better than a complete postback(which is what most of the internet is using). There should atleast be an alternative. Now we got 2 very similiar methods that do the same thing as oppose to 2 distinct methods that do different things.

this is the kind of thing to which i completely disagree! page methods had to send everything back to the server (ie, all the form's firlds, including hidden ones) and they only returned a value from the server. you don't need a postback to do this! if you need to send some values back to the server why not use javascript + web service method call or static page method call? they're a lot better that instance page methods!

if page methods updated the viwestate+control state, i'd be quite and i would be the 1st to say: bring them back. however, that didn't happened...so i'm not sure on where's the performance gain in using old page methods...can you see it?


One other thing to add. AutoEventWireup for the Page must be set to "true" or else the JS proxy is never generated.


hello.

as you can see by my previous sample, there's no need to have autoeventwireup set to true for gettig the proxy inserted on the client side. why?do?you?say?that?

Luis Abreu:

hello.

how about using an updatepanel or a web method? you do say that you need to refresh the UI...btw, i do think that you can access session state from a static method:

<%@. 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">
[System.Web.Services.WebMethod]
public static int O()
{
HttpContext ctx = HttpContext.Current;
ctx.Session["i"] = Convert.ToInt32(ctx.Session["i"]) + 1;
return Convert.ToInt32( ctx.Session["i"] );
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

if (!this.IsPostBack)
{
HttpContext ctx = HttpContext.Current;
ctx.Session["i"] = 0;
}
}
</script
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="manager" />
<div>
<input type="button" runat="server" id="bt" onclick="handleClick()" />
</div>
</form>
<script type="text/javascript">
function handleClick()
{
PageMethods.O(function(res){ alert( res ); });
}

</script>
</body>
</html>

that sample simple returns an int. maybe you can adapt it so that it returns what you need.

I'm a relative novice to ASP.Net AJAX, so please forgive me if i'm doing something blaringly obviously wrong here, but i copied and pasted the code shown above exactly, and when i press the button on the form, instead of the number "0" being displayed in the alert box, it is in actual fact displaying the entire html source of the page.

Any idea why this is happening?

PageMethods quirk

So here's what I found while using PageMethods in Beta 2

    A server side method needs the attribute [System.Web.Services.WebMethod]A server side method should be static or else you'll get a PageMethods is undefined errorA server side method should NOT be defined in code behind but should be in the ASPX page in <script runat="server"> tag.Here's the quirk. A server side method CANNOT have two parameters with names that differ only in the case of their letters. eg. someParam and SomeParam, even if they are of different types, e.g. string and int This will result in a Sys.ArgumentTypeException with the message Object of type Number cannot be converted to type Function. Parameter name OnSuccess.
    <script runat="server"> [System.Web.Services.WebMethod] public static string SomeMethod(string someParam, int SomeParam) { return "Hello " + someParam + " you are " + SomeParam.ToString() + " years old"; } </script>
    <script type="text/javascript" language="javascript"> function CallMethod() { var age = 28; PageMethods.SomeMethod('MyName',age, OnCallResponse); } function OnCallResponse(arg) { alert(arg); } </script>
    Change the SomeParam to age and it will work.

So my question is : Is this a bug, quirk or by design? If a bug or quirk will it be fixed? Sure one NEVER names two parameters the same with just a change in the case but then again, NEVER say NEVER.

Thanks

I SO MUCH SUPPORT your finding #3. It's so stupid that the server side code won't work in code-behind but inline code would work. What the heck?

To any MSFT moderator:

Is there any workaround for #3? This is driving me crazy.


Weird, but I just tried to create a page just like yours and it works even if the static method is in the code behind...

This is the class:

public partialclass _Default : System.Web.UI.Page { [WebMethod]public static string GetServerDate() {return DateTime.Now.ToString(); }}


And this is the ASPX:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="~/Default.aspx.cs" Inherits="_Default" %><%@. Importnamespace="System.Web.Services"%>"-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml">Untitled Page"server"> "form1" runat="server" method="post"> "ScriptManager1" runat="server" />

"button"value="get date" onclick="GetDate();" id="Button1" />

"date" />

"text/javascript">function GetDate(){ var div = document.getElementById("date"); PageMethods.GetServerDate(function (result) { div.innerText = result; });}

Sorry about my last post which is unreadable...Angel

Reposted:

Weird, but I just tried to create a page just like yours and it works even if the static method is in the code behind...

This is the class:

public partialclass _Default : System.Web.UI.Page
{
[WebMethod]
public static string GetServerDate()
{
return DateTime.Now.ToString();
}
}


And this is the ASPX:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="~/Default.aspx.cs" Inherits="_Default" %><%@. Import namespace="System.Web.Services"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server" method="post"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <input type="button" value="get date" onclick="GetDate();" id="Button1" /> <div id="date" /> </div> </form> </body></html><script type="text/javascript">function GetDate(){ var div = document.getElementById("date"); PageMethods.GetServerDate(function (result) { div.innerText = result; });}</script>

This looks a bug, thanks for reporting this issue, and it will be fixed in a future build.
-Hao


Hi,

that is not a bug. Remember that vbscript is case unsensitive.


Hi,

I tried the approach of using static methods for PageMethods in AJAX v1.0 Beta 2, but it is not working. The only change that happened is that the error message has changed from "PageMethods is undefined" to "PageMethods is null or not a object.

PLEASE HELP !!!!


Advance,

Where the heck is "vbscript" in whole picture? We are trying to access a WebMethod from Javascript using MS Ajax Beta 2 in the code-behind file.


I was hoping this would have been corrected in Beta 2. I guess I'll keep using the ATLAS CTP until this is resolved. Oh well, maybe in build 3??


hello.,

this is correct. the problem is related with the EnsureParameters of the WebServiceMethodData class. I don't know why, but it's "eating parameters" when they have the same name and differ only in case. here's the "bad" code:

privatevoidEnsureParameters()
{
if (this._parameterData ==null)
{
lock (this)
{
Dictionary<string,WebServiceParameterData>dictionary1 =newDictionary<string,WebServiceParameterData>(StringComparer.OrdinalIgnoreCase);
intnum1 =0;
foreach (ParameterInfoinfo1inthis._methodInfo.GetParameters())
{
dictionary1[info1.Name] =newWebServiceParameterData(info1,num1);
num1++;
}
this._parameterData =dictionary1;
}
}
}
 
I've tried reproducing this with a simple method and i get the 2 parameters and if i add them to a dictionary, i get 2 entries. this is not happening here (yes, i've used reeflection to reproduce what's going on and i can say that the dic only has one parameter.
if anyone have an idea on why is that, please,share with us!
thanks. 


hi.

dom't you hate it when you spend 1 hour looking at code and writing reflection just to see that the damn thing is right in front of you?:

newDictionary<string,WebServiceParameterData>(StringComparer.OrdinalIgnoreCase);
thanks Garbin!
 
 

Yeah, there are two places in the code that are using OrdinalIgnoreCase comparers which is what's causing the problem, removing the IgnoreCase for both dictionaries fixes the problem.

Hope that helps,
-Hao


hello.

does that mena that it'll be removed in the next release?


Yes I've already fixed it in the codebase.

Hope that helps,
-Hao

Saturday, March 24, 2012

PagingBulletedListExtender not working anymore

After Beta 2 installation PagingBulletedListExtender is not working anymore, just creates one long bulleted list. And more, notorious error 'SYS is undefined'. All changes suggested in the migration to Beta2 guide done.

"Sys is undefined" almost always means ASP.NET AJAX isn't installed correctly. If the following from its release notes doesn't help, please follow up in one of the other ASP.NET AJAX forums:

* A new ScriptResource handler has been added that requires the following entry in the Web.config
file:

<add verb="GET"
path="ScriptResource.axd"
type="Microsoft.Web.Handlers.ScriptResourceHandler"
validate="false"/>

This handler requires an entry in the Web.config file. If the entry is missing, you might see the
following error:

'Sys' is undefined.


ScriptResource handler was added to web.config
Please reply with acomplete, simple, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!

<%@. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Paging Bulleted List</title>
<link href="http://links.10026.com/?link=StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>

<ajaxToolkit:PagingBulletedListExtender ID="PBLE1" runat="server"
TargetControlID="BulletedList1"
ClientSort="true"
IndexSize="1"
Separator=" - "
SelectIndexCssClass="selectIndex"
UnselectIndexCssClass="unSelectIndex" />

<asp:BulletedList ID="BulletedList1" runat="server" DisplayMode="Text" DataSourceID="mySqlDataSource" DataTextField="CompanyName" DataValueField="CustomerId">
<asp:ListItem>Blur</asp:ListItem>
<asp:ListItem>Brand</asp:ListItem>
<asp:ListItem>Color</asp:ListItem>
</asp:BulletedList>

<asp:SqlDataSource ID="mySqlDataSource" runat="server" EnableCaching="true"
ConnectionString="<%$ ConnectionStrings:NorthWindConnectionString %>"
SelectCommand="SELECT CustomerId, CompanyName FROM customers" >
</asp:SqlDataSource>

</div>


</form>
</body>
</html>

=================

Web.Config :

...

<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>
</handlers>
...


I removed the SQL and code-behind dependencies from the sample above and tried it in the SampleWebSite directory of the 61126 Toolkit where it appears to work fine to me:

<%@. Page Language="VB" AutoEventWireup="true" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Paging Bulleted List</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <ajaxToolkit:PagingBulletedListExtender ID="PBLE1" runat="server" TargetControlID="BulletedList1" ClientSort="true" IndexSize="1" Separator=" - " SelectIndexCssClass="selectIndex" UnselectIndexCssClass="unSelectIndex" /> <asp:BulletedList ID="BulletedList1" runat="server" DisplayMode="Text"> <asp:ListItem>Blur</asp:ListItem> <asp:ListItem>Brand</asp:ListItem> <asp:ListItem>Color</asp:ListItem> </asp:BulletedList> </div> </form></body></html>

Yes, it works. The problem was in my Web.config

I added before ScriptResource to the handlers of the section system.webServer, and now I added this ScriptResource to the httpHandlers of the system.web section.

Now it works perfect. Thank you.

Wednesday, March 21, 2012

Parser Error Message: The entry ScriptModule has already been added.

On my development system everything is running fine, when i publish to my beta server (SBS 2003 - *no* VS installed) I get the following error:

Parser Error Message: The entry 'ScriptModule' has already been added.

Removing this line resolves the issue but then presents me with various errors relating to not being able to load System.Web.Extensions... If i can understand why the first issue is occuring this would help! Any clues?

Hi,

I have exactly the same happening on my server, does anyone have a fix for this ?

Thanks
James

This can happen if there are two HttpModules named "ScriptModule". This can mysteriously happen if you are running a virtual directory under an asp application that already has the module defined. You can either remove the HttpModule declaration<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> from the VD web.config, or all a remove node

<remove name="ScriptModule" />

just before adding it back.


Hi,

Excellent, thanks for the heads up.

James


That was an excellent post. Thank you for your help !

Sam


This suggest is not working for me again and again the same error only i am getting is there any other solution

please let me know soon......

Partial rendering issue with AJAX

I have following code working fine with ATLAS with partial rendering in IE and Firefox. But after I move the app to AJAX beta 1.0, it causes the the whole page rendering with Firefox 2.0 but it works fine with IE 6.x.

function setID(myID)
{
opid = document.getElementById ('<%=txtMyID.ClientID%>');
opid.value=myID;
document.getElementById('<%=ibtnMyButton.ClientID%>').click();
}

The page looks like:

<asp:UpdatePanel ID="UpdatePanel1" RenderMode="Inline" UpdateMode="Conditional" runat="Server">
<ContentTemplate>

<asp:UpdatePanel ID="UpdatePanel2" RenderMode="Inline" UpdateMode="Conditional" runat="Server">
<ContentTemplate>

<asp:TextBox ID="txtMyID" runat="server" ></asp:TextBox>

<asp:ImageButton ID="ibtnMyButton" runat="server" ImageUrl="../Images/go.gif"></asp:ImageButton>
........

</ContentTemplate>
</asp:UpdatePanel>

</ContentTemplate>
</asp:UpdatePanel>

How to solve this issue?

Try to change your codes as the following.
<asp:UpdatePanel ID="UpdatePanel1" RenderMode="Inline"ChildrenAsTriggers="false" UpdateMode="Conditional" runat="Server">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel2" RenderMode="Inline"ChildrenAsTriggers="false" UpdateMode="Conditional" runat="Server">
<ContentTemplate>
<asp:TextBox ID="txtMyID" runat="server" ></asp:TextBox>
<asp:ImageButton ID="ibtnMyButton" runat="server" ImageUrl="../Images/go.gif"></asp:ImageButton>
........
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
Wish the above can help you.
Thank you, Jasson, It works.