how to get value of variable into textbox?

C

Cliff

Hi,

i would like to get the value of variable 'em', defined in code-behind, into
a textbox.
I tried two ways but withoit succes (no error).

The first textbox is empty, the second gets:<%=em %>

aspx file:
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# eval(em)
%>'></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" Text="<%=em
%>"></asp:TextBox>
</form>

code-behind:
Friend em As String
em = "ok"


Thanks
Cliff
 
G

Guest

Cliff,

Since your textboxes are not inside one of the data bound controls
(GridView, FormView, etc.), you'll need to call Page.BindData() explicitly
and cannot use the Eval()/Bind() functions.

Change your aspx to:
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Me.em %>'></asp:TextBox>

Then in your codebehind call Page.DataBind():
.....

Protected em As String = ""

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.em = "Data binded on " & DateTime.Now.ToLongTimeString()
Page.DataBind()
End Sub

see also:
http://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx

Hope this helps,
Jason Vermillion
 
C

Cliff

Yes, thanks ..

Jason Vermillion said:
Cliff,

Since your textboxes are not inside one of the data bound controls
(GridView, FormView, etc.), you'll need to call Page.BindData() explicitly
and cannot use the Eval()/Bind() functions.

Change your aspx to:
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Me.em
%>'></asp:TextBox>

Then in your codebehind call Page.DataBind():
....

Protected em As String = ""

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.em = "Data binded on " & DateTime.Now.ToLongTimeString()
Page.DataBind()
End Sub

see also:
http://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx

Hope this helps,
Jason Vermillion
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top