aspx file call codebehind function

R

Raymond Chiu

<asp:TextBox runat="server" Text='<%#
MyProject.Common.Utility.NumberFormatUtil.StrAmount(1111.11111)
%>'></asp:TextBox>

The textbox does not show the string and it is empty.

(1) I have tried to put the StrAmount function in the current aspx.cs and
make the debug break point. When run, it does not go to the function and
textbox still show empty. do you know why???

<asp:TextBox runat="server" Text='<%# StrAmount(1111.11111)
%>'></asp:TextBox>

(2) when i put <asp:TextBox runat="server" Text="11111"></asp:TextBox>, it
show 11111.

What happened???

How about the following of setting dataformatstring='<%# %>' ?? Can it
work if the above questions solved??

<asp:GridView ID="gridview1" runat="server"
AutoGenerateColumns="False" SkinID="ResultGridSkin"
Width="100%"
PageSize="100" onrowcommand="delete_Row">
<Columns>...................
<asp:BoundField DataField="Unit_Price"
DataformatString='<%# myproject.common.utility.getunitpriceformat()%>'
HeaderText="Unit Price" />
</Columns>
</asp:GridView>
 
G

Göran Andersson

Raymond said:
<asp:TextBox runat="server" Text='<%#
MyProject.Common.Utility.NumberFormatUtil.StrAmount(1111.11111)
%>'></asp:TextBox>

The textbox does not show the string and it is empty.

(1) I have tried to put the StrAmount function in the current aspx.cs and
make the debug break point. When run, it does not go to the function and
textbox still show empty. do you know why???

<asp:TextBox runat="server" Text='<%# StrAmount(1111.11111)
%>'></asp:TextBox>

(2) when i put <asp:TextBox runat="server" Text="11111"></asp:TextBox>, it
show 11111.

What happened???

You are using a data binding expression tag, but are you doing any
databinding that involves the textbox?

You can use a <%= %> tag to output an expression without databinding.

I prefer setting the properties from code behind. Set an id on the textbox:

<asp:TextBox runat="server" ID="TextAmount" />

Set the property from the Page_Load method:

TextAmount.Text =
MyProject.Common.Utility.NumberFormatUtil.StrAmount(1111.11111)
How about the following of setting dataformatstring='<%# %>' ?? Can it
work if the above questions solved??

<asp:GridView ID="gridview1" runat="server"
AutoGenerateColumns="False" SkinID="ResultGridSkin"
Width="100%"
PageSize="100" onrowcommand="delete_Row">
<Columns>...................
<asp:BoundField DataField="Unit_Price"
DataformatString='<%# myproject.common.utility.getunitpriceformat()%>'
HeaderText="Unit Price" />
</Columns>
</asp:GridView>

If you are doing databinding involving the grid view, that should work.
 
G

Gregory A. Beamer

<%= %> is the format to call a routine in code behind
<%# %> is the format for data binding. You will generally find this in a
GridView, etc.

But you can bind any control in code behind and avoid this kludge
altogether.

--
Gregory A. Beamer
MVP: MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think Outside the Box! |
********************************************
 
R

Raymond Chiu

<%= %> which seems no use at all as
textbox's text show full string of <%= %>.
It does not call the subroutine in code behind.
It is recognized as string output.
 
R

Raymond Chiu

Dear Andersson,

In your messages: "You can use a <%= %> tag to output an expression without
databinding".
Do you mean that it cannot be put the server-side function call or no action
taken if put sever-side function as I met this before?
I find that with databinding, <%# function1(eval("column1")) %> which works.

What do you think??
 
G

Göran Andersson

Raymond said:
Dear Andersson,

In your messages: "You can use a <%= %> tag to output an expression without
databinding".
Do you mean that it cannot be put the server-side function call or no action
taken if put sever-side function as I met this before?
I find that with databinding, <%# function1(eval("column1")) %> which works.

What do you think??

In a response write tag you can use any member of your page class that
is public or protected.
 
I

Ignacio Machin ( .NET/ C# MVP )

<asp:TextBox runat="server" Text='<%#
MyProject.Common.Utility.NumberFormatUtil.StrAmount(1111.11111)
%>'></asp:TextBox>

 The textbox does not show the string and it is empty.

Hi,

I think you should get a book of asp.net or at least read some
articles about the differences between classic ASP and asp.net
 

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