Showing posts with label invoke. Show all posts
Showing posts with label invoke. Show all posts

Saturday, March 24, 2012

InvalidOperationException : Request format is invalid : application/json charset=utf - 8

Can anybody help me guys with this one,

I'm tryng to invoke a web method in my web service from javascript but i keep on getting javascript response Error stating that my webmethod couldn't execute because of this Error (InvalidOperationException : Request format is invalid : application/json charset=utf - 8 )

here is my logic for my web service

[ScriptService]
[WebService(Namespace = "http://www.wipspace.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class svrCreateReal : System.Web.Services.WebService
{
private clsLibraryFile objF;
private clsWipReel objWipR;


public svrCreateReal ()
{
objF = new clsLibraryFile();
objWipR = new clsWipReel();
}

[WebMethod]
[ScriptMethod(UseHttpGet = false)]
public int createReelfileCollection(string reelID, string menuID, string fileID )
{
try
{
objWipR.reelID = Convert.ToInt32(Server.HtmlEncode(reelID));
objWipR.reelMenuID = Convert.ToInt32(Server.HtmlEncode(menuID));
objF.fileID = Convert.ToInt32(Server.HtmlEncode(fileID));
return objWipR.createReelMovieCollection(objWipR, objF);
}
catch
{
return -1;
}

}

From my aspx page i call a javascript function that invokes the web method like below

<asp:ScriptManager ID="scriptManager"
runat="server" >
<Services>
<asp:ServiceReference InlineScript="true" Path="adminWipService/svrCreateReal.asmx" />
</Services>
</asp:ScriptManager>

<script type="text/javascript">

function createReel( sender, e )
{
var container = e.get_container();
var item = e.get_droppedItem();
var position = e.get_position();
var fileID = parseInt(item.getAttribute("fileID"));
var menuID = parseInt(container.getAttribute("MenuID"));
var row = position;

var created = svrCreateReal.createReelfileCollection(6, menuID, fileID);

alert(created );

}

thnks very much in advance

cheers

Pay attention on Web.config of your application. It have to contain some declarations. Similarly to it:

-----

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections
<system.web>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="false">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web
<system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
--
<!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and
writeAccessProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true" enableCaching="true" />
-->
</scripting>
</system.web.extensions
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
</configuration>

Invoke an UpdatePanel update from client script

I'm writing an application which is predominantly a client-centric application but I need to update a part of the page from a client script action. What is the correct way to do that? I presumed that you simply set the UpdateMode of your UpdatePanel to Always and then implemented ICallbackEventHandler on the page to do the async postback. I've done that, but my UpdatePanel is not updating... help :)

In my ClientCallback, I'm essentially rebinding the control that sits inside the UpdatePanel and then explicitly calling Update() on the UpdatePanel... but nothing.

Hi digory,

http://encosia.com/2007/07/13/easily-refresh-an-updatepanel-using-javascript/

Is this what you are looking for?

Wim.


It is. I was just trying that solution as you posted and it works fine. Thanks! Smile

Invoke an exe file on server side

I created a page with a button. The user presses this button and it is supposed to invoke an exe file that works on the server side. I tried the following code behind:

Label2.Text ="The bot began it's work. Pleas wait..."Dim startInfo As System.Diagnostics.ProcessStartInfoDim pStart As New System.Diagnostics.ProcessstartInfo = New System.Diagnostics.ProcessStartInfo("http://.../files/BotScript1.exe")pStart.StartInfo = startInfopStart.Start()pStart.WaitForExit()Label2.Text = "The bot has finished it's work"

My problem is that this doesn't work on the server side: Pressing the button asks the user if he wants to open the file. I want this file to work on the server.

If this can't be done for security reasons (I don't see why not - this file has nothing to do with the user, but is part of the server script), I would like to use the source code of this exe file and run it on the server. The problem doing it this way is that the script is in c# and my pages are in VB.NET.

Thanks
Yoni

If the .exe is on your web server, try using Server.MapPath in the ProcessStartInfo() to get the actual file location, instead of the HTTP (virtual) location.


doyleits:

If the .exe is on your web server, try using Server.MapPath in the ProcessStartInfo() to get the actual file location, instead of the HTTP (virtual) location.

I tried that, and the exe runs, but as a diff problem came up, I decided to put the source code in my code behind page. I now face a new problem:

I have created a listbox inside an update panel, but when I use the code behind to add items to the listbox (in order to notify the user whats going on) - they added items don't appear until the server is done with the code. How can I get the listbox to refresh itself every time I add/remove/edit items from it?

Thanks,
Yoni


Put the ListBox inside UpdatePanel. Also set the UpdateMode property toConditional

When items will be added/deleted call UpdatePanel1.Update()

http://www.asp.net/ajax/documentation/live/mref/M_System_Web_UI_UpdatePanel_Update.aspx


chetan.sarode:

Put the ListBox inside UpdatePanel. Also set the UpdateMode property toConditional

When items will be added/deleted call UpdatePanel1.Update()

http://www.asp.net/ajax/documentation/live/mref/M_System_Web_UI_UpdatePanel_Update.aspx

I did as you said: I added a UpdateMode="Conditional" property to the Update Panel and used the Update() function after every change I did to the list - but still nothing. Any ideas?

Thanks
Yoni


Hi Yoni,

I recommend copying those source code into a class library. And reference the assembly in your web application. It's better than changing security settings.

After the class library has been compiled into an assembly, it can be used regardless of what language it's written in.


Sorry, I didn't notice that you've solved the running exe issue.

yonidebest:

I tried that, and the exe runs, but as a diff problem came up, I decided to put the source code in my code behind page. I now face a new problem:

I have created a listbox inside an update panel, but when I use the code behind to add items to the listbox (in order to notify the user whats going on) - they added items don't appear until the server is done with the code. How can I get the listbox to refresh itself every time I add/remove/edit items from it?

Thanks,
Yoni

I think you can add a timer on the page to refresh the page at a specific interval.

Invoke client-script from the server...

I'm trying to be crafty here...I want to inject some client-script into a page, then execute it all without a postback. I thought I could use an update panel and do something like this...

1 <form id="form1" runat="server">
2 <asp:ScriptManager ID="ScriptManager1" runat="server" />
3
4 <script type="text/javascript" language="javascript">
5 document.write(Date());
6 </script>
7
8 <div style="background-color: Brown; border: solid 1px #999;">
9 <asp:Button id="button1" runat="server" onclick="button1_Click" text="clickMe" />
10 </div>
11
12 <asp:UpdatePanel id="updatePanel1" runat="server" updatemode="Conditional" />
13 </form>

CODE BEHIND AS FOLLOW --

1protected void Page_Load(object sender, EventArgs e)2{34}56protected void button1_Click(object sender, EventArgs e)7{8System.Web.UI.HtmlControls.HtmlGenericControl hiddenSpan =new HtmlGenericControl();9hiddenSpan.InnerHtml ="Here is some hidden text that I would like to show without refreshing the page.";10hiddenSpan.ID ="hiddenSpan";11hiddenSpan.Style.Add("display","none");1213updatePanel1.ContentTemplateContainer.Controls.Add(hiddenSpan);1415System.Web.UI.HtmlControls.HtmlGenericControl span =new HtmlGenericControl();16span.InnerHtml ="<script type='text/javascript' language='javascript'>document.getElementById('hiddenSpan').style.display = 'block';</script>";1718updatePanel1.ContentTemplateContainer.Controls.Add(span);1920updatePanel1.Update();21}
Turns out, the entire page refreshes when I attempt this. If I declare the button as a trigger for the update panel then the script won't work at all. Does anyone know how to do something like this? Keep in mind...this isn't my actual project, this is just a small test. My real project wouldn't have the button event...hopefully the update panel refresh and client script would be triggered by a totally different server event.

Add the Button as Trigger. Then Use the ScriptManager.RegisterStartupScript method to inject the js code like the following:

ScriptManager.RegisterStartupScript(this, this.GetType(), "startup", "document.getElementById('hiddenSpan').style.display = 'block';", true);


Bingo! You rock!! I didn't know the scriptmanager had registration events like that!! Thanks.

Invoke Javascript method after partial postback ?

Howdy All,

This might be an easy one but I don't seem to be able to figure it out.

Basically I have an update panel which contains a button that causes the partial postback. After the postback I'd like it to call a Javascript method.

I tried looking to set it on an atlas object and I even tried some hacks like putting a literal control in the Update Panel and setting the text to <script language=""Javascript"">testFunction();</script>" but still no cigar.

Any help would be greatly appreciated.

Try registering your script on the server-side, during the partial post. The script you register will be executed when the response is received from the partial postback.

Page.ClientScript.RegisterStartupScript

-Tony


in my callback function i havestring js = "alert('s');"; Page.ClientScript.RegisterStartupScript(GetType(), "key", js);It doesn't fire

casaubon:

in my callback function i have string js = "alert('s');"; Page.ClientScript.RegisterStartupScript(GetType(), "key", js); It doesn't fire

You need to wrap your js in <script type="text/javascript"> </script>, or use the overloaded RegisterStartupScript specifying "true" for the last parameter.

Hope this helps,

-Tony

Invoke JavaScript method after partial post back

  Hi,
 Im trying to invoke a javascript method after a partial update has occured from an update panel. I found some code for which i beleive works for an old version, but it doesn't work for the released version.
 Does anyone know how i can invoke a javascript method after post back?
 
 
1 function afterPostback()2 {10 }1112 function PageRequestManagerPropertyChanged(sender, args)13 {14if (args.get_propertyName() =="inPostBack")15 {16if (!$object("_PageRequestManager").get_inPostBack())17 afterPostback();18 }19 }2021 function pageLoad()22 {23 $object("_PageRequestManager").propertyChanged.add(PageRequestManagerPropertyChanged);24 }

You can handle _endRequest to do that. Try something like this:

var prm = Sys.WebForms.PageRequestManager.getInstance();prm.add_endRequest(afterPostback);function afterPostback(sender, args){}

Note: This code has to be placed below the ScriptManager control.


Brilliant, that works a treat.

Thanks

invoke ModalPopUp from GridView button

I've got a ModelPopUp that works just fine from a LinkButton.

Now I need to launch the popup from a button in a GridView column/cell. Is there a way to specify that button in TargetControlID property - or is there another way I can programmatically invoke the modalpopup?

I Have a similar problem. I need to launch the popup from a treeview node, with the added hassle that I also need the modal popup to know the Id of the tree node that poped it up!

If I find a solution, I will post here for you.


Well, I can't say this is real elegant, but the way I do it is to put a button on the form, outside of the GridView and set its class so it's not visible (Make sure you use a style and not God forbid, the control's visible property!) Use this button's ID as your TargetControlID.

Attach a client side script to the button in your GridView that is supposed to launch the popup. In the script, call the fake button's click event.

So the code will be something like this:

<asp:ButtonID="ProxyButton"runat="server"CssClass="hidden"/>

<atlasToolkit:ModalPopupPropertiesTargetControlID="ProxyButton" .../>

In the GridView:

<asp:ImageButtonID="..."runat="server"OnClientClick="fakeClick()" .../>

The script:

function fakeClick() {

$('ProxyButton').click();

}

Hope it helps.

Kathy


Thanks Kathy - this does invoke the modal dialog just fine, but it generates two problems I'm hoping you can help with. The first is that the ProxyButton postback clears the modal just as soon as it's shown. Second, I don't know how to access the commandargument from the script - this contains the ID of which grid row the button was clicked on.

Any help?


As for the first problem, I don't think that the proxy button's postback is causing the refresh. It's a fake click after all. It's most probably the button in the GridView (or imagebutton or linkbutton or whatever it is). I don't know your exact scenario, but you may want to consider one of the following options:

1- Use an html control in your grid to invoke the click event of the fake button. Something like a simple div or img with its onclick event set to fakeClick(). As you know these won't cause a postback.

2- Enclose your GridView in an atlas:UpdatePanel. This will keep the button from posting back, too.

As for the second one, if you populate your GridView in the code (as opposed to automatically), you can bind the click event there and pass whatever argument you want, in there, too. Like say you want to launch the popup upon clicking an imagebutton control called Modify, in the grid, and you want to pass the ID of the record as the argument (assuming you got the value in sID and assuming you write VB code):

Dim ibModifyAs ImageButton

ibModify =CType(e.Row.FindControl("Modify"), ImageButton)

ib.Attributes.Add("onClick","fakeClick('" & sID &"')")

If you populate the grid automatically, there is a syntax for doing this in the aspx code itself, but I'm not sure of it. So the good news is that tt can be done and the bad news is that you have to do a little more searching on it. (I will post it if I remember it!)

Now you have to alter the fakeClick script to accept an input argument. You can pass it from there and do anything you want to do. Just to give you a heads up, if you are trying to populate your popup control dynamically, I hope you just have a little html code that needs to go in there. If you want to populate it dynamically, with server controls and all, you're in for a ride :)

Hope this helps.

Kathy


Hi everyone,

You might be interested in checking outhttp://forums.asp.net/thread/1404770.aspx which provides an example of invokingModalPopup from the server in response to aCommand event.

Thanks,
Ted

Are you sure that your javascript will work!?

function fakeClick() {

$('ProxyButton').click();

}

I think NO, becauseProxyButton is asp:Button

and $('ProxyButton') will be NULL, /$('ProxyButton')=document.getElementById('ProxyButton'), butProxyButton should be HTML element

What you think?


Hi StoyanPetrov,

The JavaScript should be fine - the asp:Button will render an HTML DOM element with the same name which then gets picked up by $.

Thanks,
Ted

Hi,

I've been trying to do the same thing and as mentioned above. The page does do an AJAX postback which will cause all the controls to be reset and hence the popup to disappear( you can test this by putting a breakpoint on the Page_Load function).

I found a fairly clumsy way around this. you basically have to do the following.

i) add an event handler for OnRowCreated for the gridview and bind an event handler to the button. In this case called ButtonX

protected void RowAdding(object o,GridViewRowEventArgs e)
{
ImageButton ib=(ImageButton)e.Row.FindControl("ButtonX");
if (ib != null)
{

ib.Click += new ImageClickEventHandler(ib_Click);

}

}

ii) in that event handler store the popup state in the session and refresh the updatepanel

void ib_Click(object sender, ImageClickEventArgs e)
{
Session["ShowPane"] = "1";
UpdatePanel1.Update();

}

iii) override the render and show the panel based on the session

protected override void Render(HtmlTextWriter writer)
{

if (Session["ShowPane"] != null)
{
if (Session["ShowPane"].ToString() == "1")
{
ModalPopupExtender1.Show();
}
}


base.Render(writer);
}

I think the smart thing to do would be to stop the postback in the firstplace, does anyone know how to do this?

Invoke ModalPopupExtenders .Show() method within javascript code

Hi,

A colleague wrote an extender to validate an address (street name & postal code). He uses a web service for that BUT he didn't write the necessary code in the _onMethodFailed method !

In this method I woud like to display a popup containing 'yes' and 'no' buttons (to ask the customer if he wants to keep the wrong values or no).

Currently, I have an asp:panel with a ModalPopupExtender (which ID is 'AddressErrorPopup') linked on it.

So, in the address validation extender I would like to do something like that :

_onMethodFailed: function(err, response, context) { if (this._popupValue) { var popupExtender = $get(this._popupValue); if (popupExtender) popupExtender.Show(); }}


the _popupValue variable contains 'AddressErrorPopup' : the ID of the ModalPopupExtender.

Problem : the $get(this._popupValue) returns null...

Is there a way to invoke the Show() method of a ModalPopupExtender in the javascript code of an other extender on the same form ?

Thx for your answer...

You need to use $find instead of $get to locate ajax controls. $get is for DOM elements.

Also, make sure that the modalpopup has BehaviorID="AddressErrorPopup" as the actual client ID may be different depending on the naming container hierarchy. Store the BehaviorID in the _popupValue property and then you should find the popup OK regardless of the naming container.


Ok !

Thank you for your help, this is exactly what I needed.

I'm not good at javascript/ajax, sorry for thatConfused


No need to be sorry...that's an easy mistake to make. Working with the ajax toolkit, you will become good at javascriptSmile

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 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 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