Showing posts with label invoking. Show all posts
Showing posts with label invoking. Show all posts

Saturday, March 24, 2012

Invoking a commandline program and displaying the results incrementally on a webpage using

As seen in the title, I want to invoke a commandline program, like ping.exe and display it's results incrementally on a webpage using AJAX.

By using the following VB.NET code, I can reroute the output of the ping command to a textbox

1Dim siAs New ProcessStartInfo("cmd.exe")23si.RedirectStandardInput =True45si.RedirectStandardOutput =True67si.UseShellExecute =False89'Start the procses.1011Dim pAs Process = Process.Start(si)1213'Issue the ping command.1415p.StandardInput.WriteLine("ping -n 1 " & klant.connectieGegevens.IpAdres(0))1617'Exit the application.1819p.StandardInput.WriteLine("exit")2021'Read all the output generated from it.2223Dim outputAs String = p.StandardOutput.ReadToEnd()
BUT, the user has to wait untill the control has executed... now... the  
p.StandardOutput.BaseStream.BeginRead()
 

command allows me to access the stream assynchronously and add the contents incrementally to a control.

My question is, can I use AJAX to add this output to my webpage without using postbacks, and if so, how?

Thanks for any help you can give me

Hi,

Do it like this if i don't misunderstand you:

<%@. Page Language="VB" %>

<%@. Import Namespace="System.Diagnostics" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim si As New ProcessStartInfo("cmd.exe")
si.RedirectStandardInput = True
si.RedirectStandardOutput = True
si.UseShellExecute = False
'Start the procses.
Dim p As Process = Process.Start(si)
'Issue the ping command.
p.StandardInput.WriteLine("ping -n 1 157.60.114.61")
'Exit the application.
p.StandardInput.WriteLine("exit")
'Read all the output generated from it.
TextBox1.Text = p.StandardOutput.ReadToEnd()

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head 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:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Best Regards,


Thanks for the assistance Jin-Yu Yin, but that is what I do now and I want to improve it...

I want to use the

p.StandardOutput.BaseStream.BeginRead() asynchronous read method, to display results when the command console gets them, so as to incrementally build the output.

Meaning, that whenever the console outputs a line, this line gets displayed on the webform, so I don't have to wait untill the commands are finished before I can start displaying results...

Any thoughts?

Thanks


Well,

I'm afraid you cann't do this, AJAX is not a server push tech.

When a Async-postback is finished, the Textbox1.text change.How can you fired a postback whenever the console outputs a line?

You cann't "push" the result to the client-side when the console outputs a line!

Best Regards,

Invoking a Web Service through JavaScript

Hi,

I keep getting the 'WebService is undefined' error when I try to

access my Web Service through JavaScript. I have made all necessary changes -added handlers to

the web.config file, included the DLL in the bin directory, included referernce through the

<ScriptManager> tag...

<atlas:ScriptManager ID="ScriptManager" runat="server" enablepartialrendering="true">
<Services>
<atlas:ServiceReference Path="/TestAJAXApp/MyWebService.asmx" />
</Services>
</atlas:ScriptManager>

<script type ="text/javascript">
function MyCustomFunction(MyRecordID, event)
{
var result = MyWebService.GetRecordDescription(MyRecordID, GetCallBack);
}
function GetCallBack(result)
{
Popup('Description' , result.value, false);
}
</script>

What could I be missing? Any suggestions appreciated.

Thanks!

The first thing to double check, is whether the request for the webservice proxy succeeded or not, use fiddler or whatever your favorite http traffic monitoring tool is, and verify that there indeed is a request to an url like /TestAJAXApp/MyWebService.asmx/js and that the response of that is the client javascript proxy for your webservice. My guess is that is failing in some way, and hopefully that will lead you to the problem...

Hope that helps,
-Hao

Invoking CascadingDropDown populate from javascript

Hi,

This question has problably been asked before but I was not able to find something relevant in my search.

I am using cascading dropdown control extenders. The are populated by a client web service method. I would like to invoke the cascading dropdown behaviour using javascript as opposed to user interaction.

Could somebody give me a brief summary to the javascript interface of the CascadingDropDown extender? I want to be able to populated and change the selected index of the corresponding HTML select elements and get the full effect of the cascading dropdown behaviour.

Thank you.

This is a BUMP to my post. I just want a few hints. How can I repopulate the HTML select elements by invoking the default functionality of the CascadeDropdown control extender via javascript. Any hints are very much appreciatted.


BUMP one more time. Someone help please.


Last try to BUMB. If I don't get any feedback I will try to do the processingon the server. So that will defeat the whole Ajax concept but I have no other option.


well, I have the same situation, and did it like this:

var ccd=$find('CCD_" + sControlName +"');

if (!ccd) {return false;}

ccd._onParentChange(null,null);

(this last line triggers the cascading-event)


Hi Attractor,

My understanding of your issue is that your have two questions list below. If I have misunderstood , please feel free to let me know.

attractor:

Could somebody give me a brief summary to the javascript interface of the CascadingDropDown extender?

Please see the CascadingDropDownBehavior.js, all the functions has been listed with a brief summary. One thing should be emphasized that it is not reommended to call a function start with "_". It is just like a inner function. Here is a sample:

get_SelectedValue : function() { /// <value type="String"> /// Selected value of the drop down /// </value> return this._selectedValue; }

attractor:

How can I repopulate the HTML select elements by invoking the default functionality of the CascadeDropdown control extender via javascript.

Based on my research, there's no public method been exposed. So my solution is :

Use javascript to select a different value meanwhile store the original selected vaule somewhere such as a hiddenField. Then afterwards make the stored value as the selected item.

Best regards,

Jonathan.


Thank you for your replies.

I was able to replicate the Cascading DropDown behaviour through the fireEven('onchange');

When calling this method on the Select element it triggers the cascading effect.

I also used the window.setTimeout() method to delay the selection of the new value in the triggered select element until its content has been refreshed.

The code is something like that :

list1.value ="val1"list1.fireEvent('onchange');window.setTimeout("list2.value = 'val2';", 1000);

Unfortunately I was not able to make it work for Mozilla. The dispatchEvent() would not work as expected. Any ideas how I can atchieve this effect in Mozilla?


Hi Attractor,

The simplest way to make your Javascript code be compatible with the main browsers is using Microsoft Ajax Library's functions. In my opnion, you need not use list1.fireEvent('onchange'); Here is my solution, please add these codes to your page.

function pageLoad(){//be called automatically.
$find("<%=Your CascadingDropDown.ClientID%>").add_selectionChanged(onSelectionChanged)
}
function onSelectionChanged(){
alert(1); // add your code here
}

For more details , please dip into the Ajax Control Toolkit's source code.

Best regards,

Jonathan

Invoking javascript routine on dropdown change

I'm trying to implement a ASP.NET 2.0/Ajax page where a client-side javascript routine is invoked when the user changes the value of a dropdown list. The dropdown list is populated in the Page_Load event.

In the aspx file, I declare the drop down as:

<asp:DropDownList ID="cbIDs" runat="server"OnSelectedIndexChanged="idChanged()" >

Visual Studio complains about "'idChanged' is not a member' of the page.

I've tried searching Google and ASP.Net but haven't been able to find an example on how to do this. Can someone please help me out?

Thanks,

Richard

onselectedindexchanged is a server side event. That is not the right place to hook in client-side code.

Doing the searchhttp://www.google.com/search?q=asp.net+dropdownlist+javascript

brings me the first article at: http://weblog.vb-tech.com/nick/archive/2005/03/25/607.aspx

which shows how to add the onchange attribute to your drop down list. There you can hook in a client side event. Be careful to make sure you fire both client-side and server-side events if you need to.

--JJ


richardr:

OnSelectedIndexChanged="idChanged()" >

richardr:

Visual Studio complains about "'idChanged' is not a member' of the page.

OnSelectedIndexChanged is a server side event... so compiler would try to findidChanged()handler in code behind which is not there..

you need to useOnChange event instead of OnSelectedIndexChanged.


a sample code below:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function idChanged()
{
alert("on change event...");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server"onchange="idChanged()">
<asp:ListItem Text="1" Value="1" />
<asp:ListItem Text="2" Value="2" />
<asp:ListItem Text="3" Value="3" />
<asp:ListItem Text="4" Value="4" />
<asp:ListItem Text="5" Value="5" />
</asp:DropDownList>
</div>
</form>
</body>
</html>

Invoking methods

Hello everybody!

I've got a question! We can change property values from XXXXBehavior.js. So can we invoke methods or rise events form XXXXBehavior.js? I mean server side methods!

Thanks:)

Hi again!

I've solve my problem and want to share the solution. i found a way to invoke a serverside method for client script, but it's a reeeeealy ugly way :). The idea is to add to a page another control the supports postback (like LinkButton) and define a OnClick event handler(we will invoke it).

Now the client side function that executes postbacks is "__doPostBack", and we just call it. For example for LinkButton1: "__doPostBack('LinkButton1','');"

Unfortunately i didn't find any other way to solve my problem, so any advices and remarks are welcome.

P.S.

don't forget about UpdatePanles ;)


Consider Client Callbacks, perhaps:http://msdn2.microsoft.com/en-us/library/ms178208.aspx

Invoking ModalPopupExtender causes Submit button to not postback

I have a simple webform that contains a textbox and a required field validator. The page also has a modal popup extender tied to a button as well as two other buttons for saving the page's input and canceling the pages changes. The cancel button has causesvalidation="false".

I run the web application and on the page in question click the button that causes modal popup to show and then hide the modal popup. The textbox on the page does not have any text and so the validator shows the invalid message. When I click the 'Cancel' button the first time the page does nothing. If I click it again, the server side event handler is fired. Given that causesvalidation is set to false I expected the server event handler to fire on both occasions.

Here is the sample code that displays the said behavior -

<asp:ScriptManager ID="scriptManager1" runat="server" />
<div>
<asp:Label ID="label1" Text="Label1" runat="server" />
<asp:TextBox ID="textbox1" runat="server" />
<asp:RequiredFieldValidator ID="textRequiredFieldValidator" ControlToValidate="textbox1"
Text="*" runat="server" />
<br />
<asp:Button ID="popperUpperButton" Text="Show Popup" runat="server" />
<asp:UpdatePanel ID="pageUpdatePanel" UpdateMode="Always" runat="server">
<ContentTemplate>
<asp:Button ID="submitButton" Text="Send" OnClick="SubmitButton_Click" runat="server" />
<asp:Button ID="pageCancelButton" Text="Cancel" CausesValidation="false" OnClick="PageCancelButton_Click"
runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:Label ID="statusLabel" runat="server" />
<act:ModalPopupExtender PopupControlID="modalPopupPanel" TargetControlID="popperUpperButton"
OkControlID="okButton" CancelControlID="leavePopupLinkButton" runat="server" />
</div>
<asp:Panel ID="modalPopupPanel" runat="server">
Just some text that is shown in the popup window.
<asp:Button ID="okButton" Text="OK" runat="server" />
<asp:LinkButton ID="leavePopupLinkButton" Text="Leave Popup" runat="server">
</asp:LinkButton>
</asp:Panel>

Server event handler code -

protected void Page_Load(object sender, EventArgs e)
{

}

protected void SubmitButton_Click(object sender, EventArgs e)
{
this.statusLabel.Text += "submit clicked...";
}

protected void PageCancelButton_Click(object sender, EventArgs e)
{
this.statusLabel.Text += "cancel clicked...";
}

Has anyone else seen this behavior and is there a known fix? I am seeing it consistently on the application I am building.

Thanks in advance,

Ruwan

Why are the submitButton and cancelButtons in an UpdatePanel but the textbox is not? Could you try to get the page working without the updatepanel first? I am not sure this issue has anything to do with the modalpopup being on the page.


Thanks for the response. I have tried the above with and without the updatepanel and see the same result. My reason for suspecting some coupling with the ModalPopupExtender is that the issue does not show up till the ModalPopupExtender is placed on the page.

The updated ASPX page reads -

<asp:ScriptManager ID="scriptManager1" runat="server" />
<div>
<asp:Label ID="label1" Text="Label1" runat="server" />
<asp:TextBox ID="textbox1" runat="server" />
<asp:RequiredFieldValidator ID="textRequiredFieldValidator" ControlToValidate="textbox1"
Text="*" runat="server" />
<br />
<asp:Button ID="popperUpperButton" Text="Show Popup" runat="server" />
<asp:Button ID="submitButton" Text="Send" OnClick="SubmitButton_Click" runat="server" />
<asp:Button ID="pageCancelButton" Text="Cancel" CausesValidation="false" OnClick="PageCancelButton_Click"
runat="server" />
<br />
<asp:Label ID="statusLabel" runat="server" />
</div>
<asp:Panel ID="modalPopupPanel" runat="server">
Just some text that is shown in the popup window.
<asp:Button ID="okButton" Text="OK" runat="server" />
<asp:LinkButton ID="leavePopupLinkButton" Text="Leave Popup" runat="server">
</asp:LinkButton>
</asp:Panel

Thanks,


have you tried adding a validationgroup attribute to the validator and the submit button. adding a attribute like validatorgroup="vg1" to both should cause all other control to ignore the validation except what is part of the group. This may help.


also, I will agree with kirtid, the use of the update panel may be part of the problem. Your update panel only wraps the 2 buttons, so clicking 1 will fire but you will not be able to see the results. if the label is NOT in the update panel. it will not be updated. Try moving the label into the update panel and see if it gets written to. also move the textbox and validator into the UP as well so they can be fired and accessed. I just ran that code with all of them inside the update panel, and it worked for me.

-Alan


Alan,

The ValidationGroup suggestion has provided a work-around for the test application, which now works fine. I will merge the solution in the product that first brought up the issue.

Thanks for the help!

Invoking postback for an update panel in a parent document

The default page for my website contains a div with links to user data that is only visible when a user is logged into my site. The login control lives in an IFrame within the default page (see sample code below).

Now, how can I get the udpate panel on the default page to recognize an event or a button click inside of the login control? I'm not looking for a tutorial on getting the login control to work, but rather any link button inside of the IFrame's update panel forcing the default page's update panel to post back. Both pages have a script manager.

chopped down version of existing code:

dafault page:

1<asp:update panel id="upUserPrefs" runat="server" updatemode="conditional">2 <contenttemplate>3 <div id="userPrefs" runat="server"><a href="prefs.aspx">preferences</a></div>4 </contenttemplate>5</asp:update panel>

IFrame source page:

1 <asp:UpdatePanel ID="updateSignon" runat="server" UpdateMode="conditional">2 <ContentTemplate>3 <asp:Table ID="tblLoginCtrl" runat="server" visible="false" Width="100%" HorizontalAlign="Left" CellPadding="0" CellSpacing="0">4 <asp:TableRow>5 <asp:TableCell ID="tcLoginCtrl">6 <uc1:LoginControl ID="LoginControl" Enable runat=server LoginStyle=Login_Home />7 </asp:TableCell>8 </asp:TableRow>9 </asp:Table>10 </ContentTemplate>11 </asp:UpdatePanel>
Any help would be greatly appreciated.

</p><p> (this.Parent.Parent as UpdatePanel).Update();</p><p>

is what I use.....however i have other problems...LOL. but that should fix yours.


Hi,

I think you can add a invisible button in the default page, set it as a trigger for the update panel.

Then add a javascript function in the contained page, in which invoke the click event of the button in the container.

Please feel free to let me know if there is any problem.


I tried that before, but when I have 2 instances of the same control on my page, it fires events for both of them. Or did I do something wrong?? Should this be happening? Have you ever heard of this??


In my opinion, it's normal that two control of the same type would behavior the same.

Invoking post back on page load (an easy question - but I couldnt find the answer!)

What I want to do is very easy, so I'm very frustated to have to ask this on the forum - but I've been searching the net for 2 days now and couldn't figure out the answer in a nice "Atlas" way of doing things.

The behaviour I want is exactly what pageflakes.com does when you go their home page: Display a "loading" message while the data is being loaded.

Icanput an UpdatePanel with my data controls in it.

Icanput an UpdateProgress control to show the "loading" message.

What Idon'tknow, is how to make it so that the client-side page will invoke a postback immidietly after loading, i.e. call the BindData() function on the server-side page.

I would prefer a declerative solution to this, or at least, a very short Javascript code (but I'm not too picky - first priority is to get the basic functionality :-) )

Little help?

Is the question unclear? or is it not as easy as I thought? Google does it, pageflakes does it, so I know it's possible...

This is what I have so far.

The javascript pageLoad() function runs properly after loading, and it does indeed call the server (and is capable of returning data to the page, I checked with js alerts)- but the label in the updatepanel doesn't change.

In addition, I received the wierdest error -must have <head runat="server"> You might notice I've added the runat=server to the header, though it still doesn't work.

Default2.aspx

<%

@.PageLanguage="VB"AutoEventWireup="false"CodeFile="Default2.aspx.vb"Inherits="Default2" %>

<

html>

<

headrunat="server"><title>ddd</title>

</

head>

<

body><formid="MainForm"runat="server"><atlas:ScriptManagerID="sm"runat="server"EnablePartialRendering="true"/><atlas:UpdatePanelID="UpdatePanel1"Mode="Always"runat="Server"><ContentTemplate><asp:LabelID="Label1"runat="server"Text="Label"></asp:Label></ContentTemplate></atlas:UpdatePanel></form><scriptlanguage="javascript">function pageLoad()

{

GetServerTime();

}

function GetServerTime()

{

var message ='';var context ='';

<%=sCallBackFunctionInvocation%>

}

function ShowServerTime(timeMessage, context) {

alert(

'The time on the server is:\n' + timeMessage);

}

function OnError(message, context) {

alert(

'An unhandled exception has occurred:\n' + message);

}

</script>

</

body>

</

html>

Default2.aspx.vb

Partial

Class Default2Inherits System.Web.UI.PageImplements ICallbackEventHandlerPublicFunction GetCallbackResult1()AsStringImplements System.Web.UI.ICallbackEventHandler.GetCallbackResultMe.Label1.Text ="Binded, at last"Return ("The server time is " &Date.Now.ToString)EndFunctionPublicSub RaiseCallbackEvent1(ByVal eventArgumentAsString)Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEventEndSubPublic sCallBackFunctionInvocationAsStringProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

sCallBackFunctionInvocation = _

Me.ClientScript.GetCallbackEventReference(Me,"message","ShowServerTime","context","OnError",True)EndSub

End

Class
Sorry, I havent got an asnwer for you, but Im trying to do the same thing.

I have built a query screen that connects to one of my web services and nicely brings back a list of results using atlas, then when you click on one of the results it loads the details page which then shows you the full details of the selected item.

The thing is when the details page is being loaded I have to call 4 web services to get the required data back, and this can take anything upto 8seconds to do. During this time the first screen is just locked whilst the details page is being built in the background.

What i want is the details page to show straight away - but empty, and my UpdateProgress to show a nice ticking loading sign.

As you said, PageFlakes has a nice example of this working, but I cant seem to replicate it.

I have tried putting my server side code in the page load event, then setting the trigger for the updatepanels to page load, but it doesnt seem to like this.

if you find an answer let me know!

stuart

Eureka !Idea [Idea]

With the help ofMatt Gibbsfrom Microsoft (ScottGuthrie refered me to him) I managed to do it.

Matt's answer to my question was a little different from how I ended up doing it, so I'll show both.

First, my crude way... The trick was not to useICallbackEventHandlerbutIPostBackEventHandler (I didn't even know it existed before Matt told me).

ASPX page:

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default4.aspx.vb" Inherits="Default4" %><html><head runat="server" > <title>ddd </title></head><body> <form id="MainForm" runat="server"> <atlas:ScriptManager ID="sm" runat="server" EnablePartialRendering ="true" /> <atlas:UpdatePanel ID="UpdatePanel1" Mode="Always" runat="Server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </atlas:UpdatePanel> <atlas:UpdateProgress ID ="UpdateProgress1" runat="server"> <ProgressTemplate> Loading... </ProgressTemplate> </atlas:UpdateProgress> </form> <script language="javascript"> function pageLoad() { GetServerTime(); } function GetServerTime() { var message = ''; var context = ''; <%=sCallBackFunctionInvocation%> } function ShowServerTime(timeMessage, context) { alert('The time on the server is:\n' + timeMessage); } function OnError(message, context) { alert('An unhandled exception has occurred:\n' + message); } </script> </body></html>


This is the code behind:
 PartialClass Default4Inherits System.Web.UI.Page'Inherits System.Web.UI.WebControls.WebControlImplements IPostBackEventHandlerPublic sCallBackFunctionInvocationAs String Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load sCallBackFunctionInvocation = _Me.ClientScript.GetPostBackEventReference(Me,"message")' Me.ClientScript.GetCallbackEventReference(Me, "message", "ShowServerTime", "context", "OnError", True)End Sub Public Sub RaisePostBackEvent1(ByVal eventArgumentAs String)Implements IPostBackEventHandler.RaisePostBackEvent System.Threading.Thread.Sleep(2000)Me.Label1.Text ="Binded, at last"End SubEnd Class


Now, this is what Matt wrote, I see how it's better because it's easier to apply later to any application, but I couldn't create it:

1) create a custom control that inherits from WebControl, let's call it Loader

2) In the code for Loader, have it override the Render method and call GetPostBackEvent reference. It should render out clientside script for the pageLoad function that contains the result of the call to GetPostBackEventReference.

3) The Loader control should also implement the IPostbackEventHandler interface. In the RaisePostBackEvent method call DataBind on the page.

4) Now you can use the control on your page to have the UpdatePanel refreshed when the page loads.


Here is your sample packaged as a custom control.

The Page:

<%

@.PageLanguage="C#" %>
<%@.RegisterTagPrefix="my"Namespace="Samples" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<scriptrunat="server">
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<atlas:ScriptManagerID="sm"runat="server"EnablePartialRendering="true"/>
<atlas:UpdatePanelID="UpdatePanel1"Mode="Always"runat="Server">
<ContentTemplate>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</ContentTemplate>
</atlas:UpdatePanel>
<atlas:UpdateProgressID="UpdateProgress1"runat="server">
<ProgressTemplate>
Loading...
</ProgressTemplate>
</atlas:UpdateProgress>
<my:Loaderrunat="server"/>
</div>
</form>
</body>
</html>

And the custom control:

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;

namespace

Samples {
publicclassLoader : System.Web.UI.WebControls.WebControl,IPostBackEventHandler {public Loader() {
}protectedoverridevoid Render(HtmlTextWriter writer) {
writer.Write("<script type=\"text/javascript\" >\r\n");
writer.Write("function pageLoad() {\r\n");
writer.Write("alert(\"waiting\");\r\n");
writer.Write(this.Page.GetPostBackEventReference(this));
writer.Write("}\r\n");
writer.Write("</script>\r\n");
}publicvoid RaisePostBackEvent(string eventArgument) {
Label label =this.Page.FindControl("Label1")asLabel;
if (label !=null) {
label.Text ="updated at last";
}
}
}
}
Well done - that has helped me a lot. I got it all working with the user control setup.

I just found out (late, huh?) that search engine spider bots will not be able to "see" the information on any page that uses this, because this uses post backs.

If there's no way to do this and still have the search engines find it, I'll have to give it up. Pitty - this was a very nice UI solution.


I just found this thread - how do I keep the page from posting back in a loop ? It does in fact do a postback after page_load has fired, but it keeps doing it...
It shouldn't be doing it. Go over the code again, see if you can debug it. If not, post it and we'll take a look.

@.BitShift:

The problem might be that you moved the Loader control within the UpdatePanel?? I did that for another reason and I got exactly what you described.

Here is the problem I'm facing:

Yes the sample code that Matt provided does work, however, I want to move my Loader control into the UpdatePanel, so that the first it renders it does the AsyncPostback, and then on the second render it display the real control that I want to load. This avoid the need for triggers and everything in centralized in my Loader control. I too thought this would be easy, but alas not. :(

here is what I have (simplified):

<asp:UpdatePanelID="UpdatePanel1"UpdateMode="Conditional"ChildrenAsTriggers="true"runat="Server">
<ContentTemplate>
<cc1:LoaderID="Loader1"ReportPath="/Analysis Reports Test/Report1"runat="server"/>
</ContentTemplate>
</asp:UpdatePanel>

CodeBehind of Loader.cs:

protectedoverridevoid Render(HtmlTextWriter writer)
{
if (!bPostback)
{
writer.WriteLine("Loading...");
writer.WriteLine("<script type=\"text/javascript\" >");
writer.WriteLine("Sys.Application.add_load(" +this.ClientID +"_Load);");
writer.WriteLine("function " +this.ClientID +"_Load() {");
writer.WriteLine(this.Page.ClientScript.GetPostBackEventReference(this,""));
writer.WriteLine("}");
writer.WriteLine("</script>");
}
else
{
this.Controls[0].RenderControl();
}
}bool bPostback =false;
publicvoid RaisePostBackEvent(string eventArgument)
{
System.Diagnostics.Debug.WriteLine("Postback from : " + eventArgument);
bPostback =true;
MyCustomControl c =new MyCustomControl();
this.Controls.Add(c);
}

When I do this, I lose the AsyncPostback of the UpdatePanel, it does a full page postback. I have to explicitly set the AsyncPostBackTrigger even though it is a child control and the ChildrenAsTriggers="true"?!?

Even at that I am still having another issue, that my page has mulitple of these loaders and all UpdatePanels should be triggered only once. Unfortunately this is not the case. I have the UpdateMode set to Conditional however with the AsyncTrigger it still appears to trigger multiple updates. With 2 UpdatePanels and Loader controls, I get 3 postbacks:
1) Loader2
2) Loader1
3) Loader2

Any helpwould be greatly appreciated.

Perry


I got this problem also, and it's been a long time this thread gone unanswered.

Could somebody gives me exact explanation about how the postback sequence in favor of MS AJAX? It seems to me it got mixed up and the order is different on web form without AJAX.

regards,

Eriawan

Invoking the ModalPopupExtender from a ListBox

I would like to know if it is possible to invoke the ModalPopupExtender by making a choice in a ListBox. All of the posts and examples I can find appear to use a button to invoke the control. My need is to invoke the control only when a particular selection is made in the ListBox. In my case, there are 4 choices in the ListBox, but I only want the Popup to show when #4 is selected.

As a follow-up, if this cannot be done, is there any work-around that will make the user think this is what happens. In other words, the Popup will appear when they make the particular selection in the ListBox, even if the program had to do something else to make it happen.

This seems like it should be a simple thing to do, but I cannot figure it out (I am new to AJAX and the Toolkit, and still trying to get a good grasp of them).

Any help will be greatly appreciated.

The individual ListItem will not have an ID that the ModalPopupExtender can target. You instead have a hidden input that the ModalPopupExtender targets, set the BehaviorID on the ModalPopup and call show and hide when the ListBox selected index is changed and is equal to the 3. You can hook up the onchange event handler on page load.


kirtid,

I appreciate your answer, and I follow the logic of it. However, you give me far too much credit for understanding how to implement your solution. When I mentioned that I was new to AJAX, I should have probably said (in the interests of full disclosure) that I am new to client-side programming and/or javascript.

I have dropped an html input (text) control onto my page, but the only way I can seem to get the ListBox SelectedIndex into it is to wrap it in an UpdatePanel and use the listbox as a trigger. I have set the BehaviorID in the Extender, but I can't seem to get the ModalPopup to pay attention to my input box. My attempt at the onchange function (for entertainment purposes) looks like this:

function Text1_onchange() {

If (Text1.value="3") {

$find("showPopUp").show()

}

else

{

$find("showPopUp").hide()

}

}

Even if by some miracle this will work, I am unsure how to wire it up.

I would appreciate any hand holding you can provide. I figure I won't learn anything if I don't ask those who know.


In the List element add a client side handler to the changed event:http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/option.asp.

Something like this.

<

bodyonclick="DoSomething()"><scripttype="text/javascript">

function DoSomething() {var listBox = $get('listBox1');

$addHandler(listBox,

'change', ShowModalPopup());

}

function ShowModalPopup() {var listBox = $get('listBox1');var modalPopup = $find('modalBehavior1');var index = listBox.selectedIndex;if ( index == 1) {

modalPopup.show();

}

returnfalse;

}

</script><formid="form1"runat="server"><asp:ScriptManagerrunat="server"></asp:ScriptManager><div><asp:Buttonrunat="server"ID="btn1"Visible="false"/><ajaxToolkit:ModalPopupExtenderID="ModalPopupExtender1"runat="server"TargetControlID="btn1"PopupControlID="DropPanel"DropShadow="true"BehaviorID="modalBehavior1"></ajaxToolkit:ModalPopupExtender><asp:ListBoxrunat="server"ID="listBox1"><asp:ListItem>Foo</asp:ListItem><asp:ListItem>Bar</asp:ListItem><asp:ListItem>Baz</asp:ListItem></asp:ListBox>


kirtid, I've got it working.

Thanks for your help

Invoking WCF web services from client script with MS Ajax RC1

Hello,

I've read through the Ajax documentation which shows some examples of invoking .asmx web services from client code but I couldn't find any information about doing the same with .svc WCF web services. Is this supported in the current Release Candidate of Ajax? If not, is this planned for future releases?

Thanks for your time.

No, svc is not currently supported. However it will be supported in upcoming "Orcas" release. Read ithere and search for "Support for WCF Web Services"

I'm intested by calling a wcf services with ajax

could anyone tell me which version of ajax let me use .svc files and how ? sinc the docs on the web are gone ..


thanks in advance :)