質問

I'm putting together a web forms application that is utilizing the WebFormsMvp library. In the examples, it shows something like this in the ASPX markup:

Name:
<asp:TextBox runat="server" 
             ID="txtName" 
             Text="<%# Model.Name %>" 
             Visible="<%# Model.ShowName %>" />

This is allowed outside of a binding container (e.g. grid, repeater, etc.). It reminds me of MVVM style programming in WPF. What I'm missing is a value converter so I can setup how values should be converted. I suppose I could do this with extension methods for the types on the Model, but that doesn't seem like it has very good separation between the View and the code.

Ultimately I have two questions:

  • Does ASP.Net WebForms 4.5 support this type of behavior without extra libraries?
  • Is there any concept similar to a value converter in WebForms bindings?
役に立ちましたか?

解決

I might be thinking about this too much as the following seems to work great:

Name:
<asp:TextBox runat="server" 
         ID="txtName" 
         Text="<%# Model.Name %>" 
         Visible="<%# !String.IsNullOrEmpty(Model.Name) %>" />

This is almost as good as a value converter.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top