0

Is it just me or is there are severe shortage of material on 2-way databinding?

anyhow, my problem is, I've created a UserControl to be placed inside a FormView.InsertItemTemplate.

My UserControl itself has a ITemplate field. Basically the idea is, in my form i have 5 controls that are common to all forms, and another section which can be customizable depending on the form.

My Markup looks like this:

<irt:FormView ID="FormViewInsertEvent" DefaultMode="Insert" runat="server"
    DataKeyNames="EVENT_ID" DataSourceID="DataSourceEvents">
    <InsertItemTemplate>
        <irt:EventControl ID="EventControlInsertEvent" runat="server" DataSourceID="DataSourceDataModemEvents"                
            EventDate='<%# Bind("EVENT_DATE") %>'
            EventTypes='<%# Bind("EVENT_TYPE") %>'>  
            <CustomContent>
                 Additional Property: 
                 <asp:TextBox ID="AdditionalTextBox" runat="server" Text='<%# Bind("ADDITIONAL_PROPERTY") %>'  />                            
            </CustomContent>
        </irt:EventControl>
    </InsertItemTemplate>
</irt:FormView>

I feel like theoretically everything is correct. But i get an ASP.NET runtime compilation error @line 4637:

Compiler Error Message: CS0128: A local variable named 'AdditionalTextBox' is already defined in this scope

Source Error:

Line 4635:            #line default
Line 4636:            #line hidden
Line 4637:            System.Web.UI.WebControls.TextBox AdditionalTextBox;
Line 4638:            
Line 4639:            #line 378 "C:\MyProj\trunk\Releases\Source\FilePathSensored.aspx"

The code at this line is this:

Line 4620:         [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 4621:         public System.Collections.Specialized.IOrderedDictionary @__ExtractValues__control84(System.Web.UI.Control @__container) {

...
Line 4628:             #line default
Line 4629:             #line hidden
Line 4630:             System.Web.UI.WebControls.TextBox AdditionalTextBox;
Line 4631:             
Line 4632:             #line 378 "C:\MyProj\trunk\Releases\Source\FilePathSensored.aspx"
Line 4633:             AdditionalTextBox = ((System.Web.UI.WebControls.TextBox)(@__container.FindControl("AdditionalTextBox")));
Line 4634:             
Line 4635:             #line default
Line 4636:             #line hidden
Line 4637:             System.Web.UI.WebControls.TextBox AdditionalTextBox;
Line 4638:             
Line 4639:             #line 378 "C:\MyProj\trunk\Releases\Source\FilePathSensored.aspx"
Line 4640:             AdditionalTextBox = ((System.Web.UI.WebControls.TextBox)(@__container.FindControl("AdditionalTextBox")));
Line 4641:             

As you can see, the code generated for my aspx has AdditionalTextBox declared twice

Does anyone know why this is? more importantly, how do i fix this or work around this?

Thanks in advance Nandun

Nandun
  • 1,802
  • 2
  • 20
  • 35

1 Answers1

0

If the ID of the text box is not mandatory for you and you are not using it in code-behind then you can safety remove it and asp.net will auto-generate it.

Marian Ban
  • 8,158
  • 1
  • 32
  • 45
  • True, but the problem is I have to use <%# Bind() %>. When you use 2 way binding, the ID is required. otherwise it leads to an error. – Nandun May 10 '12 at 09:18