Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Wednesday, March 28, 2012

Calling jvascript function from the button under UpdatePanel

Hello,

I am having a a web application developed using asp.net2.0 with vb.net as a language.

In this web application i am having two buttons and one update panel. Now my button1 is outside the updatepanel and another button2 is present inside the updatepanel.

In asp.net if we want to run any javascript function on the click of a button then we normally use the button.attribute.add() function but if we want that when user click on button then first some server side code will be performed and then the javascript function will be called.

For that we uses the below code in asp.net !!!

Page.ClientScript.RegisterClientScriptBlock(Me.GetType,"Script", "<Script>alert('Hello');</Script>")

this code is working fine on the click event of the button that is present outside the update panel. But when i am running the same code on the click event of the button that is present inside the updatepanel then its not working,

Remeber that i d't want to run the javascript code when user just click on the button , i want first some server side code wil perform his work then after this script will run.

But for controls under update panel its not working.??

please paste your code here, because I am doing almost the same thing here without any issues.


Hi,

Add a Literal control to your web form.

In your Click method use this code:

literal1.Text = "<script type=\"text/javascript\"> alert('Hello world!');</script>";

Dont forget to clear Text property in another postbacks.


Use ScriptManager.RegisterStartupScript, instead of the ClientScript class' method.


Can anyone tell me the solution for this?

Me too getting the same issue.

Thanks,

Jasmeeta.

Calling javascript when a page has refreshed

I have an AJAX app that needs to call a javascript function when the page changes its state (for example some panels are hidden/displayed).

Due to the nature of AJAX, I can't use window.onload since no load event occurs.

What can I use to call my javascript functions when the page content changes?

If you are using UpdatePanels you can handle the PageRequestManager events:

http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/default.aspx


It worked!

I had a javascript function called adjustHeight.


I added

<head>... <script type="text/javascript"> function adjustHeight() { . . . } window.onLoad = function() { Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(adjustHeight); } </script>

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 JavaScript Function From C#

Dear Team

i am using VS2005 ASP.NET 2.0 C# JavaScript AJAX
i want on timer tick in side uodate panel to call javascript Function()
so how can i do that.

thank you

I would very much like to know how to do that too.

I have a ModalPopup containing SimpleViewer, and I need to set the path to an xml file when the user clicks an imagebutton, but as there is no postback going on I can't add that path or whatever it might be to the JavaScript block.

So I relaly need for the JavaScript block to be "loaded" and executed when the user clicks one of many buttons and then load the javascript based on that.


This is a great resource on using a TimerControl with an UpdatePanel:

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

However if you want to execute a JavaScript function before/during/after an UpdatePanel is refreshed you will need to explore the PageRequestManagerClass:

http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/default.aspx

You can add the following Javascript to a page:

<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
function pageLoaded(sender, args) {
if (args.get_panelsUpdated().length > 0){
alert('a panel was just updated!');
// doSomeFunction();
}
}
</script>

Cheers,
Al

Calling Javascript function as a property for an extender

Hi,

I have written a custom extender. In this custom externder, after a specific function is called, I would like to call another javascript function. This custom extender is re-used in various scenarios.So the javascript function to call is different in different scenarios. Code for all these scenarios cannot be put in the extender js file. So I would like to pass a dynamic javascript function name as a property value to the extender, and also give it the path of the js file which contains this javascript function. However I am unable to write this.

Can some one help please


Regards

Raj

Hi,

You can use eval function to invoke a function with its name.

For instance:

// in the .js file of the extender

function handler()
{
// a specific function
eval(_functionNameFiled + '();'); //_functionNameFiled is a field that hold the name of the function to be invoked
}


Marked your property asExtenderControlMethod, make this property as a function interface

calling javascript function after asychronous call back event

I have a grid showing a list of records and a 'AddNew' Button on page. When user clicks on 'AddNew' a 'Table' which is not visible by default becomes visible using javascript and setting 'style.visible='visible'' and 'style.display='block'' properties. Now when user enters the data for new listing and click on 'Save Data' button i am sending an aschrounous call back using AJAX tool kit and UpdatePanel. Everything workes fine and record is entered withour complete Page Postback. But after the record is inserted and Grid is refreshed with asychronous postback what i want is to Hide that 'Add New' table and just wanted to show Grid on page. And the problem is i am not able to call the javascript function after asychronous call back which hides the Table.

Any suggestions?

Look into the Sys.WebForms.PageLoadedEventArgs class.

http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageLoadedEventArgsClass/default.aspx

(its a lot easier than the docs make it look)

<script type="text/javascript">var postbackElement;Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded); function beginRequest(sender, args) { postbackElement = args.get_postBackElement(); } function pageLoaded(sender, args) { var updatedPanels = args.get_panelsUpdated(); if (typeof(postbackElement) === "undefined") { return; } else if (postbackElement.id.toLowerCase().indexOf(YOURPOSTBACKELEMENT) > -1) { //WHATEVER SCRIPT YOU NEED TO RUN } }</script>

Thankslilconnorpeterson ! your solution worked fine but fortunately i came to know that the problembecomes really simple and there is no need for calling javascript and making a Table Visible/Invisible if i replace the HTML table with server side Panel. Now i can simple make it Visible/Invisible by setting its Visible/Invsible property to true/false in codebehind.

Regards,

Zeeshan Malik

Calling javascript from a js file

I have a js file that contains the function that i want called when the user clicks on the textbox and the calendarextender is shown

calendarextender.onShown = functionName

Working with a single page i have put this at the top inside the head

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

With a single page is works perfectly but now i want to make it add this to a master page

creating a masterpage i have also added the same line inside the head, but when i try and run my content page and click on the textbox i get "Error: object is required"

I have viewed the source and made sure that the <script> line is present. Also have tried pasting the function directly on the master page instead of pointing to a file

<script type= "text/javascript" >

function dosomething() </script>

and i get the same error

anybody got a suggestion on how i can get my master/content page to work with my js file

Thanks

allan

I could be wrong, but I don't think the <head /> element from the Master Page is included when the page is sent to the browser - you normally set the info in the content page as you'd expect things like the title and meta tags to be different.

You can do a quick "view - source" on the executed page to check this and if it's the case, you could included the script tag right at the top of your <body /> element - as long as it appears before the call to the function.

Calling javascript from a control

I think this is a newbie question but it has me stumped.

I want to call a javascript function on a control when an event is fired. Specifically I want to call a javascript function when the value of a label changes.

i.e.

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

When that changes, call the javascript function HelloWorld()

that label is getting updated through a slidercontrol, so I was thinking about using the "onunload" event, but I'm really not sure.

I don't think the label control has onchange event in javascript. You could implement an AJAX timer and check if the label was change every x amount of second.

Sample how to use the Ajax timer here:http://alpascual.com/blog/al/archive/2006/12/21/Code-Snip-_2200_AJAX-Timer_2200_.aspx

Calling function on Codebehind from client side scripting using ASP.NET AJAX

Hi,

I'm relatively new to the new avtar of AJAX. I've used the Ajax.dll in my previous application to make an AJAX call.

Now my issue is. How do i call a function on my code behind page , from my client side javascript. To elaborate this consider the following.

I'm creating a new ASP.NET AJAX Web Site.

I've Defaul.aspx with following controls.

1. a button.

2.a dropdown.

In my Default.vb page i've a function FillComboValues() that returns a string.

No on clicking Button i wanna run the FillComboValues() function on my code behind.( I DONT WANT TO USE UPDATEPANEL.)

I've read many articles on net to solvemy problem but every example describes how to access a webservice method. none of them have described how to access a pagemethod.

Pls help me out with this ...

Thanks in advance.

----

In previous version of ajax , we needed to register the server side function using <Ajax.AjaxMethod()> _ . isn't there an equivalent way of registering the function.?

Hi,

Same problem for me, plz let me know whether you have found a solution for this or not?

Thanks


Hi, you can only call static functions of codebehind from javascript normally. Create a static function in codebehind and in javascript just call it in the following way:

say your static method is returning some string value, then in javascript you have to write,

var returnedValue = <% ="'" + ReturnHello() + "'" %>


In order to call a function on codebehind you can use either a WebService or an static method. I had the same problem and i used static methods because it′s more like Ajax.AjaxMethod, The first thing to do is to add to the scripmanager the following line EnablePageMethods="true" and then in code behing put [WebMethod] in front of every method you want to use. To call them from your client script, just use PageMethods.[your method name] and you should be good to go....


i am speaking about the code behind file of aspx page (not asmx-webservice). You can not use [WebMethod] in codebehind file.

In previous version of ajax , we needed to register the server side function using[Ajax.AjaxMethod()] {in codebehind} . isn't there an equivalent way of registering the function.?

Pleaes let me know if you have any thing equivalent to this?


SaiTej:

i am speaking about the code behind file of aspx page (not asmx-webservice). You can not use [WebMethod] in codebehind file.

In previous version of ajax , we needed to register the server side function using[Ajax.AjaxMethod()] {in codebehind} . isn't there an equivalent way of registering the function.?

Please let me know if you have any thing equivalent to this?

Alternate method inAjax Extensions is putting the control (for ex:button) in Update panel. All the events that u write for this control are async.

So no need to declare explicitly[Ajax.AjaxMethod()]


asj:

Equivalent way inAjax Extensions is putting the control (for ex:button) in Update panel. All the events that u write for this control are async.

So no need to declare explicitly[Ajax.AjaxMethod()]

Calling Clinet Function from Code Behind (Inside Ajax Update panel)

Hi,

Can anyone please provide information on how I can do this:

I have a GridView control inside an Ajax Update panel and have wired the Selected IndexChanged action to call a Client side Javascript function (ViewReceipt()). Unfortunately it doesn't seem to work except if I take the control outside the update panel.

Have posted my code below..

protected void rgvInv_SelectedIndexChanged(object sender, EventArgs e)
{
// Now execute the client-side stuff...
StringBuilder sbScript = new StringBuilder();
sbScript.Append("\n<script language=\"JavaScript\" type=\"text/javascript\">\n");
sbScript.Append("<!--\n");
sbScript.Append("ViewReceipt();\n");
sbScript.Append("// -->\n");
sbScript.Append("</script>\n");
this.RegisterStartupScript("ClientSideCall", sbScript.ToString());
}

Regards..

Peter.

Hi,

Found some posts on this and tried to add the recommended code but still getting a syntax error, hope someone can help out..

code behind:

protected void rgvInv_SelectedIndexChanged(object sender, EventArgs e)
{
// Now execute the client-side stuff...
StringBuilder sbScript = new StringBuilder();
sbScript.Append("\n<script language=\"JavaScript\" type=\"text/javascript\">\n");
sbScript.Append("<!--\n");
sbScript.Append("EditReceipt();\n");
sbScript.Append("// -->\n");
sbScript.Append("</script>\n");
//this.RegisterStartupScript("ClientSideCall", sbScript.ToString());
//ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "ClientSideCall", sbScript.ToString(), true);
ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientSideCall", sbScript.ToString(), true);

}

Javascript Function:

function EditReceipt()
{
var manager = GetRadWindowManager();
var rwEntry = manager.GetWindowByName("rwReceipt");
}


Regards..

Peter.


Hi Peter,

The problem with your code is that you should specify the last parameter to false in RegisterStartupScript method.

This parameter indicates that <script> tag will be added automatically to wrap the sbScript. Since you've done that manually, so false should be used.

Like this:

ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientSideCall", sbScript.ToString(), false);

Hope this helps.


Hi Peter,

Give full definition of EditScript() function then only I can help to you.

Regards,

Aru


Raymond,

Thanks for the information, I have already implemented a work around by moving the grid outside of the update panel. I'm using a telerik grid which has inbuilt AJAX and there are some clientside events which can be hooked into that has given me the functionality I require, anyway thanks for the information I can use it else where later.

Regards..

PeterBig Smile

Calling AJAX function

Hi, I wonder if there's a way to call an AJAX function via code behind page. That is, I have an asp tab control on my page, in which on pressing a tab I open a menu via AJAX code and ask user to enter password then I validate that password and want to select that tab if password is correct. Since my tab is asp control the AJAX code doesn't know that so I have to return the password to the code behind page but since I have to call such function through AJAX:

[Ajax.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
public void CheckRoomPsw(string psw)
{

...

}

I don't have access to Tab control because this returns null, so there's two options which I don't know how to perform:

1. call an AJAX control from CheckRoomPsw(string psw)

2. get an access to tab control in CheckRoomPsw(string psw)

Any idea is appreciated.

have you tried using the findControl function. it lets you access a conrol by referencing its location and using its ID. so if you had a bunch of controls on your form and wanted to get to one you could do.

form1.findControl("controlIDgoesHere");

if yours is inside of some ajax stuff it might be like

UpdatePanel1.findControl("myControlsID");

then you can just cast that to reference the object type

string value = ((TextBox)form1.findControl("txtUserName")).Text;


Actually, I've done that:

[Ajax.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
public void CheckRoomPsw(string psw)
{
JQD.TabStrip ts = (JQD.TabStrip)this.FindControl("TabStrip1");
ts.SelectTab(Global.tabPos);
}

but this returns null!!

I think it's because CheckRoomPsw() is an AJAX function


Perform the tab selection on the client-side callback. Return a boolean from the AJAX method after you check the password, if it is true perform the tab selection.


Also, it looks like you're using AJAX.NET, which is a completely separate product from ASP.NET AJAX, so you might want to see if they have a forum.


Have you had luck fixing your issue?

-Damien


Not yet!

I'm still looking for solution!


Have you tried doing the tab selection client-side?


I tried much to get access to the tab control from js code (client side) but since the tab control is an asp user control, it can't be known from js code.


Use theOnClientActiveTabChangedproperty on the tab. Seehttp://asp.net/AJAX/Control-Toolkit/Live/Tabs/Tabs.aspx for more information.

-Damien


Thanks for your concern Domien!

However, I'm not using AJAX.net and don't know much about itEmbarrassed and it's a bit risky to change my tab control now that I'm on the final steps of completing my project

IS there any other solution please

Calling a Web service method that returns an XmlDocument object

I'm calling a webservice method that returns an XmlDocument object. I'm getting the result back object back, but in my SuccededCallback function I'm having trouble navigating through the object with JavaScript. I'm trying to use methods on the object like .selectsinglenode and .selectnodes etc, but I keep getting a script error; "Object doesn't support this property or method. Any ideas? I'll post some of the code i'm trying to work with below.

Here is how i call the method from the client ...

Navegate.Services.GeneralTasks.GetSelectedPartyNumber(guid, id, SucceededCallback, FailedCallback);

Here is the web method ...

<WebMethod()> _

<ScriptMethod(ResponseFormat:=ResponseFormat.Xml)> _

PublicFunction GetSelectedPartyNumber(ByVal sessionguidAsString,ByVal idAsInteger)As XmlDocumentDim oXmlDocumentAs XmlDocument

oXmlDocument =

New XmlDocumentWith oXmlDocument

.LoadXml(

"<DocumentPacket><Company><Number>12345</Number></Company></DocumentPacket>")EndWithReturn oXmlDocument

EndFunction

And here is how i handle the response from the webservice method but get an error on .selectsinglenode ...

function

SucceededCallback(result)

{

alert(result.selectsinglenode(

"DocumentPacket/Company/Number").text);

}

Umm... Since it took five hours for this to post i was able to find the solution elsewhere.

I worked after I user .selectSingleNode instead of .selectsinglenode.

Calling a simple JS Function in the "Atlas way"

How could I, from an server-side control (like a Button), call an JS Function?
In the "old way", I used theRegisterClientSideScriptBlock to do this, but it does not work in the Atlas.

Thanks in Advance for the attention,
Fract4L

RegisterClientSideScriptBlock isn't working anymore for you with Atlas? Could you post a code sample showing the problem and describe what error you're getting if any?


I haven't tested this with Atlas but I assume it should work. This might even be some deprecated method of calling a JS funcion from a .NET control but I would always add the following to the page_load.

Button1.Attributes.Add("OnClick", "HelloWorld();")

Not sure again if this will work in Atlas, but it does add the js event function to the button itself.

JoeWeb


hello.

use the overload that has a boolean as its last parameter. this method will generate the correct script block in all cases (i think that you're script string has <script type='javascriopt'> on it, right? if you fo this, it won't work in atlas because only the scripts that have the type attribute set to text/javascript will be correctly loaded by the platform).

regarding the bt click handling on the client side, you can also use the new onclientclick property intesad of using the attributes collection.


Hello all,

TheRegisterClientScriptBlock was deprecated in favor of the classClientScript, that has all the funcionallities of the old method and some new ones.


Either way, thanks in advance for your fast responses and I hope that this question could help others.

Fract4L

Here is the code:

1protected void btnAccess_Click(object sender, EventArgs e)2{3// this works fine ;-)4StringBuilder sb =new StringBuilder();5sb.Append("<script type=\"text/javascript\">");6sb.Append("alert('test');");7sb.Append("</" +"script>");8ClientScript.RegisterClientScriptBlock(this.GetType(),"test", sb.ToString());9}

hello.

i'd remove the lines <script> and </script> and add ,true to the registerclientscriptblock method.

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

calling a javascript function in tabpanels button

Hi

I want to call a javascript function on a button_click() event. I was able to call this function without using tabcontrol. but I want to call this function by clicking on a button which is inside a tabpanel control .

Thanks in Advance

It should work, what is you code?

Can you provide a repro?


I have two tab panels , first one showinggoogle map .

<cc1:TabPanel ID="tab_google" runat="server">

<HeaderTemplate>Google Map</HeaderTemplate>
<ContentTemplate>
<div id="map" style="width:617;height:400" >

</div>
<input type="hidden" id="go" runat="server"/>
</ContentTemplate>
</cc1:TabPanel>

Its woking properly

and second tab panel having two <select> control.

See Below for Code

<cc1:TabPanel id="tab_distancecalc" runat="server" >
<HeaderTemplate>Distance Calculator</HeaderTemplate>
<ContentTemplate>
<div id="distance_calc" >
<form name=xyz>
<table cellspacing=0 cellpadding=0 align=center border=0>
<tbody>
<tr>
<td><font face=Verdana color=#800000 size=-1><b>Originating Point :</b></font></td>
<td align=left><b><font face=Verdana color=#800000 size=-1>Terminal Point :</font></b></td>
</tr>
<tr>
<td align="center">
<select size=12 name=abc>
<option
value=/1/0.158995591/-1/1.369611552 selected>Abiramam ,TN</option>
<option value=/1/0.526186067/-1/1.295638007>Abohar ,Punjab</option>
<option value=/1/0.371031746/-1/1.353291005>Achalpur ,Maharashtra</option>
<option
value=/1/0.275936067/-1/1.396306437>Addanki ,AP</option
<option
value=/1/0.343536596/-1/1.371362434>Adilabad ,AP</option>

</select>
</td>

<td align=middle>
<select size=12 name=pqr>
<option
value=/1/0.158995591/-1/1.369611552 selected>Abiramam ,TN</option
<option value=/1/0.526186067/-1/1.295638007>Abohar ,Punjab</option>
<option value=/1/0.371031746/-1/1.353291005>Achalpur ,Maharashtra</option>
<option
value=/1/0.275936067/-1/1.396306437>Addanki ,AP</option>
<option
value=/1/0.343536596/-1/1.371362434>Adilabad ,AP</option>
<option
value=/1/0.27280291/-1/1.349202381>Adoni ,AP</option>
<option
value=/1/0.410181658/-1/1.502780423>Adra ,WB</option>
</select>
</td>
</tr>
</tbody>
</table>
<p align="center">
<input onClick=DoCalc() type=button value=" Measure " name="button"></p>
<asp:Button ID="btn_mesure" runat="server" Text="Mesure" OnClientClick="DoCalc() return false" CausesValidation="False" ValidationGroup="distance_calc" />
</form>
</div>

</ContentTemplate>
</cc1:TabPanel>

Here is Java Script (This Java Script function should display distance )

<script language=JavaScript>
<!-- Begin
var eind=new Array();
var tourism=new Array();
var a=0;
var b=0;
function DoCalc() {
if (xyz.abc.options[xyz.abc.selectedIndex].value == null || xyz.pqr.options[xyz.pqr.selectedIndex].value==null) {
alert("Please enter both an Originating and a terminal place.");
}
else {
eind=xyz.abc.options[xyz.abc.selectedIndex].value.split("/");
tourism=xyz.pqr.options[xyz.pqr.selectedIndex].value.split("/");
d=Math.acos(Math.sin(eind[2])
*Math.sin(tourism[2])
+Math.cos(eind[2])
*Math.cos(tourism[2])
*Math.cos(eind[4]-tourism[4]));
a=Math.round(3956.073*d);
if (Math.sin(tourism[4]-eind[4]) < 0) {
b=Math.acos((Math.sin(tourism[2])
-Math.sin(eind[2])*Math.cos(d))
/(Math.sin(d)*Math.cos(eind[2])));
}
else {
b=2*Math.PI
-Math.acos((Math.sin(tourism[2])
-Math.sin(eind[2])
*Math.cos(d))/(Math.sin(d)
*Math.cos(eind[2])));
}
b=b*(180/Math.PI);
alert("Distance measured is:" +" " + Math.round(a*1.6094) +" "+ "kms.");
alert("hi");
}
}
// End -->
</script>


It has nothing to do with the tab panel. Calling a javascript function is the same no matter how many layers of control nesting there are. The problem is that you are missing a semicolon between "DoCalc()" and "return false". Use:

OnClientClick="DoCalc(); return false"
or
OnClientClick="DoCalc(); return false;"


I am geeting java script error "xyz is undefined"

xyz is a form which is declared inside tabpanel.


Hi,

May you try document.getElementById("xyz"), If xyz is runat server,use document.getElementById("<%=xyz.clientID%>").

Best Regards,

Calling a JavaScript function after return from callback in UpdatePanel

Hi all.

I am trying to solve this focusing problem inherint in Atas, I have a 90% generic solution, but am missing the last piece to the puzzle.

I need a way to invoke a JavaScript function after the UpdatePanel has returned from a server callback.

I know this is pretty simple to do without an UpdatePanel, unfortunately I am kinda tied into the UpdatePanel.

Any help??

Thanks

Hi,

I had the same problem. This is the solution I could found.
See this post for reference:http://forums.asp.net/thread/1290506.aspx

function pageLoad()
{
$object("_PageRequestManager").propertyChanged.add(BindOnLoad);
}


function BindOnLoad(sender, args)
{

if (args.get_propertyName() == "inPostBack"){
if (!$object("_PageRequestManager").get_inPostBack()){
AtlasPostBack();}
}
}

function AtlasPostBack()
{ //Runs at every postback. This allows us to run things that need to be taken care of
//after postbacks

alert("partial postback is done");
}


Thanks,

I also found that from the server side, registering a script as a startup script will make it fire on every callback.

Page.ClientScript.RegisterStartupScript.

CallBack Fails

In my website I had a callback function that works perfectly fine, but sometimes it fails and doesn't work.

I am not getting the point of failure. Is there any reason for callback failing.

Please post the code, callbacks can fail when you register the same call back function somewhere else, also remember that every control in that page will received the callback.