function call from textbox

J

Jack

Why won't this work?

in the .aspx file:

<asp:TextBox id="name1" runat="server" Text='<%#
GetValue(1)%>'></asp:TextBox>

in the codebehind file:


public string GetValue( int index )
{
return "dog";
}


So, the text "dog" should appear in the textbox...but it doesn't. It
is just blank. I obviously simplified this code in the process of
debugging; it appears the function isn't getting called for some
reason.

Thanks,

Jack
 
C

Chris R. Timmons

(e-mail address removed) (Jack) wrote in
Why won't this work?

in the .aspx file:

<asp:TextBox id="name1" runat="server" Text='<%#
GetValue(1)%>'></asp:TextBox>

in the codebehind file:


public string GetValue( int index )
{
return "dog";
}


So, the text "dog" should appear in the textbox...but it
doesn't. It is just blank. I obviously simplified this code in
the process of debugging; it appears the function isn't getting
called for some reason.

Jack

Use <%= instead of <%#. <%# is used in data binding. See the
DataBinder.Eval documentation for more info.

Hope this helps.

Chris.
 
J

Jack

Use <%= instead of <%#. <%# is used in data binding. See the
DataBinder.Eval documentation for more info.

That just prints <%=GetCookieValue(1)%> itself in the text box -- so
it seems it is treating the functional call as a text string, which
baffles me. Seems like it must be a configuration issue. Any ideas?

Thanks,

Jack
 
J

Jack

The answer: I needed to call

this.Databind() in Page_Load. Also, my original syntax <%# was
correct.

Jack
 

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

Top