On a page_load() ,
Is there a way of capturing that a paging value has been changed? (e.g.from page 1 to page 2)
This relates to a Gridview control
John - why are you looking for this in the page_load? You may be better off handling the PageIndexChanged or PageIndexChanging events on the gridview instead.
In the event that you need to know the control that caused the postback during the page_load - look at this post for a solution. In that solution, they suggest that you query the Request["__EVENTTARGET"] variable. Another similar solution is here.
Related
I am trying to take advantage of the page lifecycle in Asp.NET so that I don't bind to my datasources more than I actually need to.
This has led to the following problem. I have an ObjectDataSource, GridView, and a button on my page. The button adds a record to the database, which should be picked up by the data source and presented on the Grid. The problem is that the item is not showing up on the gridview until I refresh the page.
I can solve the problem by calling GridView.DataBind() in my button's event handler, but this goes against what I understand about the .NET Page Lifecycle.
Based on this article, the lifecycle should be as follows:
In addition the article states that the Databinding event is "Raised after the control's PreRender event, which occurs after the page's PreRender event."
So, my button click event should fire first, during the Event Handling phase. It should add the record the database.
Next PreRender should be called on the controls.
Finally DataBind should be called on the controls, and the Grid should update to capture the new record.
Yet this doesn't seem to happen. What am I not understanding?
I think the issue is that your viewstate is not enabled on your GridView. This is what I experienced, but then I also had to call DataBind() on the GridView from the page PreRender event if the request was a postback to get the data updated in the GridView on postback.
Edit:
It would help to understand the issue and context better if you could post the source code of your page (aspx + codebehind). How and where do you connect your GridView to your datasource? Statically in markup or dynamically? Do you make any calls to page.DataBind()? ... These things may influence the behaviour of the GridView.
I have a TextBox inside an UpdatePanel which is inside of a GridView. The purpose of the UpdatePanel is to update the TextBox when the TextChanged event is called (like in a previous question of mine).
This i got working after I read into the topic. But the problem I am stuck with now is that I have to add new data to the GridView at PostBack and the following new rows don't fire the TextChanged event. Only the first row in the GridView does.
Therefore I thought of setting the EventHandler for the TextChanged event in the RowCreated event so the Handler is set before the new rows are created but I still seem to miss something here. Any clues will be gladly taken :)
PS: If you want to see some of my code I have to refer for now to the code from the previous question as I am currently at home. I can post it as soon as I get back to work tomorrow.
Stupid me strikes again!
In codebehind the AsyncPostback never got to the part where the gridview built the new rows at postback. Therefore the TextChanged Event only occured for the first row since it is the only row which is also built when no postback is occuring.
The tricky part here is to find out in AsyncPostback if the last time Page_Load was called through PostBack or not. I think I solved it through a very dirty way: on PostBack I wrote in Page_Load to a hiddenField a certain value. Afterwards I checked if the value is still in the hiddenField. If so, then I knew that in the AsyncPostback I have to go the route of the PostBack and if not then not.
If somebody comes up with a better way to achieve this you are welcome to enlighten me :)
I have a aspxgridview with details row.
in detils row of this gridview, there are about 10 aspxgridviews. whenever one of this grids cause callback by clicking edit/new/delete , other gridview also databound i.e hit database. this cause performance issue.
Is there a way to disable databinding on other aspxgridview?
tanks.
You can use tab content lazy loading. Look here for example and here for further explanation.
i find a solution here:
ASPxPageControl - Page Load of all TabPages
How can I make a dropdownlist with no postback - I have a dropdownlist which has code in selectedindexchanged
Basically for every indexchanged the code will connect to sql and get values then populate textboxes with values.
Here is my code
<asp:DropDownList ID="ddlSalesOrg" runat="server" Style="width: 200px;"
AutoPostBack="true" />
I want that the selectedindexchange should get hit, but it should NOT cause a full postback. If I set the AutoPostBack to false, then it won't hit selectedindexchange at all
You must choose - do you want postback or not. You can't set AutoPostBack="true" and after that stop the post backs.
If you just don't need full postback - use UpdatePanel for partial page update.
I dont get you question, do you want avoid the postback and also have the funcionality of vb/C# on every indexchanged?
Then your solution were AJAX all this time.
At this time I supose you have more knowledge about this.
But only for the register.
When you write something in the codebehing of ASP in response to an event, there you MUST be a postback (or partial postback) to achieve that code.
If you stop the postback abiously (as you said) these code is not achieved.
If you want to avoid the postback and also get some databind functionality (or any server side functionality) then you can disable the postback, handle the event in javascript, and call some AJAX function to make the databind.
key words for your next google search: ajax, dropdownlist,asp
Good luck to the next guy who has this problem.
You need to set the AutoPostBack property of the list to true.
Also, if you're populating the contents of the drop down list from the code behind (getting the contents of the list from a database, for example) - make sure you're not re-binding the data in every postback.
Sometimes people are caught out by binding the drop-down in the page load event without putting it in an If Not IsPostBack. This will cause the event not to fire.
The same is also true of repeaters and ItemCommand events.
Hi I have a Repeater and I am doing various things during the ItemDataBound event. My Repeater is in a control. What I am noticing is that the things that are supposed to happen in the ItemDataBound event happen after the Page_Load of the page hosting the control. Is there a way to use some sort of ItemDataBoundComplete trigger so I can do other things on my page after the events of the ItemDataBound have taken place? Thanks, please let me know if I have not been clear.
[Edit] I have controls that are being bound to the ItemDataBound and they are not available until after the Page_Load for the page hosting the control.
[Solution] (In my case):
In my page I used the following:
Control.Page.LoadComplete += new EventHandler(Control_LoadComplete);
Then I performed what I had to do in that event.
What kind of things? You can override the OnPreRenderComplete method, which is called immediately before the page renders.
You can also change to a ListView, which is support as much flexibility in the html, and use the DataBound event (which is called after the whole ListView has finished data binding).