Add Rows to Table through Client-Side

Discussion in 'ASP .Net Web Controls' started by Tony, Apr 3, 2007.

  1. Tony

    Tony Guest

    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?
    --

    Tony
     
    Tony, Apr 3, 2007
    #1
    1. Advertising

  2. "Tony" <> wrote in message
    news:...
    >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
     
    John Saunders, Apr 3, 2007
    #2
    1. Advertising

  3. Tony

    Tony Guest

    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?
    --

    Tony


    "John Saunders" wrote:

    > "Tony" <> wrote in message
    > news:...
    > >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
    >
    >
    >
     
    Tony, Apr 3, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2lsZWVzaA==?=
    Replies:
    0
    Views:
    490
    =?Utf-8?B?U2lsZWVzaA==?=
    Nov 3, 2004
  2. Arjen Hoekstra
    Replies:
    0
    Views:
    588
    Arjen Hoekstra
    Aug 2, 2005
  3. Rio
    Replies:
    4
    Views:
    1,241
  4. Boss302
    Replies:
    0
    Views:
    1,098
    Boss302
    Nov 21, 2006
  5. Bogdan
    Replies:
    2
    Views:
    686
    Bogdan
    Jun 9, 2008
Loading...

Share This Page