assign a varriable to text box

  • Thread starter Thread starter Ganesh
  • Start date Start date
G

Ganesh

Hi There,

I'm trying to use a variable value in the text box, i cannot find a way to
do this.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="c#">
string a12 ="89";
page.databind();
</script>



</head><body>
<form id="form1" runat="server">
<div><asp:TextBox ID="TextBox1" runat="server" text ="<%= a12 %>"
Style="z-index: 100; left: 120px; position: absolute;top:
104px"></asp:TextBox></div></form></body></html>

Thanks
 
Ganesh said:
Hi There,

I'm trying to use a variable value in the text box, i cannot find a way to
do this.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="c#">
string a12 ="89";
page.databind();
</script>

</head><body>
<form id="form1" runat="server">
<div><asp:TextBox ID="TextBox1" runat="server" text ="<%= a12 %>"
Style="z-index: 100; left: 120px; position: absolute;top:
104px"></asp:TextBox></div></form></body></html>

Thanks

You use the <%# tag for databinding, not the <%= tag. Also you need
runat="server" on your script tag, otherwise the script will not execute
on the server, but instead be sent to the browser, where it will be
ignored as the browser don't know C# code.

I would skip the databinding altogehter, though:

<script language="C#" runat="server">
TextBox1.Text = "89";
</script>

<asp:TextBox ID="TextBox1" runat="server"
Style="z-index:100;left:120px;position:absolute;top:104px"/>
 
Back
Top