2

I am dynamically creating dragrids in different rows of an existing datagrid in asp.NET

My generated datagrids have a column which is TemplateColumn (a CheckBox Column).

In my parent datagrid, I have a template column with checkboxes. when I check or uncheck the value of the check box, the check_change method is called (autopostback is set to true), the dynamically generated datagrids lose the checked checkboxes (the checkboxes are all unchecked again). However, if i check any of the checkboxes of the child (dynamically generated) grids and press F5, it refreshes the page but still I have my checked checkboxes.

What's happening ?? how is post-back different from refresh F5??? understanding this might help me fix my problem here :DataGrid not being altered!

1
  • are you testing the Page.IsPostBack property in your code-behind? Jul 22, 2010 at 12:37

3 Answers 3

2

It's simple, the browser caches the response. So if you press F5, you'd generally see your grid with the checked checkboxes each time. But if you do a post-back in code, you force the browser to connect to the server and post the data.

It will then wait for a response from the server, and return whatever the reason for the post-back was.

Annoying, but that's how browsers work. You can force a complete refresh than emulates a post-back by hitting Ctrl+F5.

This is (sometimes) browser dependent because not all browsers will act the same as you described here.

If a post-back is necessary but you still want to keep the checkbox status as checked, I'd recommend an AJAX call instead.

2
  • 5
    Ctrl+F5 does NOT emulate a post-back, it just overrides the browser's cache. Visiting the page for the first time or refreshing it uses an HTTP GET to retrieve the page; a post-back uses an HTTP POST to post data to the server. Ajax may not help here, you need to ensure that the dynamic controls are being persisted on every post-back. Jul 22, 2010 at 12:44
  • 1
    Apologies, my best English failed me :) I meant to say that CTRL+F5 will clear cache like post-back will force the browser to. I also agree that he needs to implement some kind of persistent state, however, it depends on the specific application and what will work for him. The only site I can recommend to learn AJAX is asp.net's site itself and a lot of Google searches :)
    – AcidRaZor
    Jul 22, 2010 at 13:00
1

A "Refresh" simply calls the last request made for a page. So, if you just browsed to a page then hit refresh, it simply asks for that page again.

A Postback is essentially an action on the page that sends information back to the server.

1
  • do you think I can still fire the CheckChanged event without a postback....this is my problem, can't alter the datagrid due to the postback and at the same time, can't fire checkChanged without the post back! Jul 22, 2010 at 12:24
0

Ideally it is a PostBack but it will depend on your Browser Settings if you have set it to Request page from Server for every visit or it picks from the Local Histroy Cache.

Hitting the Refresh button will make a new request to the page from the server , and it will not change the status of the Http Method(Get , Post) , I mean it will not change the IsPostBack status for the page.

However submitting the form(posting the form) will set the IsPostBack property to true and about page_load it will be called for both of the cases

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.