How to? AutoGenerateSelectButton manually

Discussion in 'ASP .Net' started by, Mar 31, 2006.

  1. Guest

    A GridView control in ASP.NET has the option to Auto-Generate the
    select button (which is a link that calls __doPostBack which I presume
    does a post-back to the server). Is there information on how to
    generate this __doPostBack function manually?

    The motivation is simple. Using the same __doPostBack([tablename],
    'Select$[table row index]') function generated on the 'Select' button
    link from AutoGenerateSelectButton flag being set to true, I have made
    it so that whenever you click on a row in the GridView, it executes as
    if the select button was clicked. However, if I remove the
    AutoGenerateSelectButton property, the __doPostBack function is no
    longer defined. This is quite annoying because the 'Select' button is
    ugly and takes away from the ease of use.

    I haven't found much information on this, so any would be greatly
    , Mar 31, 2006
    1. Advertisements

  2. Darren Kopp

    Darren Kopp Guest

    well, what you are looking for is the GetPostBackEventReference()
    method. you can inject that into the javascript onclick event or
    whatever for the table row, i believe, but i have not done it myself.
    you will want to create the table yourself.

    hopefully this gives you the start that you need, if you need more
    help, shoot me an email.

    Darren Kopp
    Darren Kopp, Mar 31, 2006
    1. Advertisements

  3. Guest

    Ahh, thank you very much. I will try that and let you know how it goes.
    , Apr 3, 2006
  4. Guest

    Ok, after some playing around I got it. I'm going to post it here for
    all those that might come across this issue.

    Here's the progression that I imagine most people inexperienced at this
    (like me) will go through.

    In Page_Load:
    if (!IsPostBack){
    // Add __getPostBack to onclick handler for a gridview row
    for (int i=0; i < myGridView.Rows.Count; i++)
    ClientScript.GetPostBackEventReference(myGridView, "Select$"+i));

    But this still doesn't work. You must add to the @Page directive
    EnableEventValidation="false". This may raise some security issues to
    be dealt with later.

    Ok, so at this point, you can remove the AutoGenerateSelectButton
    attribute from the GridView and it will work. However, once the
    Postback is performed, __doPostBack is no longer registered. Simply
    move the loop out of the "if(!IsPostBack)" scope and it's all set.

    Thanks for the info, Darren Kopp.
    , Apr 3, 2006
    1. Advertisements

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. Replies:
  2. Adam Preble

    Manually specifying the shell

    Adam Preble, Mar 17, 2005, in forum: Perl
    Adam Preble
    Mar 17, 2005
  3. Nathan Baulch
    Nathan Baulch
    Jun 26, 2003
  4. Anthony Leuzzi

    Manually Posting to an ASP.NET page

    Anthony Leuzzi, Aug 14, 2003, in forum: ASP .Net
    Anthony Leuzzi
    Aug 14, 2003
  5. Mel

Share This Page