Syntax error on asp.net. Need Help!

Joined
Jun 30, 2006
Messages
2
Reaction score
0
--------------------------------------------------------------------------------

hi all,
I have a problem on creating the multiple TextBoxs for inserting multiple row into oracle(10g) database.

Line 41: <% for (int i=0; i<InsertRow;i++) {%>
Line 42: <tr>

Line 43: <td><asp:TextBox ID='<% PortNo %>' runat="server"></asp:TextBox></td>


Line 44: <td><asp:TextBox ID='<% Model %>' runat="server"></asp:TextBox></td>
Line 45: </tr>



Parser Error Message: '<% PortNo %>' is not a valid identifier.

I guess it is a sytax error. can anyone help me. PLZ!
!
 
Joined
Jul 7, 2006
Messages
1
Reaction score
0
This is not a syntax error.

I'm not sure if you can set the ID of a control programmatically in the aspx. However you can create and add these controls dynamically from your code behind.
The thing you need to remember about dynamically added controls is
1) You have to add them on each postback, otherwise the controls will just disappear from the screen.
2) If you want them to persist their view state (which in most cases is true), then these controls must be added either in the Page_Init or Page_Load method. If you add them any later than this, then the controls will not maintain their viewstate.

You can refer to the following articles on the topic on adding controls dynamically:
http://aspnet.4guysfromrolla.com/articles/082102-1.aspx
http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

Even though the article says that you have to add the dynamic controls in the Page_Init and not the Load, I have done it in the Load event in the past and it has worked. I have read documentation somewhere to the effect that the controls are guaranteed to be fully loaded (including the View State) only by the end of the Load event. So I think the Load works fine too.

Its upto you to decide if you really need to set the IDs programmatically in the HTML. If the Ids are not so important, then don't bother adding the controls dynamically.
An alternate way to get access to the group of textboxes you are creating in the aspx would be to put only these textboxes inside a panel or a placeholder, and when needed you can access all the controls within the placeholder. You can use the clientID to figure out the sequence in which the textboxes were added. But this is not foolproof.
If the IDs are important, then dynamic controls is perhaps the best way to go.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top