Retriving data from some asp.net object to client side javascript

I

Ivan S

Hello. :)
I'm relatively new in web programing...

Anyway...

How can I, for example, retrive data from Profile object (or what so
ever) to some variable declared in javascript tag on client side?

For example, let's say I have this code in Some_Page.aspx:

....
Profile.Name = "Some Name";
....

And I have some variable in java script tag:

var someVariable;

How can I get this "Some Name" from Profile.Name to someVariable?

Tnx. :)
 
M

Muhammad Naveed Yaseen

<script>
var someVariable = <asp:Literal runat="server" id="ltlAux"
EnableViewState="false" Text='<%# Profile.Name %>' />;
</script>

And then in code behind you may call ltlAux.DataBind() if it is not
already being called by some parent in hierarchy.

If dynamic databinding is not appropriate for your app, you may
explicity assign as ltlAux.Text = Profile.Name in code-behind
 
M

Muhammad Naveed Yaseen

<script>
var someVariable = "<asp:Literal runat="server" id="ltlAux"
EnableViewState="false" Text='<%# Profile.Name %>' />";
</script>

And then in code behind you may call ltlAux.DataBind() if it is not
already being called by some parent in hierarchy.

If dynamic databinding is not appropriate for your app, you may
explicity assign as ltlAux.Text = Profile.Name in code-behind
 
G

Guest

Hello. :)
I'm relatively new in web programing...

Anyway...

How can I, for example, retrive data from Profile object (or what so
ever) to some variable declared in javascript tag on client side?

For example, let's say I have this code in Some_Page.aspx:

...
Profile.Name = "Some Name";
...

And I have some variable in java script tag:

var someVariable;

How can I get this "Some Name" from Profile.Name to someVariable?

Tnx. :)

You can assign the Profile.Name to a public variable, say

public string profileName;
.....

profileName = Profile.Name;

and use it as

<script>
var someVariable = '<%=profileName%>';
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top