Skip to main content
Known Participant
December 31, 2006
Question

JavaScript in ASP.NET

  • December 31, 2006
  • 3 replies
  • 363 views
hello
I have this simple javascript code:

<script language="JavaScript" type="text/javascript">
var Emp = new String(3);
Emp[0] = fname;
Emp[1] = mname;
Emp[2] = lname;
</script>

the question is : how to give values to fname, mname, lname from a database table using asp.net? ( table contains : Fname,MName,LName)
thx alot guys
This topic has been closed for replies.

3 replies

Inspiring
January 2, 2007
I would suggest that you use a literal field inside of the javascript and
then you can set the values of the literals as part of either the page load,
or the datagrid selection.

The JS code would look like this

<script language="JavaScript" type="text/javascript">
var Emp = new String(2);
Emp[0] = <asp:Literal id="fname" runat="server" />;
Emp[1] = <asp:Literal id="mname" runat="server" />;
Emp[2] = <asp:Literal id="lname" runat="server" />;
</script>

You would set the literal text value to whatever you were grabbing for
example

fname.Text = dgTop.Items(0).Cells(0).Text()



--
Paul Whitham
Certified Dreamweaver MX2004 Professional
Adobe Community Expert - Dreamweaver

Valleybiz Internet Design
www.valleybiz.net

"Feras_86" <webforumsuser@macromedia.com> wrote in message
news:en9q1k$roo$1@forums.macromedia.com...
>i wanted to get the first row from a datagrid and pass them to the java
> script code :
> <script language="JavaScript" type="text/javascript">
> var Emp = new String(2);
>
> News[0] = <%
> dgTop.Items(0).Cells(0).Text() %>; News[1]= <%
> dgTop.Items(0).Cells(1).Text() %>;
> </script>
>
> well i got the following error :
> Property access must assign to the property or use its value.
>
> any ideas?
> thx alot
>
>


Feras_86Author
Known Participant
January 1, 2007
i wanted to get the first row from a datagrid and pass them to the java script code :
<script language="JavaScript" type="text/javascript">
var Emp = new String(2);

News[0] = <% dgTop.Items(0).Cells(0).Text() %>; News[1]= <% dgTop.Items(0).Cells(1).Text() %>;
</script>

well i got the following error :
Property access must assign to the property or use its value.

any ideas?
thx alot
Inspiring
December 31, 2006
As usual, nothing is said about how or when the data is being retrieved from
the database. Sigh.
Let's say the data is available when the page loads. Thus, HTML controls of
type="hidden" can be populated with the data retrieved from the database
during the page compilation process. The data in the HTML controls can then
be referenced using the document object model in your JavaScript.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h


"Feras_86" <webforumsuser@macromedia.com> wrote in message
news:en828c$dm$1@forums.macromedia.com...
> hello
> I have this simple javascript code:
>
> <script language="JavaScript" type="text/javascript">
> var Emp = new String(3);
> Emp[0] = fname;
> Emp[1] = mname;
> Emp[2] = lname;
> </script>
>
> the question is : how to give values to fname, mname, lname from a
> database
> table using asp.net? ( table contains : Fname,MName,LName)
> thx alot guys
>