Showing posts with label server. Show all posts
Showing posts with label server. Show all posts

Wednesday, March 28, 2012

calling javascript in atlas

Hi,

I want to call a javascript function when call is made to server using atlas.

For e.g. instead of using ProgressBar of atlas which makes a div tag visible till server response comes in,I want to do some other processing through a javascript function till server response comes in (like hiding button).

Is it possible ?

thanks in advance for response

hello.

yes, you can...search this forum for pagerequestmanager _inPostback...you should find 1 or 2 examples that show how to do that.

calling javascript function in atlas

Hi,

I want to call a javascript function when call is made to server using atlas.

For e.g. instead of using ProgressBar of atlas which makes a div tag visible till server response comes in,I want to do some other processing through a javascript function till server response comes in.

Is it possible ?

thanks in advance for response

I believe this is not a Toolkit issue; please see FAQ topic "Posting in the right forum". Thanks!

Calling from client to server directly

Hi,

i want to access my server session values from the client using Ajax.Net, and i'm unsure how to do that.

does the only way to access the server from the client (without a postback) is using a web service? can i access

the server methods in my code behind file?

if someone can attach some code sample it will be greatly appreciated

This is actually pretty easy to do by taking advantage of the "WebMethods" feature of ASP.NET AJAX.

http://ajax.asp.net/docs/tutorials/ExposingWebServicesToAJAXTutorial.aspx

Notice the last section on "Calling Static Methods". The drawback is that your method will need to be static. Fortunately, you can still grab the session values by using

HttpContext.Current.Session[key]

hth

-Tony


Hi,

thanks, but this is the code i use right now.

for some reason, i can't make it work when the methods marked as [WebMethod] are in the code behind file - only in the code infornt...

is this a known limitation??

thanks


Not sure what you mean by only being able to get this to work in the code infront. Are you sure that your page is set up to use the codebehind file? What does your method declaration look like? Is it possible that your code behind file isn't compiling due to an error?
If you're refering to the codefile for teh page itself, you have to do a couple things. first, the method in the codefile has to be static, and second the scriptmanager has to have EnablePageMethods=true. After that, you should be able to call it from js via PageMethods.MethodName();

Hi,

My code behind file is configured correctly, and i can call other methods in the code behind file.

my method is marked as public static, and has the

[WebMethod] flag on it.

when my method is declared in the ASPX file under <script runat="server"> tags, it works fine

and i can access my server objects , when i copy it into my code behind file inside the class

representing the page, i get a javascipt error saying "PageMethods is undefined"

any ideas??

thanks


Hi shahar_lazer,

Can you post your code over here so we can test and hopefully fix it for you? Thanks

Regards,


I'd start looking in 2 places. Do you have a script manager on the page? If so, do you have EnablePageMethods=true?

The second place you should look is your web.config. Is this a new "AJAX" project, or are you upgrading an older app? The Web.config needs to have certain entries in it to make everything work, including PageMethods. Try creating a new AJAX project and defining and testing a PageMethod there - if that works, you can narrow it down to your app, and likely your config.


Hi,

Tried my code inside an Ajax project and got the same results.

here is my code (basically taken from the site examples)

<%@. Page Language="C#" MasterPageFile="/MasterPages/BaseTemplate.Master" %><%@. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %><%@. Import Namespace="System.Web.Services" %><%@. Import Namespace="Common" %><script runat="server"> </script><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderPage" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> <Scripts> <asp:ScriptReference Path="PageMethod.js"/> </Scripts> </asp:ScriptManager> <center> <table> <tr align="left"> <td>Write current date and time in session state:</td> <td> <input type="Button" onclick="SetSessionValue('SessionValue', 139135)" value="Write" /> </td> </tr> <tr align="left"> <td>Read current date and time from session state:</td> <td> <input type="Button" onclick="GetSessionValue('SessionValue')" value="Read" /> </td> </tr> </table> </center> <hr/> <span style="background-color:Aqua" id="ResultId"></span> </asp:Content>
 
 

PageMethods.js looks like this:

// PageMethods.jsvar displayElement;// Initializes global variables and session state.function pageLoad(){ displayElement = $get("ResultId"); PageMethods.SetSessionValue("SessionValue", Date(), OnSucceeded, OnFailed);}// Gets the session state value.function GetSessionValue(key) { PageMethods.GetSessionValue(key, OnSucceeded, OnFailed);}//Sets the session state value.function SetSessionValue(key, value) { PageMethods.SetSessionValue(key, value, OnSucceeded, OnFailed);}// Callback function invoked on successful // completion of the page method.function OnSucceeded(result, userContext, methodName) { if (methodName == "GetSessionValue") { displayElement.innerHTML = "Current session state value: " + result; }}// Callback function invoked on failure // of the page method.function OnFailed(error, userContext, methodName) { if(error !== null) { displayElement.innerHTML = "An error occurred: " + error.get_message(); }}if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
 
i'm getting the feeling it is simply a limitation in the current version of Ajax.Net to use these
methods in the code behind file - did someone pullled that off??
 
thanks

Hi,

Tried my code inside an Ajax project and got the same results.

here is my code (basically taken from the site examples)

<%@. Page Language="C#" MasterPageFile="/MasterPages/BaseTemplate.Master" %><%@. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %><%@. Import Namespace="System.Web.Services" %><%@. Import Namespace="Common" %><script runat="server"> </script><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderPage" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> <Scripts> <asp:ScriptReference Path="PageMethod.js"/> </Scripts> </asp:ScriptManager> <center> <table> <tr align="left"> <td>Write current date and time in session state:</td> <td> <input type="Button" onclick="SetSessionValue('SessionValue', 139135)" value="Write" /> </td> </tr> <tr align="left"> <td>Read current date and time from session state:</td> <td> <input type="Button" onclick="GetSessionValue('SessionValue')" value="Read" /> </td> </tr> </table> </center> <hr/> <span style="background-color:Aqua" id="ResultId"></span> </asp:Content>
 
 

PageMethods.js looks like this:

// PageMethods.jsvar displayElement;// Initializes global variables and session state.function pageLoad(){ displayElement = $get("ResultId"); PageMethods.SetSessionValue("SessionValue", Date(), OnSucceeded, OnFailed);}// Gets the session state value.function GetSessionValue(key) { PageMethods.GetSessionValue(key, OnSucceeded, OnFailed);}//Sets the session state value.function SetSessionValue(key, value) { PageMethods.SetSessionValue(key, value, OnSucceeded, OnFailed);}// Callback function invoked on successful // completion of the page method.function OnSucceeded(result, userContext, methodName) { if (methodName == "GetSessionValue") { displayElement.innerHTML = "Current session state value: " + result; }}// Callback function invoked on failure // of the page method.function OnFailed(error, userContext, methodName) { if(error !== null) { displayElement.innerHTML = "An error occurred: " + error.get_message(); }}if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
 
i'm getting the feeling it is simply a limitation in the current version of Ajax.Net to use these
methods in the code behind file - did someone pullled that off??
 
thanks

Well, your code above you didn't include the relevant methods from the codefiel for us to evaluate, and in fact what you did copy looks a lot like a page that doesn't use a codefile (the @.import statements and the lack of the CodeFile= attribute in the @.Page directive being my first clues on that). Given that you're getting and setting session variables, however, do your C# methods int eh codefile have the EnableSession=true set on the webmethod attribute flags? that could be the problem as well.

that was the problem indeed!!! thanks!!Smile

Calling a server side method.

My experience lies with Ajax.net. I need to call a method passing parameters back on the server. What ATLAS methodology should I do?

Imagine the scenario where I have a ordered list and I have the option client side to change the order. After each order change (the client UI is modified), I need to just touch a method on the server. I don't need any response or updates back.

I would like to do something like this

function OnItemMoved( first, second )
{
AltasCall.MovingObject.MoveItems( first.ID, second.ID );
}

Hi,

a PageMethod seems appropriate for your scenario. Basically you have to add the [WebMethod] attribute on your server method (you have to declare this method in your Page class), make it public and then you will be able to call it on client side through the PageMethods namespace:

function OnItemMoved( first, second )
{
PageMethods.MyMethod(first, second);
}

I appreciate it greatly, works like a charm.

Do you know if it is possible to call another method outside the Page class's scope? This is library code, and I don't want to force the end user to declare this method on all their pages.


billrob458:


Do you know if it is possible to call another method outside the Page class's scope?


At the moment the methods must be put in the Page class. One solution to your problem would be to wrap the library method with a WebMethod and put it in a base class that inherits from Page. The other pages will then be derived from the base class.
Another solution would be to expose the reusable method as a web service - which can act as a wrapper for your library code. Then you can make the calls to the webservice from anywhere.

calling a server side method to rebind and refresh a datalist in updatepanel without a ful

I have 2 datalists:

datalist1 (inside UpdatePanel1)

datalist2 (outside UpdatePanel1)

I have a ImageButton inside the datalist2 & when it is clicked, in the datalist2_ItemCommand event, I am updating some information in the database & calling a DataBind() on datalist1 & then calling an Update() method of UpdatePanel1.

This works fine, but my problem is that because of the datalist2_ItemCommand getting fired, a full postback occurs as well. How do I avoid this? I just want the datalist1 to be refreshed inside the UpdatePanel & not refresh the datalist2 at all.

If I use Web Service method, then I can do the database update in it, but I am unable to access the datalist1 to rebind it and also the UpdatePanel1 to update it.

Can someone please help me.

Thanks

Hi,

You canregister theItemCommand event ofdatalist2as a trigger of the UpdatePanel in whichdatalist1 is contained.

<Triggers>
<asp:AsyncPostBackTrigger ControlID="DataList1" EventName="ItemCommand" />
</Triggers>

Best Regards,


I had logged this issue in another forum my mistake and it got moved in this forum only after I logged it again as a new post (link below):

http://forums.asp.net/p/1180380/2000803.aspx#2000803

Thanks for your help.

Calling a server side method from javascript without page methods

Hi everyone.

I'm trying to do some like this:

if (confirm("foo") == true) {

MyServerSideFunction();

}

Of course, I can call this function using PageMethods, but since this function in my code behind shold be static, I cannot call others methods inside my class.

Is there any way to call serer side methods without using PageMethods?

Thanks, and sorry for my bad english!

You can use ajax to call a webservice from javascript. Check out this article on how to do it:http://www.semenoff.dk/en/Code-Corner/ASP.Net.AJAX/WebService-From-JavaScript.aspx

Hope it helps


__doPostBack("ServerEventNameHere","");


Hi Everyone :)

@.Klaus Byskov Pedersen

I alread tryed using web services and it works fine, but it's not the case.

@.rpack79

Nice! It works! I noticed that I had to catch this requent inside my OnPageLoad and call the appropriated methods. Now one more question: And if I want do catch this postback inside an WebControl? Actualy I'm catching the postback event inside my control's OnInit event. Is it the right way?

Thanks a lot by the answers.

Calling a server side function from client side using the toolkit

Ok, I'm sure this is a really stupid question, but I'm willing to ask it anyway.

Let's say that I created a new extender called "My", so I now have three files files, MyExtender.cs, MyBehaviour.js, and MyDesigner.cs.

I want my control to be able to take some data on the client side and use it to retrieve some data on the server side, which AJAX is all about right? :) So for the sake of argument, let's say I want to enter an email address in a textbox, and then consult a database to return the user's password.

So in my MyExtender.cs file, I create a function something like this:

public string getPassword(string email) {

... Make some database calls to get the info

return password;

}

What code do I put into the MyBehaviour.js file in to to call the getPassword function? And do I need any special decorations on the getPassword() function to make it happen?

You can use ICallbackEventHandler interface for this purpose. This is the exact purpose of this interface in ASP.Net 2.0. Check out the MSDN for this interface.


You really should look at how to create an extender to do it the best way. There is a great tutorial here,http://www.asp.net/ajax/ajaxcontroltoolkit/samples/Walkthrough/CreatingNewExtender.aspx that is a simple example of how to create a simple extender. Also if you just want to use the code behind to retrieve info from the database, you may just want to wrap an update panel around your form and get the data from the code behind. Either way you will be able to accomplish what you want.

Calling a JS function from server side

Hi,

I try to call a javascript function from the server side but it doesn't work, here my code :

1<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>23<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">45<html xmlns="http://www.w3.org/1999/xhtml" >6<head runat="server">7 <title>Test</title>8</head>9<body>10 <form id="form1" runat="server">1112 <atlas:ScriptManager ID="scriptManager1" runat="server" EnablePartialRendering="true"></atlas:ScriptManager>1314 <atlas:UpdatePanel ID="UpdatePanel1" runat="server">15 <ContentTemplate>1617 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />18 <asp:TextBox ID="TextBox2" runat="server" Text="test"></asp:TextBox><br />19 <asp:Button ID="Button1" runat="server" Text="Write" OnClick="Button1_Click" />20 <asp:Button ID="Button2" runat="server" Text="Clear" OnClick="Button2_Click" />2122 </ContentTemplate>23 <Triggers>24 <atlas:ControlEventTrigger ControlID="Button1" EventName="Click" />25 <atlas:ControlEventTrigger ControlID="Button2" EventName="Click" />26 <atlas:ControlValueTrigger ControlID="TextBox1" PropertyName="Text" />27 </Triggers>28 </atlas:UpdatePanel>2930 </form>31</body>32</html>33

And the code behind :

1using System;2using System.Data;3using System.Configuration;4using System.Collections;5using System.Web;6using System.Web.Security;7using System.Web.UI;8using System.Web.UI.WebControls;9using System.Web.UI.WebControls.WebParts;10using System.Web.UI.HtmlControls;1112public partialclass test : System.Web.UI.Page13{14protected void Page_Load(object sender, EventArgs e)15 {1617 }1819public void Button1_Click(object sender, EventArgs e)20 {21 TextBox1.Text ="Button clicked";22 }2324public void Button2_Click(object sender, EventArgs e)25 {26 TextBox1.Text ="";27 Response.Write("<script type=\"text/javascript\">alert('hello');</script>");28 }2930}31

When i click on the button 2, my alert function is not called and the textbox 1 is not cleaned.

How can i call the JS function ?

Take a look at this post:http://forums.asp.net/thread/1395511.aspx
thank you :)

copy this code atButton2_Click

public void Button2_Click(object sender, EventArgs e)
25 {
26 TextBox1.Text ="";
27 Page.ClientScript.RegisterStartupScript(typeof(Page), "OnLoad", "alert('hello');",true );
28 }

See more details athttp://forums.asp.net/thread/1403704.aspx

Monday, March 26, 2012

Callback to server (by javascript) which updates an UpdatePanel

I already posted this in http://forums.asp.net/thread/1178950.aspx
but it seems to be a very general questions about callback in ASP.NET 2.0


I have a custom (image map like) control which reacts to clicks bya javascript. the javascript part sets postback values like x, y, andraises a postback by form.submit().

Now when I place thiscontrol on an UpdatePanel, the javascript:form.submit() raises apostback, but not a partial postback...

Do I have to register thejavascript somewhere else (expect RegisterClientScript or so)?

Or isthere a way to make a postback in order that the server updates theUpdatePanel with a new image?
I tried the Callback (implementing ICallBackProvider), but this seems only to be for delivering a stringvalue from server to client (at least I couldnt kick off any partialupdate of the page..)

Regards,

RayHi Ray,

Executing form.submit() will never cause a partial postback. A partial postback occurs within an UpdatePanel if the following is true. The control causing the postback is within the UpdatePanel or the control causing the postback is setup as a trigger of the UpdatePanel. These are the two situations that cause a postback.

In your case, there are a couple of options (or lots of options that I can't think of).

One option is that your custom control's click event could cause a postback. Causing a postback boils down to executing a JavaScript command: "__doPostback(params);". I'm not sure how you're registering the client side JavaScript that sets postback values X and Y, but you can generate the necessary JavaScript to cause a postback by executing "Page.ClientScript.GetPostBackClientHyperlink (params)" in code behind. You then associate this code with the onclick clientside event by executing "this.Attributes.add("onclick",postbackCommand)." It seems that this line of JavaScript would go after whatever other clientside code you needed to execute that set X and Y.

If for some reason doing it this way is not an option, you can always place a hidden button (not .NET hidden but CSS hidden) within the UpdatePanel and programmatically through JavaScript, click it. This presents some problems because you have to have the ClientId to find the exact button you need, which can be difficult as .NET generates this Id for you based upon control hierarchy.

So those are two options for causing a postback in your situation.

Hope this helps.

- Joel

Hi Joel

Thank you, the first option (__doPostback) works great for me.

Regards,

Ray

call webService server side

hi...

is that possiable to call webservice(that exists in the same IIS server), from server side?

thank you...

Of course. Run throught he Add a Web reference wizard in VWD or Visual Studio, it'll take you right through it.

hi..

yeh, i know that, but i ment, without referencing it into my project. i want to use remoting call to the webservice, even if it exists in the same server, can i do that?

thank you...


Well, you'd still typically create a proxy of some kind. I suppose you could build a new Request object and parse the xml response if you really wanted to, but what's the point?

Call Server Side method from JavaScript function in Master Page

I have a JavaScript function in a Master Page. The function is below.

function Add(q, p) {//call server side method }

I want to be able from within the JavaScript Add function defined above, call a C# server side method and pass the values q and p to it. No value is returned.

I have tried PageMethods.CallServerSideMethod(q, p); but it will only work in a Page, not a master page.

Is there any way I can do this in a master page?

How about using a web service call?

Thanks for your help.

How could i code that? An example maybe?


The documentation has pretty good code examples. See if this helps: http://www.asp.net/AJAX/Documentation/Live/tutorials/ExposingWebServicesToAJAXTutorial.aspx

Niall20:

it will only work in a Page, not a master page.

That's because .master file can't work as a httpHandler to server the request. It's blocked. In a simple word, the method in master page can't be accessed from client side directly.

Call server side function on javascript mouseover event?

Hi, I'm very new to ajax so please forgive me if this is a stupid question:

I have a hyperlink hooked to a mouseover event and an asp server side function called Test(). I like to know if there's any way in ASP.NET AJAX to call Test() when that mouseover event fires, and how to go about hooking this up. Code samples on how to do this would be helpful.

Thanks in advance.

Hi Totenkopf,

You can do what you want to do using the new client callback feature in asp.net 2.0 :

check these articles for more info -

http://www.devx.com/webdev/Article/28451/0/page/2

http://dotnetjunkies.com/Article/E80EC96F-1C32-4855-85AE-9E30EECF13D7.dcik

For other options check this post -

http://forums.asp.net/thread/1515994.aspx


Hmm, so can this be done at all using the existing AJAX extension? What I wish to accomplish is when a user mouseover a hyperlink, have a server-side method executes which populates a repeater control (these two are within an updatepanel)

Here's an ASP.NET AJAX solution. In this example, hovering over the link does the same thing as clicking on it. (Either action triggers an async postback.) For your example, put your repeater where I have the label. I hope this helps!

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><script runat="server"> public void click(object sender, EventArgs e) { lbl.Text = "Moused at " + DateTime.Now.ToString(); }</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 ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="up1" runat="server"> <ContentTemplate> <asp:LinkButton ID="hoverButton" runat="server" OnClick="click" onmouseover="__doPostBack(this.id, '');" Text="Mouse Over Me" /> <asp:Label ID="lbl" runat="server" /> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

Using the client callback doesn't give you the triggering you need. Unfortunately this can only be forked by using a private JS method that is included when you add an UpdatePanel.

On the client side, call the following method on the hover event:
Sys.WebForms.PageRequestManager.getInstance()._doPostBack(hyperlinkClientID,"Some String Argument");

Your custom hyperlink control should implementIPostBackEventHandler.

Create anOnHover event on you custom hyperlink control that can be used for triggering an update panel to refresh.

In theRaisePostBackEvent method that you have to implemented on your control, fire the OnHover event.


or yeah you can replace Sys.WebForms.PageRequestManager.getInstance()._doPostBack(hyperlinkClientID,"Some String Argument"); with __doPostBack(hyperlinkClientID,"Some String Argument");as shown be Steve.

Furthermore I forgot to mention you would have to register your control as an asyncronous control in OnPreRender():

ScriptManager

sm =ScriptManager.GetCurrent(this.Page);
if (sm !=null) sm.RegisterAsyncPostBackControl(this);

I've tried passing in an argument to the second parameter of __doPostBack, but I keep getting a "Invalid postback or callback argument..." popup. I then tried registering the control as suggested:

protected override void OnPreRender(System.EventArgs e)
{

ScriptManager sm = ScriptManager.GetCurrent(this.Page);
if (sm != null)
sm.RegisterAsyncPostBackControl(this);
}

... but then I get "The page cannot be registered through RegisterAsyncPostBackControl or RegisterPostBackControl"

I can get the argument with Request.Params.Get("__EVENTARGUMENT")if I disable EnableEventValidation, but is there any way to get this workingwithout setting EnableEventValidation to false?

Thanks for the help again.

Call server side function from javascript using ajax

Hi,

I want to call a server side function from javascript. Using Ajax.dll I am able to call a simple server side function but server side function containing webservice cannot be called. Does anyone have solution for this?

You should start out by watching this video:http://www.asp.net/learn/ajax-videos/video-79.aspx

Hope it helps


Thanks for the video.

It worked with ajax.dll. I had missed the Script service namespace in web service.

Call Server Side Function from Javascript

I wan to call Serverside function from Javascript function . We can use it by using AjaxPro.dll Assembly.

Can anybody have an idea how can we do that in new AjaxAsp.net extensions. I dont want to use Webservice . just want to call the web page class fucntion from html page using javascript.

use PageMethods.

there's a tutorial for it under the /docs web services section (all the way at the bottom). Basically, you flag a public static method in your codefile with the WebMethodAttribute and then your javascript can find it by claling PageMethods.myMethodName(params,onsuccess,onfailure) where 'myMethodName' is the name of the method in your page's codefile, params are any parameters it needs, and onsuccess and onfail are js functions to handle those events. You also need to set your scriptmanager's property EnablePathMethods=true.


I have tried this already and its gives me PageMethod undefined Error. ANd i have not found any soln. except of third party
Well, PageMethods do work, so there's probably some small mistake in your code or configuration. Perhaps you could post a sample of one that fails?
My guess is a missing EnablePageMethods="true" on your ScriptManager, though as Paul pointed out, we're just guessing until we can see what you've tried.

Call Server Side Function before showing Modal Popup

I m showing Modal Popup on click of Edit Link Button of Datagrid.

Now when Link button is clicked I want to show the values of that particular row in Modal Popup.

This has to be done at server side as it would be updation of row and it has dropdown which has to be filled at server side..

So plz help ..

Below i m attaching the code:

<%@dotnet.itags.org.PageLanguage="VB"AutoEventWireup="false"CodeFile="ModalPopUp_In_Datagrid.aspx.vb"Inherits="ModalPopUp_In_Datagrid" %>

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

<!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>Untitled Page</title>

<scripttype="text/javascript"language="javascript">

function shopModalPopup(employeeID){

//show the ModalPopupExtender

$get("<%=Label1.ClientID %>").value = employeeID;returnfalse;

}

</script>

<styletype="text/css">

.modalBackground

{

background-color:#000;

-moz-opacity:0.7;

opacity:.70;filter:alpha(opacity=70);

}

</style>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

</div>

<asp:PanelID="Panel1"runat="server"Height="50px"Width="125px">

<asp:GridViewID="GV1"runat="server"AutoGenerateColumns="False"DataKeyNames="RID">

<Columns>

<asp:BoundFieldDataField="rid"HeaderText="rid"/>

<asp:BoundFieldDataField="name"HeaderText="Name"/>

<asp:TemplateField>

<ItemTemplate>


<cc1:ModalPopupExtender ID="ModalPopupExtender2" runat="server" PopupControlID="popupPanel"
OkControlID="btnOk" CancelControlID="btnCancel" BackgroundCssClass="modalBackground" TargetControlID="lnkPopup">
</cc1:ModalPopupExtender>

<asp:LinkButtonrunat="server"Text="Popup"CommandName="EditRow"CausesValidation="false"ID="lnkPopup"OnCommand="lnkPopup_Command"></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

</asp:Panel>

<asp:PanelID="popupPanel"runat="server"Height="50px"Width="125px">

Click To Display Authors Name:

<asp:LabelID="Label1"runat="server"></asp:Label>

<br/>

<br/>

<asp:ButtonID="btnOk"runat="server"Text="OK"/>

<asp:ButtonID="btnCancel"runat="server"Text="Cancel"/>

</asp:Panel>

<br/>

</form>

</body>

</html>

Hi Varun,

Please don't attach a hidden Control(visible= false) to your ModalPopupExtender or it won't work because no Dom element generate to the client. Also don't put $get function before ScriptManager. Here is the sample , please pay attention to the "Bold" part.

<%@. Page Language="VB" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> Sub fill_values() Label1.Text = "a" End Sub Protected Sub GV1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) If e.CommandName = "EditRow" Then fill_values() ModalPopupExtender2.Show() End If End Sub</script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Untitled Page</title> <style type="text/css"> .modalBackground { background-color:Gray; filter:alpha(opacity=70); opacity:0.7; } .modalPopup { background-color:#FFD9D5; border-width:3px; border-style:solid; border-color:Gray; padding:3px; width:250px; } </style></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px"> <asp:GridView ID="GV1" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1" AllowPaging="True" onrowcommand="GV1_RowCommand" > <Columns> <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" /> <asp:BoundField DataField="LastName" HeaderText="LastName" /> <asp:BoundField DataField="FirstName" HeaderText="FirstName" /> <asp:BoundField DataField="Title" HeaderText="Title" /> <asp:TemplateField> <ItemTemplate> <asp:LinkButton runat="server" Text="Popup" CommandName="EditRow" CausesValidation="false" ID="lnkPopup"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString%>" SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [Title] FROM [Employees]"></asp:SqlDataSource> </asp:Panel> <asp:Panel ID="popupPanel" runat="server" CssClass="modalPopup" Height="200px" Width="200px" style="display:none"> Click To Display Authors Name: <asp:Label ID="Label1" runat="server"></asp:Label> <asp:Button ID="btnShowAuthorName" runat="server" Text="Show Author's Name" OnClientClick="getName(); return false;"></asp:Button><br /> <asp:Label ID="lblAuthorsName" runat="server" BackColor="Beige" ForeColor="Red"></asp:Label> <br /> <br /> <asp:Button ID="btnOk" runat="server" Text="OK" /> <asp:Button ID="btnCancel" runat="server" Text="Cancel" /> </asp:Panel><cc1:ModalPopupExtender ID="ModalPopupExtender2" runat="server" PopupControlID="popupPanel" BackgroundCssClass="modalBackground" TargetControlID="Label2" CancelControlID="btnCancel" OkControlID="btnOk"> </cc1:ModalPopupExtender> <div style="display:none"> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></div> <script type="text/javascript" language="javascript">function getName(){ var labelValue = $get("<%=Label1.ClientID%>").innerHTML; } </script> </form></body></html>

Best regards,

Jonathan


Hi Varun,

Here is another sample which won't postback when click to show the ModalPopupExtender.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<script runat="server"
protected void Page_Load(object sender, EventArgs e)
{
//Attach a Javascript funtion to the LinkButton.
LinkButton myLinkButton;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
myLinkButton = (LinkButton)GridView1.Rows[i].Cells[4].FindControl("LinkButton1");
myLinkButton.Attributes.Add("onclick", "shopModalPopup('" + GridView1.Rows[i].Cells[0].Text + "');return false;");
}
}
</script
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style>
.modalBackground {
background-color:Gray;
filter:alpha(opacity=70);
opacity:0.7;
}

.modalPopup {
background-color:#FFD9D5;
border-width:3px;
border-style:solid;
border-color:Gray;
padding:3px;
width:250px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" InsertVisible="False"
ReadOnly="True" SortExpression="EmployeeID" ItemStyle-Width="0" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server">Click On Me</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString%>"
SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [Title] FROM [Employees]">
</asp:SqlDataSource>
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Height="200px" Width="300px" style="display:none">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
EmployeeID:<asp:TextBox ID="tbEmployeeID" runat="server"></asp:TextBox> <br/>
Reason:<asp:TextBox ID="tbReason" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</asp:Panel>
<div style="display: none">
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Button1"
PopupControlID="Panel1" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
<script type="text/javascript" language="javascript">
function shopModalPopup(employeeID){
//show the ModalPopupExtender
$get("<%=tbEmployeeID.ClientID%>").value = employeeID;
$get("<%=tbReason.ClientID%>").value ="";
$find("<%=ModalPopupExtender1.ClientID%>").show();
}
</script>
</form>
</body>
</html>

Best regards,

Jonathan

Call server side function

Hi is there a way to call server side function using Atlas. I know we can access Code-Behind function usingPageMethods but i don't want to put all of my code in code-behind and neither do i want to inherit my class from System.Web.UI.Page class Instead i want to put it in separate class file. Is this possible without putting code in web service ?

TIA

hello.

well, you can use the network stack to get what you want. in these case, i'd suggest using web services because you can use the client generated proxies which simplifies the acess to those methods. you can, however, build your own handler and then invoke it from client side if none of the default available solutions are adequate to your scenario.

Saturday, March 24, 2012

Call Client script from Server Side

Hi All,

I want to call javascript function from server side when I am using updatePanel.

Actual Scenario is as follows:

I have one form A.aspx in which I have a button named "btn_display" and this button is in Update Panel.

Now I call server side function on btn_display_click and from that server side function i want to call javascript function.

How should I proceed??

Plz help

Thanks in advance

HI,
You can use registerclientscriptblock to allow the client script to work from a serverside event

Hello, RegisterStartupScript is more appropriate for this.

Regards. -LV

Call a WebMethod from javascript (I dont want to use any server side buttons only javascri

I think my problem is slightly different.

I have defined a region of an image using jquery (javascript) I check the click event, it something like onclick for button, so as you can see its all javascript nothing server side button, etc

I want to load a .asmx dynamically in an update panel. I know how to do this using a link button. Now what I want to do is to call a method that load this file in my server code behind.

This is what I tried to do so far. I simplified the problem.

' <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true">
<Scripts>
<asp:ScriptReference Path="JavaScript/loadmypages.js"/>
</Scripts>
</asp:ScriptManager>

'

loadmypages.js is a simple javascript that call my function (i am hoping that it will) through PageMethods. this is a simple style of my javascript.

'

// JScript File

var Load_content2 = function()
{
PageMethods.myfunction_on_code_behind(OnComplete1, OnTimeOut1, OnError1);
return false;
}

function OnComplete1(result)
{
alert(result);
}

function OnTimeOut1(result)
{
document.getElementById('lblMsg').innerHTML ="Time out";
}

function OnError1(result)
{
document.getElementById('lblMsg').innerHTML ="There is an error!";
}

'

I have tried to make my method accesable for javascript like this:

'

using System.Web.Services;

[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public string myfunction_on_code_behind()
{
return "Its good if it works";
}

'

but every time i click on that region the script debugger say PageMethods is not defined.

Could someone help me to solve this problem ? am I missing something here ? as you can see I have even enabled page method: EnablePageMethods="true"

Thank you

Hi,

Please note that the method should be a static method.
Hope this helps.
Can you post your whole webservice file here? I think you are missing something.

Has there been any updates to MS Ajax that don't require PageMethods to use static methods yet?


No, nor would I expect one in the future.

Wednesday, March 21, 2012

CalendarExtender problem in production server

Hello:

I've a strange problem with CalendarExtender Control. When I'm designing web application on my computer, this control works perfectly. When the textbox for date got focus, calendarextender shows correctly etc...

So, my problem is when I upload my Published Web to production server (with ajax installed, and net framework 2.0 etc..) and I navigate on the web, calendar extender returns to me an error "Object doesnt support this property or method."

I don't understand which is the difference between my computer and production server. I have same installed (excluding visual studio Net on production server, of course)

Web Application consist (to simplify) in one script manager, one update panel wich two textbox with calendarextender inside and a gridview)


Could you help me? Any ideas??

Thanks!


Xabi

Has someone already installed the ASP.NET AJAX Extensions on the production server?


In addition, please also check is there any difference between the configurations on two server's IIS.

CalendarExtender problem in format and position

i have a page contain CalendarExtender

.....

<li id="liDate" runat="server">
<asp:Label ID="lblDate" runat="server" AssociatedControlID="txtRegDate" Text="Date"></asp:Label>
<asp:TextBox ID="txtDate" runat="server" Enabled="false"></asp:TextBox>
<asp:ImageButton ID="imgbtnDate" runat="server" AlternateText="Click to show calendar" ImageUrl="~/images/Calendar.png" CausesValidation="false"></asp:ImageButton>
<ajaxToolkit:CalendarExtender ID="calendarExtenderDate" runat="server" TargetControlID="txtDate" PopupButtonID="imgbtnDate" Enabled="True">
</ajaxToolkit:CalendarExtender>
<asp:RequiredFieldValidator ID="ReqValDate" runat="server" ControlToValidate="txtDate" Display="Dynamic" ErrorMessage="Required" Text="Required" Visible="false">
</asp:RequiredFieldValidator>
</li>

......

when i click on image btn, it show th calendar but weird format , and even the position that the calendar pop up not below the Tartger txt that i set.

But it is so weird if i do something that postback of this page the format and position become correct . WEIRD BUGTongue Tied, need some help

Tks in advance

I get the lastest AjaxControlToolkit already, the Sep 1.0.109... version

Hi Conga,

I have tested your sample on my machine. <asp:Label ID="lblDate" runat="server"AssociatedControlID="txtRegDate"Text="Date"></asp:Label> I get a compile error when remove the Bold part. It works great. I use V10920 + VS2008. So would you please do a double check? If it doesn't work, please show me the whole sample.The more information you provided , the more easy we can find out the exact root cause.

Best regards,

Joanthan