Add Rows to Table through Client-Side

T

Tony

I have a page with a Table control and 1 row. When the page loads, 5 rows are
added with their respective controls. There is a LinkButton that, when
clicked, will add 5 more rows to the Table. Whenever this button is clicked,
5 more rows are added. Except that because it is posting back, it does not
work correctly.

Is there a way I can add client-side script that would add the rows to the
table and be able to access a SQL server and .NET namespaces without posting
back? I know AJAX can accomplish this, but I am not familiar with how it is
implemented in ASP.NET. Does someone have an example of what I am trying to
do? Or an example of this implementation AJAX that is not too confusing?
 
J

John Saunders

Tony said:
I have a page with a Table control and 1 row. When the page loads, 5 rows
are
added with their respective controls. There is a LinkButton that, when
clicked, will add 5 more rows to the Table. Whenever this button is
clicked,
5 more rows are added. Except that because it is posting back, it does not
work correctly.

Is there a way I can add client-side script that would add the rows to the
table and be able to access a SQL server and .NET namespaces without
posting
back? I know AJAX can accomplish this, but I am not familiar with how it
is
implemented in ASP.NET. Does someone have an example of what I am trying
to
do? Or an example of this implementation AJAX that is not too confusing?


If I understand you correctly, you want to add rows on the client side, and
have them persist after a postback.

The issue here is that the client can't create server-side controls. Only
the server can do that. So you need to cause the client (in addition to
adding the rows on the client side) to send the server enough information so
that the server can recreate the rows on the server side.

You could do this by having the client store information about the rows in
hidden fields. The server, during a postback, could look at those hidden
fields to determine things like how many rows to add, and what to put into
those rows. These new table rows would be sent back to the client.

John
 
T

Tony

Thanks for the tip John. The only question I have is how to get the client to
store the info in the hidden cells. I can't seem to figure out how to execute
client-side script from a server-side control.

However, my original intention was to execute a client-side script when the
user clicks the 'Add More Rows...' LinkButton. That way, the client is
creating the controls and there is no Post Back. How can I do that?
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top