Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to? AutoGenerateSelectButton manually

307 views
Skip to first unread message

eric....@gmail.com

unread,
Mar 31, 2006, 3:13:27 PM3/31/06
to
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
appreciated.

Darren Kopp

unread,
Mar 31, 2006, 5:20:45 PM3/31/06
to
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.

HTH,
Darren Kopp
http://blog.secudocs.com/

eric....@gmail.com

unread,
Apr 3, 2006, 8:14:57 AM4/3/06
to
Ahh, thank you very much. I will try that and let you know how it goes.

eric....@gmail.com

unread,
Apr 3, 2006, 9:28:10 AM4/3/06
to
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++)
{
myGridView.Rows[i].Attributes.Add("onclick",
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.

0 new messages