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

  • Thread starter Thread starter Ivan S
  • Start date Start date
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. :)
 
<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
 
<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
 
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>
 
Back
Top