Search code examples
methodsdynamic-datacode-behindedititemtemplate

How to set textbox value from code behind in EditItemTemplate


I have an Dynamic Data application with a custom edit page. In this page I have two field; a name and a unique identifier field. After this last field I placed a button. When I click the button I want a method to be executed that generated the unique identifier and place that value in the corresponding text field. I tried some thing with the onclick, eval, etc. but getting a lot of errors like not wellformed tags etc.

aspx looks like:

<EditItemTemplate>
    <asp:DynamicControl ID="dcIdentifier" DataField="Identifier" Mode="Edit" runat="server" />
    <asp:Button ID="btnGenerateIdentifier" runat="server" Text="Generate" OnClick='what to do here?');" />
</EditItemTemplate>

The code behind has a method that must do something like

public void Generate(){
   dcIdentifier.Text = GenerateId();
}

Hope someone can help.


Solution

  • Got it working by just using a custom field and handle the generation there. On my partial model class I specified that I wanted to use that custom field for the specific property and everythings turns out to work like I wanted.