PDA

View Full Version : [CLOSED] Pass parameters from codebehind to client side (javascript)



supera
Sep 05, 2012, 9:09 PM

Aurelio
Sep 06, 2012, 2:45 AM
Hi.Supera

If you want you can use the session variable...

In the Page_Load..define a session variable..


protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Session["Name"] = "pisolo";
}
}


and client-side
read the value:



<script type="text/javascript" >




Ext.onReady(function () {

alert('<%= Session["Name"].ToString() %>');

});
</script>


Thanks
Aurelio

Daniil
Sep 06, 2012, 7:51 AM
Hi all,

Yes, @Aurelio is right, you can use "<%= %>" to achieve your requirement. The same is possible with a Hidden.

Example

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

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Session["param1"] = "param1";
this.Hidden1.Text = "param2";
}
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script type="text/javascript" >
Ext.onReady(function () {
alert('<%= Session["param1"].ToString() %>');
alert('<%= Hidden1.Text %>');
});
</script>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:Hidden ID="Hidden1" runat="server" />
</body>
</html>


Also you can always render any JavaScript from server with a required data.

supera
Sep 06, 2012, 12:38 PM

Daniil
Sep 06, 2012, 1:29 PM
What is the impact in renderer javascript in server?

Well, it just can be helpful in some scenarios.



It is advisable to do this in all my project?


Only if it is required and suites your needs.



I have very large javascript files and I do use of webservices call in all project... Some increase in performance?


Well, if you don't need to render dynamically generated JavaScript, you should not do that. The inline scripts or referring them via

<script src="url">
gives the best performance.

Generally, I just said about another approach which can be also used to achieve your requirement.

If you would describe what exactly you are trying to achieve, then, probably, we could suggest something more.

supera
Sep 06, 2012, 1:41 PM
My goal is performance.

I wish provide to my user the best experience in use our application.

If you know any article with tips to achieve this goal, I would be very grateful for it.

Thanks.

Daniil
Sep 06, 2012, 2:39 PM
Please open
http://forums.ext.net/search.php

Type "optimizing an application" in the "Tag" field and click the "Search Now" button.

It will search for threads related to optimization.

supera
Sep 06, 2012, 2:47 PM
Ok!

Thanks Daniil!

I will do this.