The ListView LayoutCreated Event Is Not Fired After Handling ItemCommand - asp.net

I am trying to update controls in the of a ListView control after handling the ItemCommand event.
My ListView displays line items of a purchase order in the as html table rows along with a TextBox to enter a new quantity and a Button to update the quantity. My ListView then displays sub-totals, discounts, and a grand total of the line items above in the as html table rows as well. On initial load, I set the values of the controls in the ListView's in the LayoutCreated event handler.
When a new quantity is entered and the button to update is clicked, I handled the event in the ItemCommand event handler. I update the quantity of the specific line item. I then re-bind my ListView to the underlying collection and call DataBind(). The problem is, LayoutCreated is not fired this time around, only on initial load.
My work around is to just pull those controls out of the and address them as static controls, but I like having them inside because my table markup can be fully contained in the and my can show cleanly without having to juggle the static controls' display properties.
Is what I am asking possible? Thank you for any help you can provide.

I'd reccomend handling the DataBound event of the ListView (instead of the LayoutCreated event), and setting the values there. That will get called everytime you re-bind the ListView, as well as when it loads for the first time, which (from your description) is what you want to do.

Related

Master Page and Child Page Events

I have a Master Page which contains a Dropdown, based on the Drop down selection I change the language of the entire site. Now, in one of the child pages I am using a repeater and binding some data to it. I am also using the ItemDataBound event of the repeater as well (I require a tooltip for one of the cells). I am trying to figure out a way when the master page Dropdown value is changed I should also fire the ItemDataBound event so that the data is displayed in the correct language. I am guessing it has to do something with playing around certain events. Any ideas or feedback will be appreciated.
ItemDataBound is only fired when data is bound to the control. You would have to rebind the data to the repeater in order for its ItemDataBound events to fire again.
Your other option is to write additional code to loop through all of the items in your repeater and perform the actions you usually perform in ItemDataBound.

Can I fire button click event without firing pageload event?

I have a button on my page and and few textboxes which alters their context on page_load event. when I open the page for the first time it loads random data from a database to textboxes with a function in pageload and also I create those textboxes dynamically. what I want is to make some changes on textboxes texts and click the button than send new context of textboxes to database. But when I click on button, PageLoad event fires again and It regenerates the textboxes and the context of them alter naturally since they are newly created textboxes. I tried to use "if(!Page.isPostBack)" in pageload but then the textboxes and related objects are not being created and they become null.
how can I overcome this problem?
best thing I can think of is to find some way to fire buttons click event without firing PageLoad event, but I dont know how can I do it.
any help would be appreciated;)
From Comments
Can you regenerate the Textbox on each Page load Execution? and data assignment to these Textbox should be under !Page.IsPostback. All you have to do is to keep the IDs of the Textbox in ViewState only first time page load and next regeneration of Textbox will have the previous stored ID and you also have to store the ID corresponding data in ViewState. Makes sense?

How to create custom pager's dynamic LinkButtons properly?

I'm creating a simple custom pager for repeater (or anything else, it doesn't actually matter because all I want from it is current page number). Pager has 3 public properties: PageSize, MaxResults and PageIndex.
First is set in markup, second is set on the page in Page_Load or EventHandlers when various buttons are clicked and repeater is databinding again. Third is decided by user when clicking on page numbers.
Page numbers are dynamically created LinkButtons with OnCommand set to method that launches my pager's OnPageChanged event to inform webpage that it need to reload data.
The problem is that in order to create correct number of page linkbuttons I need to know MaxResults. I will know it not sooner than in Page_Load and most probably even later. But as far as I know if I want my linkbuttons to fire events they need to be created before Page_Load when I don't know MaxResults...
Now I'm creating linkbuttons in Page_PreRender and event's don't launch. What is the solution for this? It looks like GridView's built in pager is also done with LinkButtons and it also can't know count of data before databinding but the events are firing.

Get value of certain Page control in an asp:Repeater

On my asp.net page, I have several DropDownLists.
I also have a Repeater.
In the ItemDataBound event I want to get the value of these DropDownLists, to change the data in the Repeater. The SelectedValue of these DropDownLists is empty.
But after the ItemDataBound, the Page_Load is executed. There I can get the value of these DropDownLists.
Is there a solution to get the value when the ItemDataBound is executed.
thanks!
Filip
You need to data-bind these drop-down lists in the Page.Load event.
There're a lot of web controls that get their state or other details during load life-cycle (I had these kind of problems long time ago).
NOTE: When I say "State" I'm not talking about ViewState.
And why don't you do that data-bind after the load event?
Can you get the drop down lists' selected values in the page PreInit event? If so, store them in view state and retrieve them from view state during the repeater's item data bound event.
If that doesn't work, try adding a selected index changed event to each drop down. When the drop downs change, set a view state variable that you can retrieve during the repeater's item data bound event. If you have values to which you are setting the drop downs during page load, such as when reading from a database, use those values to directly set the appropriate view state variables.

Trigger UpdatePanel on mouse over (as tooltip)

I need to display additional information, like a tooltip, but it's a lot of info (about 500 - 600 characters) on the items in a RadioButtonList.
I now trigger the update on a PanelUpdate when the user selects an item in the RadioButtonList, using OnSelectedIndexChanged and AutoPostBack. What I would like to do, is trigger this on onMouseHover (ie. the user holds the mouse a second or two over the item) rather than mouse click but I cannot find a way to do this.
You could try setting an AsyncPostBackTrigger on the updatePanel to watch the value of a hidden field. Then in the javascript onMouseHover event, increment the hidden value. This would fire the AsyncPostBackTrigger, updating the UpdatePanel.

Resources