Showing posts with label developing. Show all posts
Showing posts with label developing. Show all posts

Wednesday, March 28, 2012

Calling a Web Service from Javascript

Hello!

I'm developing a WebTv channel using Atlas. My problem is in the calling of the Webservice from Javascript, it only works when I put one button like in the Atlas example:http://atlas.asp.net/docs/atlas/samples/services/Simple.aspx

The error appears when I'm invoking the WebService on the 'onload' event of the page:

requestSimpleService = iDomus.RSS..RssParser('http://www.maisfutebol.iol.pt/rss.php',OnComplete, OnTimeout);

The error on the 'onload' event is: Microsoft JScript runtime error: 'iDomus' is undefined.

I suspect that the namespace is not recognized because the Atlas engine is rendered after my script.

Any help will very appreciated.

Best regards,

Paulo Alves.

not that i have any answer for this but...

do you have "Type.registerNamespace("iDomus")" any where in your javascript?
better yet... is it before the actualy class (or object) decleration:

<script type="text/javascript">
Type.registerNamespace("iDomus");
iDomus.RSS=function(){
...
}
</script>

The other problem is that you might not have the "Namespace" setup correctly... so if your object is actually "iDomus.RSS.RssParser" then I would register the "iDomus.RSS" Namespace

since I'm working blind with what the page setup looks like...
it could also be that your object decleration is further down in the code than in the "onload" event.

again... i'm not apart of any "team" so... take it for what it is worth:
declare all of your objects first and then utilize the "pageLoad" function that gets called from Atlas

-- page declare
-- html
-- head
-- -- script manager
-- body
-- -- html elements
-- end body
-- script [for atlas]
-- -- js objects
-- -- pageLoad(){}
-- end script
-- end html

this way if you have the a seperate JS file then the "Script Manager" should load the JS file before the "pageLoad" or before the lower script section gets parsed by the browser

hope that helps...


Hellomeisinger!

Thank you for your reply.

The namespace I think is registered by the ScriptManager. When I invoque the webservice: Rss.asmx/js the result is:

Type.registerNamespace('iDomus'); iDomus.RSS=new function() { this.path = "http://localhost:4360/WebTV/RSS.asmx"; this.appPath = "http://localhost:4360/WebTV/"; var cm=Sys.Net.ServiceMethod.createProxyMethod; cm(this,"RssParser","url"); }

My aspx has the follow code:

<%

@.PageLanguage="C#"AutoEventWireup="true"CodeFile="SimpleRSS.aspx.cs"Inherits="aluno_Media_player" %>

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

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>WebTV.ESTIG</title><linkrel="stylesheet"href="default.css"type="text/css"/>

</

head><atlas:ScriptManagerID="scriptManager"runat="server"EnableScriptComponents="true"><Services><atlas:ServiceReferencePath="RSS.asmx/js"/></Services></atlas:ScriptManager>

<

bodytopmargin="0"leftmargin="0"rightmargin="0"background="images/ban5.jpg"><formid="form1"runat="server"><divid="Publico"class="PainelWebTV"></div>

<

scripttype="text/javascript"language="JavaScript">//timer = window.setInterval('parser();',1000);

parser();

function parser()

{

//Call script proxy passing the input element data

requestSimpleService1 = iDomus.RSS.RssParser(

'http://www.publico.clix.pt/rss.asp?idCanal=10'

,

//params

OnCompletePublico,

//Complete event

OnTimeoutPublico

//Timeout event

);

window.clearInterval(timer);

timer = window.setInterval(

'parser();',10000);returnfalse;

}

function OnCompletePublico(result)

{

Publico.innerHTML = result;

}

function OnTimeoutPublico(result)

{

Publico.innerHTML =

"Offline.";

}

</script></form><scripttype="text/xml-script">

<page xmlns:script=

"http://schemas.microsoft.com/xml-script/2005">

<references>

</references>

<components>

</components>

</page>

</script>

</

body>

</

html>

------------------------------------------

And the WebService:

<%

@.WebServiceLanguage="C#"Class="iDomus.RSS" %>

using

System;

using

System.Web;

using

System.Collections;

using

System.Web.Services;

using

System.Web.Services.Protocols;

using

System.Text;

using

System.Text.RegularExpressions;

using

System.Xml;

using

System.Net;

using

System.IO;

namespace

iDomus

{

[

WebService(Namespace ="http://idomus/")]

[

WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]publicclassRSS : System.Web.Services.WebService

{

[

WebMethod]publicstring RssParser(string url)

{

string title =null;string link =null;XmlTextReader reader =null;StringBuilder sb =newStringBuilder();

reader =

newXmlTextReader(url);

reader.MoveToContent();

if (!reader.EOF)

{

reader.MoveToContent();

int cont = 0;while (reader.Read() && cont < 4)//processa o ficheiro RSS

{

if (reader.Name =="item" && reader.NodeType ==XmlNodeType.Element)

{

sb.Append(

"<img src=\"images/bullet.gif\"> ");

}

if (reader.Name =="title")

{

title = reader.ReadString();

}

if (reader.Name =="link")

{

link = reader.ReadString();

}

if (reader.Name =="item" && reader.NodeType ==XmlNodeType.EndElement)

{

sb.Append(title);

sb.Append(

"<br />");

cont++;

}

}

sb.Append(

"<small>(act. " +DateTime.Now.Hour +":" +DateTime.Now.Minute +")");

}

return sb.ToString();

}

}

}

----------------------------------------

As you said, maybe the code is not in right place, but I don't know another option.

Sorry for the length of the post and thank you again for your help.

Regards,

Paulo Alves.


The Javascript error is:

Microsoft JScript runtime error: 'iDomus' is undefined

In Fiddler the error is:

An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

System.Web.HttpMethodNotAllowedHandler.ProcessRequest(HttpContext context) +103
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +317
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +65

I think the error is on the Atlas.js, but I can't figure it out.

Paulo Alves.


hello.

well, it looks like a permissions problem..are you running in medium trust?


Luis Abreu:

hello.

well, it looks like a permissions problem..are you running in medium trust?

I try even put in low trust, but the error is the same.

In my web.config I have the typical settings for Atlas:

<

sectionname="webServices"type="Microsoft.Web.Configuration.WebServicesSection"requirePermission="false"/>

<

sectionname="authenticationService"type="Microsoft.Web.Configuration.AuthenticationServiceSection"requirePermission="false"/>

<

sectionname="profileService"type="Microsoft.Web.Configuration.ProfileServiceSection"requirePermission="false"/>

<

httpHandlers>

<

removeverb="*"path="*.asmx"/>

<

addverb="*"path="*.asmx"type="Microsoft.Web.Services.ScriptHandlerFactory"validate="false"/>

<

locationpath="ScriptServices">

<

system.web>

<

authorization>

<

allowusers="*" />

</

authorization>

</

system.web>

</

location>

Thank you..

Paulo Alves.


Hello again!

I follow All the options addressed by Meisinger and Luis Abreu and with the change in the loaction of Javacript, I put it in the Head of the document, and using the Javascript Function:

timerRss1 = setTimeout("parser()", 1000);

Now it works without problems.

Thank you very mutch Meisinger and Luis Abreu for your tips.

Regards,

Paulo Alves.


hello again...

are you saying that putting the script block in the header solves the problem?


I thought the position of the script has influence, but I put it back in the body and still working. The change that solve me part of the problem was in the SCRIPTMANAGER:

<atlas:ServiceReferencePath="RSS.asmx"/>

When in the last version I put "Rss.asmx/js", like in examples of Atlas Team.

I make this change several times but did't work. I don't know why but now is working. A lot of people had experience some problems with atlas in some specific script blocks, maybe this has the same problem and by magic disappeared.

Regards,

Paulo Alves.


hello again.

ah, i've missed it...

well, you put the /js if you add the file by hand. for example, you could do this:

<script type="text/javascript" src="http://pics.10026.com/?src=rss.asmx/js">
</script>

when you use the scriptmanager, you can't add the /js since it'll add it automatically...

Wednesday, March 21, 2012

CalendarExtender Render Issues when Placed Inside Wizard Control

I'm using the CalendarExtender within the 3rd step of a Wizard Control. While developing the WizardStep, I would run the app (from that step) and the CalendarExtender controls render correctly. After completing development, I appropriately reset the Wizard Control to deploy from the Start WizardStep. But, the CalendarExtender does not render correctly when running the app from any step prior to the step that contains the CalendarExtender.

CORRECT RENDERING
Correct

INCORRECT RENDERING

Thanks,

-Dave

Many people have had this issue it has to do if the calender control is in a hidden update panel. see this page for a workaroundhttp://forums.asp.net/thread/1590343.aspx

AjaxButter


Clumsy...but it worked.

Thanks,

-Dave

CalendarExtender not working

Hello.

I'm developing a web site in VS2005 Pro, Sp1, ASP2.0, WSE3.0, SQLServer Express 2005 on XP Pro, SP2.

I'm attempting to use the CalendarExtender from the AJAX Control Toolkit. My code showing the extender and the text box it is tied is below.

When i run the program, it does not popup a calendar when the text box get focus. It just functions as a normal textbox.

Is there another property i should set?

It seems pretty simple. Just assign the id of the text box to the TargetControlID of the extender.

Any help would be gratefully appreciated.

Thanks,
Tony

Sorry. I forgot this:

<%@.PageLanguage="VB"MasterPageFile="~/AppMaster.Master"CodeFile="GetTruckMileage.aspx.vb"Inherits="GetTruckMileage"title="Coyne Web Services - Get Truck Mileage" %>

<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>

<%@.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Namespace="System.Web.UI"TagPrefix="asp" %>

<asp:ContentID="Content1"ContentPlaceHolderID="mainCopy"runat="server">

<divclass="container">

<h1>Coyne Chemical Trips and Truck Mileage</h1>

<pclass="teaser">Coyne Chemical Trips and Truck Mileage from Xatanet.</p>

<br/>

<asp:LabelID="Label1"runat="server"Text="Start Date:"></asp:Label>
<asp:TextBoxID="startDateCalendar"runat="server"></asp:TextBox>

<br/>
<br/>

<asp:LabelID="Label2"runat="server"Text=" End Date:"></asp:Label>
<asp:TextBoxID="endDateCalendar"runat="server"></asp:TextBox>
<asp:ScriptManagerid="ScriptManager1"runat="server">
</asp:ScriptManager>

<cc1:CalendarExtenderID="startDateCalendarExtender"runat="server"TargetControlID="startDateCalendar">
</cc1:CalendarExtender>

<cc1:CalendarExtenderID="endDateCalendarExtender"runat="server"TargetControlID="endDateCalendar">
</cc1:CalendarExtender>

<div>

<br/>
<br/>

<asp:ButtonID="getTruckMileageButton"Text="Get Truck Mileage"runat="server"/> 
<asp:ButtonID="exportTripsButton"runat="server"Text="Export to HP3000"/> 

<br/>
<br/>

<asp:TextboxID="getTruckMileageCompletedTextbox"runat="server"ReadOnly="True"style="overflow: visible"TextMode="MultiLine"Width="360px"></asp:Textbox>

</div>

</div>


try putting the scriptmanager before the textboxes, as good practice you should always put it at the top of a page, ( i think i heard that somewhere :P)


Hello Cowboy.

That did not help.

Why do things look so simple and easy in demos and when other people use them. When i try something, it never works the way it is supposed to.

Maybe i don't know how to set up a development computer. Have other programmers run into this problem with the calendarextender?

Thanks,
Tony


i just did this and it works fine

<head runat="server"> <title>Untitled Page</title></head><body><form id="muy" runat="server"><div class="container"><h1>Coyne Chemical Trips and Truck Mileage</h1><p class="teaser">Coyne Chemical Trips and Truck Mileage from Xatanet.</p><br /><asp:Label ID="Label1" runat="server" Text="Start Date:"></asp:Label><asp:TextBox ID="startDateCalendar" runat="server" ></asp:TextBox>  <br /><br /> <asp:Label ID="Label2" runat="server" Text=" End Date:"></asp:Label><asp:TextBox ID="endDateCalendar" runat="server"></asp:TextBox><asp:ScriptManager id="ScriptManager1" runat="server"></asp:ScriptManager><cc1:CalendarExtender ID="startDateCalendarExtender" runat="server" TargetControlID="startDateCalendar"></cc1:CalendarExtender><cc1:CalendarExtender ID="endDateCalendarExtender" runat="server" TargetControlID="endDateCalendar"></cc1:CalendarExtender><div><br /><br /><asp:Button ID="getTruckMileageButton" Text="Get Truck Mileage" runat="server" />         <asp:Button ID="exportTripsButton" runat="server" Text="Export to HP3000" />  <br /><br /><asp:Textbox ID="getTruckMileageCompletedTextbox" runat="server" ReadOnly="True" style="overflow: visible" TextMode="MultiLine" Width="360px"></asp:Textbox></div> </div> </form></body></html>
i think there is an issue with how you have it in your container dealy

Well then. I must be pretty stupid.

If my code works for you, then there must be something seriously wrong with my computer. I could try it on other computers, but that requires more effort than the benefit i would realize. To me it's not worth it to go through a bunch of troubleshooting steps just to have a nice little popup for a date entry. I'm sure there are a lot of other troubleshooting steps too.

I can't figure it out. I guess that's the end of my attempts to put AJAX control toolkit to use.

Thanks,
Tony


i wouldnt give up on the toolkit just yet, it has great features, try to put the code i posted above in a new page and see if it works, there could be a compatibility issue because you were putting the controls inside a container of some kind (i forget how u had it set up) but the code i posted put it right on the form. Try it like that and see if the calendar works, then you will know if its an issue with the container (in which case you can find another way to hold the contorls, like a panel) or if its actually you computer. Usually if you have an issue with your computer you would see an error tho


I tried your code in another project and it worked ok.

So there is something in my project that is keeping it from working.

Thanks,
Tony


I think its a probelm with this

<asp:ContentID="Content1"ContentPlaceHolderID="mainCopy"runat="server">

ive never used this control so im not sure what is going on, but maybe try using a different control then this if u can.


I don't think i can use a different control. That control is tied to the master page.

I didn't see any warnings or notes in AJAX saying that it would not work with master pages and in fact, if AJAX is not compatible with master pages, then i can't use it anyway, because all of my projects use master pages.

Thanks,
Tony


ajax works with masterpages, it just takes a little effort from what ive heard. another option though is just using the standard asp.net calendar and putting it in its own <div> and using hide/show to make it display and use the selecteddate event to add the date they pic to your textbox. note a nice looking as ajax calendar with animation and stuff, but it gets the job done


Hello Cowboy.

I figured what the problem is. I should have watched this video before i started using AJAX.

I alao should have informed you that i was adding to an existing application.

Thanks for your help.
Tony

http://www.asp.net/learn/videos/view.aspx?tabid=63&id=81

How Do I: Add ASP.NET AJAX Features to an Existing Web Application?