ToddBeaulieu
asked on
How can I fill in ASP:TextBox.Text property dynamically as I generate table?
Hello,
I'm super new to ASP, and struggling with basic concepts. In the attached code snippet, you can see that I'm able to lay down table rows containing <INPUT> tags, dynamically filling in the Text property via the embedded code block. For instance, "<%= s.Name %>" evaluates to the Name property of the business object (for that row).
I wanted to use the AJAX CalendarExtender control, but it appears to support binding only to an ASP:TextBox control, as opposed to the generic <INPUT>. Ok, so I swapped out the <INPUT> for the <ASP:TextBox>. The problem is that it immediately balked at my previously-ok use of the embedded code block. I've been unable to discover an equivellent means of inserting the date value from the BO into the ASP:TextBox.
To be clear, please keep in mind that I'm laying down potentially hundreds of rows, each to receive it's corresponding date values.
A related topic: I noticed that only the first row gets the date picker. I assume I need to generate a unique (incrementing) ID for each ASP:TextBox, so that each new CalendarExtender will bind to its corresponding TextBox.
But, when I tried something like:
<% int nextId = 1; foreach (Site s in ViewData.Model.Sites)
{ %>
...
<asp:TextBox ID="Date<%=nextId%>"
I get:
Parser Error Message: 'Date<%=nextId%>' is not a valid identifier.
Obviously, I'm missing something pretty basic here. I don't understand why it's ok to evaluate code blocks in the <INPUT> construct, but not the <ASP:TextBox>.
I'm super new to ASP, and struggling with basic concepts. In the attached code snippet, you can see that I'm able to lay down table rows containing <INPUT> tags, dynamically filling in the Text property via the embedded code block. For instance, "<%= s.Name %>" evaluates to the Name property of the business object (for that row).
I wanted to use the AJAX CalendarExtender control, but it appears to support binding only to an ASP:TextBox control, as opposed to the generic <INPUT>. Ok, so I swapped out the <INPUT> for the <ASP:TextBox>. The problem is that it immediately balked at my previously-ok use of the embedded code block. I've been unable to discover an equivellent means of inserting the date value from the BO into the ASP:TextBox.
To be clear, please keep in mind that I'm laying down potentially hundreds of rows, each to receive it's corresponding date values.
A related topic: I noticed that only the first row gets the date picker. I assume I need to generate a unique (incrementing) ID for each ASP:TextBox, so that each new CalendarExtender will bind to its corresponding TextBox.
But, when I tried something like:
<% int nextId = 1; foreach (Site s in ViewData.Model.Sites)
{ %>
...
<asp:TextBox ID="Date<%=nextId%>"
I get:
Parser Error Message: 'Date<%=nextId%>' is not a valid identifier.
Obviously, I'm missing something pretty basic here. I don't understand why it's ok to evaluate code blocks in the <INPUT> construct, but not the <ASP:TextBox>.
<tbody>
<% foreach (Site s in ViewData.Model.Sites)
{ %>
<tr>
<% if (s.IsSelected) { %><td><input type="checkbox" name="selectedSites" checked="checked" value="<%= s.Id %>" /></td><% }
<td>
<%--<input id="Date2" class="shortdate" type="text" value="<%= s.EffectiveStartDate.ToShortDateString() %>" /> --%>
<asp:TextBox ID="Date2" runat="server" Text='<%= s.EffectiveStartDate.ToShortDateString() %>' >
</asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="Date2" CssClass="">
</cc1:CalendarExtender>
</td>
<td><input type="text" value="<%= s.EffectiveEndDate.ToShortDateString() %>" /> </td>
<td><%= s.Name %> </td>
</tr>
<% } %>
</tbody>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your solution could not have been more perfect. Thank you very much!
Change line 9.
Open in new window