Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Wednesday, March 28, 2012

Accessing server-side Datatable object from client-side javascript?

I am working on a control that generates 2D charts (line,bar,pie,etc) using VML (for now) to draw the charts client-side. I am new to Javascript and still cant figure out how to access the data I need to graph from the javascript side. I am currently using a Sys.Data.Datable on the client side as test data (building the table manually in javascript) and it works fine but I cannot figure how to pass a datatable from the server to the control extension behavior?

I have read/seen code on the forums on how to do this using a web-service but I am really looking at a more generic approach where people could just bind a datatable to the control via the properties or in code so they can use their business logic layer functionality without having to write web-services.

Let's say I have the name of the page object/variable holding the datatable (from properties of control) how would I access this object as a Sys.Data.Datatable in Javascript? Would I need to use some kind of converter?

(hope I explained myself correctly and this makes sense to someone hehe)

Thanks in Advance

Pascal

Hello Pascal:

> I am new to Javascript and still cant figure out how to access the data I need to graph from the javascript side.

Strictly speaking, you can't! It is the server-side code that renders client-side code, so what you can do is actually the reverse: write the datatable to javascript.

Here is a topic that can give some hints:http://forums.asp.net/thread/1285185.aspx

This said, please feel free to go deeper with your question if needed.

-LV


Thanks for the quick reply btw :)

Here is some example of what I am trying to do (not actual code):

Lets say I have some ASPX page code like...

<script language="VB"> Private sub Page_Load() dim myTable as System.Data.Datatable ... populate table ... End sub</script><html> <body> <atlas:ScriptManager runat="server" ID="PageScriptManager" EnablePartialRendering="True"> </atlas:ScriptManager> <asp:Panel ID="ChartPanel" runat="server" Height="300" Width="400" /> <cc1:ChartPanelExtender ID="ChartPanelExtender1" runat="server" > <cc1:ChartPanelProperties ChartTitle="This is my Graph!" TargetControlID="ChartPanel" ChartType="0" ChartHeight="100" ChartWidth="300" ChartBackColor="#FF3A00" ChartTitleFontFamily="Arial Black" ChartTitleFontSize="20" ChartTitleFontWeight="Normal" ChartTitleTextAlign="Right" /> </cc1:ChartPanelExtender> </body></html>

The ChartPanelExtender is an atlas control extender that has its functionality (chart graphing) in its ChartPanelBehavior.js javascript file. What I would like to do is access that myTable from inside the javascript behavior file? Is that possible?

Thanks in advance,

Pascal

Saturday, March 24, 2012

abortPostBack(); is not working..

Hi, I

I have written a javascript file as

Sys.Application.add_load(ApplicationLoadHandler)

function ApplicationLoadHandler(sender, args)

{

Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckStatus);

}

function CheckStatus(sender, args)

{

var prm = Sys.WebForms.PageRequestManager.getInstance();if (prm.get_isInAsyncPostBack() & args.get_postBackElement().id =='CancelRefresh')

{

alert('cancelling');

prm.abortPostBack();

alert('cancelled');

}

}

if(typeof(Sys) !=="undefined") Sys.Application.notifyScriptLoaded();

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

I have written this to cancel my dropdown list postback But request is not cancelling.

My .aspx code.. is

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

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

<Scripts>

<asp:ScriptReferencePath="Cancel.js"/>

</Scripts>

</asp:ScriptManager>

<div>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:DropDownListrunat="server"ID="ddl_testing"OnSelectedIndexChanged="ddl_testing_SelectedIndexChanged"AutoPostBack="True">

<asp:ListItemText="Manoj"></asp:ListItem>

<asp:ListItemText="Atul"></asp:ListItem>

<asp:ListItemText="Punit"></asp:ListItem>

</asp:DropDownList>

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

<br/>

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

</ContentTemplate>

</asp:UpdatePanel>

</div>

</form>

While my .cs code is as follow..

protectedvoid Page_Load(object sender,EventArgs e)

{

Label1.Text = ddl_testing.SelectedItem.Text;

}

protectedvoid ddl_testing_SelectedIndexChanged(object sender,EventArgs e)

{

System.Threading.Thread.Sleep(2000);

Label1.Text = ddl_testing.SelectedItem.Text.ToString();

}

}

But my ajax request is not cancelling on clikcking cancel button ..Can anybody tell me why..

Thanks in advance..

Since the Cancel button resides in the UpdatePanel it appends the NamingContainer in the ID.
Try indexof instead of exatct match:

args.get_postBackElement().id.indexOf ('CancelRefresh') > -1

Abort aysnc request when user clicks a menu link on the web page

Hi,

I've got my web page working with ASP.NET AJAX but the problem is when I click a link on pages menu I don't get taken to the new page until the page I'm on has received all the async. data from the server.

So, I need to know how to abort the async. requests when the menu link is clicked so it takes me straight to the newly requested page.


Thanks
Jon

You may want to look at the update progress. I think the at least the older releases had a way to do that there.
Hi,

You can use the following javascript function to abort an async call.

function CancelAsyncPostBack()
{
Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
}

Hope this helps.

Hi,

Just to test this, I added button to my page which calls the Cancel javascript function. After clicking this button I then click one of the menu links and I don't get taken to the new page until the AJAX stuff has finished.

Below provides more information and hopefully clarifies what I'm doing.


1) On page load a javascript function is called which loops through each row in the DataList table and makes an asynchronous call to a webservice method on the server.

2) It takes 10-20 seconds for the server to calculate the details for each request and then return the results to the callback function on the client, where the results get shown in appropriate columns of the DataList table.


I have 10 rows in my table so end up making 10 near simultaneous calls to the webservice on the server. Whilst waiting for the server to finish responding to these requests I click a link on the page and I want to be taken to the new page immediately. As it stands, I have to wait for the server to respond with all the requested data.


So, my questions are:

1) how do I stop the client waiting for the rest of the data so it goes to the new page?

2) Is it possible to tell the webservice on the server to quit working on the problem?

Thanks
Jon



The reason is because of theInternet Explorer's Simultaneous Connections Limit which is 2 by default.
Please refer to this: ?http://weblogs.asp.net/mschwarz/archive/2005/10/20/428047.aspx

speedbird:

?1) how do I stop the client waiting for the rest of the data so it goes to the new page?

2) Is it possible to tell the webservice on the server to quit working on the problem?

As far as I can tell, there isn't a good way to achieve your requirement.

Hello,

Q) how do I stop the client waiting for the rest of the data so it goes to the new page?
A) What you can do is use JavaScript or HTML anchor to redirect the client to a different page.

Sample: HTML Anchor: <a href=URL_Name target="_self">Click to go to different page</a>

JavaScript Function
function Redirect()
{
location.href='http://www.asp.net';
}

<asp:hyperlink id="hlRedirect" Text="Click Link to Go" onclick="Redirect(); return false;" style="cursor: hand;" runat="server" />

Sample URL:http://forums.advancemicrotech.com/threads/thread051507.aspx
Note: The Start Thread button is the same as your webservice doing its job. Once you click Start Thread button, the thread goes to sleep for 10 seconds, same as your webservice doing something on the server. During this time, you can either click the Redirect button that is created with HTML or the ASP Hyperlink ... as shown above ...


Q) Is it possible to tell the webservice on the server to quit working on the problem?
A) No you cannot tell the webservice to quit working while it's doing its job.

Hope these help ... Cheers.