Passing values between tabs in AJAX tabcontainer in ASP.net - asp.net

I have a ASP.net page with couple of tabpanels. When a user hits submit button when he is on the First tab I am showing the user the second tab control. Ontabindexchanged I am dynamically creating a usercontrol and passing some values to the control.
Now when the user is in the 2nd tab and if he navigates to the first tab, I need to pass some values to the first tab.
At the tabcontainer level how do I pass values between tabs?

I think what your problem is, you need to maintain viewstate of your dynamically created controls, otherwise there is no problem to pass values between tabs. like..
tab1TextBox1.text=tab2Textbox2.text (Since your controls are in AJAX tab panel, no need to find control from tab panel)
For Maintaining viewstate of your dynamically created user control, you need to create your control in page_init() event.

Related

How to keep options in listbox after a postback?

I have (1) dropdown list, (2) listboxes, (1) button on a page.
The listboxes start out empty, but it is filled via jquery/ajax on the dropdown list change.
When i click the button it causes a postback and every time it does the contents (options) within the listboxes are removed.
Questions:
1) WHY does this happen?
2) HOW do i keep the contents of the listbox from being removed? No options in the listboxes are selected
The content/state of form controls are stored in view state that is created on server side by asp.net engine. The elements added on client wont be accessible on server side. You can put the content data in the hidden field in javascript and get the data back on server side from the hidden field and assign to control like listbox, dropdown etc. This is how asp.net also works.
This happends because since you add the values with AJAX, they are not added to the ViewState, which is what asp.net uses to persist the state of the form. Your best option is probably to use AJAX to avoid a postback or load the values on your page load event only if it's a postback.

How Does ASP.NET Knows Which Button Caused a PostBack?

I'm using ASP.NET 4 to create a page with elements that are used in a jQuery UI Sortable plugin.
All of these elements contain a button (implemented as a submit button) with the name SubmitButton. All but one of these buttons are hidden in the page's Load event. But if I drag the element to another position, and then submit the page using that button, ASP.NET gets confused.
ASP.NET thinks I've clicked a different button, one that wasn't even visible on the page, but is associated with content at the position where the clicked button was before the move. (If I don't move the element, it works fine.)
I can't seem to determine how this is happening. As I understand it, ASP.NET knows which submit button caused a postback because the button's name and value is included in the postback data. (__EVENTTARGET plays no role here and is empty.) So how can it think a different button submitted the page?
How could ASP.NET get confused about which button submitted the page?
(Sorry, it's not possible to put this page on a public website.)
I worked through this issue and here's what I found.
First of all, buttons by default are rendered as <input> tags with type = submit. The postback mechanism in this case has nothing to do with ASP.NET. The postback data includes, among other things, the name of the submit button that caused the postback along with the button's text (in the form name=text).
But ASP.NET button names, by default, include the names of all parent controls. When those controls are unnamed, they are given an ID like ctl00, ctl01, ctl02, etc. The result is that all my buttons are guaranteed to have a unique name.
The problem is when these buttons and parent controls are all created dynamically. On the postback, these controls are reconstructed in the load event but in the new order. Because the order affects the name (ctl01 vs ctl02), this means my submit button has a different name than it did when the page was originally rendered.
The result is that ASP.NET sees the wrong name associated with the submit button used to trigger the postback.

Why does drop down list in ListView in user control cause full page postback in page-level update panel?

I have the following scenario. I have a page that hosts several user controls. The user controls are all surrounded by a single update panel. All user controls have a save button on them. When the save buttons are clicked the page updates the update panel as expected.
Some of the user controls contain editable list views. Whenever an action is taken on these list views, the Update Panel is NOT refreshed, but the whole page posts back. How can I get these ListViews to also refresh the Update Panel? I cannot post the code because of NDA.
There are no javascript errors on the page reported by either IE8 or Chrome.
Check the autopostback property of the dropdownlist control, if the property is set to true it tries to postback every time the selection changes.
If this does not work for you, you may wish to try implementing manual update triggers in your controls code and setting the update panel to conditional, to firmly control when you want the panel to update.

asp.net ajax asyn. postback problem

There is a tab menu which was created by asp.net control. Now I'm changing this with a new tab menu I made with javascript. There is an event on third tab and when i click the tab it's posting back with asp.net ajax as asyn. but it takes me to the first tab after postingback every time but I don't want to change the tab after this. it must be stay on the third tab just must be changed content that's all. How do I solve it?
thank you
If your home-made tabset is in the update panel, then it will be part of the partial update. Your tab control needs to remember it's viewstate so that when it is rendered after a postback (or partial update) it will render with the right selected tab. I suggest using a hidden field on the page that holds the value or index of the selected tab. Then, when you go to render the tabset from a postback, you read from that hidden field and know what tab is selected and render as such.

Can't find dynamic controls in datagrid on postback

Using .NET 1.1, I have a DataGrid that contains three columns for each row.
Row one has a label with some text.
Row three will always have two radio buttons and two checkboxes and those are in the HTML side of the page.
Row two will have dynamically generated controls (just textboxes for now) and there can be 1 or more per row. These will be used for user input.
There is a button on the page and when the user clicks the button I need to update the DataGrid’s source (my DataTable) with the new values from the user’s input.
The issue is the DataGrid seems to be losing the dynamically generated controls on PostBack. I can loop through each Item in the DataGrid and I can access the radio buttons and the checkboxes, but the textboxes aren’t there.
Any ideas?
Remember: every time a postback occurs you are working with a new instance of your page class. Dynamic controls added to the page during a previous postback went to the garbage collector as soon as the page for that postback rendered to the browser, along with the rest of that page instance. You need to re-create your dynamic controls on every postback.
you have to regenerate the controls. You should be able to get their values from the http request object

Resources