GridView Postback adds IDs to TD and TR Elements

B

Bryan

Has anyone else noticed this?

I have a Gridview on a page. On the ititial load of the page, the
HTML is generated as I would expect. For example:


<table class="RenewalTable" cellspacing="0" border="0"
id="ctl00_ApartmentPlaceHolder_gridRenewal" style="border-
collapse:collapse;">
<caption>
Renewal information for a given date range
</caption><thead>
<tr>
<th scope="col">Apt</th><th scope="col">Name</th>
</tr>
</thead><tbody>
<tr>
<td class="apt">14D</td><td class="name">
<a href='Applicants.aspx?id=2602'>Jana C. Krumholtz</a>
</td>
</tr>



After a postback, however, all of the Table Row (TR) and Table Data
(TD) elements have IDs added to them. For example:


<table id="ctl00_ApartmentPlaceHolder_gridRenewal_ctl00"
class="RenewalTable" cellspacing="0" border="0"
id="ctl00_ApartmentPlaceHolder_gridRenewal" style="border-
collapse:collapse;">
<caption>
Renewal information for a given date range
</caption><thead>
<tr id="ctl00_ApartmentPlaceHolder_gridRenewal_ctl01">
<th id="ctl00_ApartmentPlaceHolder_gridRenewal_ctl01_ctl00"
scope="col">Apt</th><th
id="ctl00_ApartmentPlaceHolder_gridRenewal_ctl01_ctl01"
scope="col">Name</th>
</tr>
</thead><tbody>
<tr id="ctl00_ApartmentPlaceHolder_gridRenewal_ctl02">
<td id="ctl00_ApartmentPlaceHolder_gridRenewal_ctl02_ctl00"
class="apt">14D</td><td
id="ctl00_ApartmentPlaceHolder_gridRenewal_ctl02_ctl01" class="name">
<a href='Applicants.aspx?id=2602'>Jana C. Krumholtz</a>
</td>
</tr>


This is messing up the jQuery tablesorter. Any idea how I can stop
ASP.NET from adding in the ID's?

Thanks In Advance!

- Bryan
 
B

bruce barker

this is one of the disadvantages of webforms, the generated html is not
javascript friendly as there is little control of the ids or their
values. often there is extra spans, or the html may change based on user
agent.


if you want to use javascript, you should look at the mvc toolkit.

-- bruce (sqlwork.com)
 
B

Bryan

Hi Bruce,

Thanks for the reply. I will take a look at the MVC Toolkit.

That said, .NET should not be generating invalid HTML. After
tinkering a bit I see that it added a 2nd ID attribute to the TABLE
tag. Adding IDs to the TR and TD elements is bad enough, but a 2nd ID
on a TABLE element is just plain invalid.

FYI, for anyone who may find this in the future, the way I got around
the problem was to change my ASP.NET code. I added the
EnableViewState="False" attribute to the GridView, and rewrote the way
the code-behind worked to get rid of a GridView.DataBind() that was
occurring during the postback. That may not be possible for everyone,
but I was able to make it work in my case.

Once I did those two things, the IDs stopped being added to the HTML
output, and the jQuery code started working again.

Ah the frustrations of working on the web...

- Bryan
 
Joined
Apr 13, 2009
Messages
5
Reaction score
0
search button

hi all,
can anyone help me how to do for search button and text field. When the user write the input and click the search button, the output should show in other .aspx page in girdview format. What code should i put?


Thanks.
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top