Visible Property of ASP.Net Control not working - asp.net

I have a radiobutton list and three placeholders in my page, out of which the radiobutton list,first and third placeholder are within updatepanel, second placeholder is not within updatepanel.
When radiobutton list selectionindex is changed, I want all three placeholders invisible. Placeholder2.visible=false code executes but still Placeholder2 is visible.
How to resolve this.
Thanks,
Viknesh.A

You should put all your placeholders in update panel on reload the page when the radio button hits (full post back) by setting AutoPostBack="true"
You should understand that by default changin radio button on a client only affects client html, so you need to pass that info to server.
Another option is to have client onclick for radiobutton and write your custom javascript function to hide your second placeholder, but don't forget to manage that situation on the server as well, when postback (either ajax or not) will occur.

Move Placeholder2 inside the UpdatePanel.
Or don't use an UpdatePanel at all.
Or use JavaScript to hide it, instead of server-side code.

Related

Page does not render after SelectedIndexChanged event of dropdownlist in UpdatePanel

I have one dropdownlist (with static listitems). On SelectedIndexChanged event of this dropdownlist, I have three cases to check:
1) If the value is 'A', I need to bind another dropdownlist.
2) If value is 'B', I need to hide above another dropdownlist and instead show nothing in place of that i.e. ulitmately hide that particular div.
3) If values is 'C', I need to hide above div and in place of that, show a textbox.
Now, to prevent Page postback each time a value in dropdownlist is changed, I am using UpdatePanel control here.
I have tried using single updatepanel for both these dropdownlists, two separate udpatePanels for each of them.
With two separate updatePanels, I could succeed in calling the "SelectedIndexChanged" event of that dropdownlist, but once the event is called, the changes done in that code are not reflecting on the page.
i.e. if I hide a div when selected value is 'B', it still shows me, or in either case if it is 'A' and I bind another dropdown, it does not even render.
And, if I reload that page, the pervious changes get reflected. Can anybody please tell me what could be wrong here?
Also, please note that I want be able to postback the page programmatically, because that is the I am trying to prevent.
Also, I would like to notify here that I am using all these things in a WizrdStep of an asp.net wizard control.
Would be greatful for any help.
Thank you in advance.
The issue was not because of update panel or dropdownlist.
The problem was with the way my page was being rendered.
I have used url rewriting for my application and I was trying render this page using my customized form tag instead of built-in Html form tag.
That is why updatepanel was not working normally.
I have got it working now using normal Html Form tag and meanwhile I am trying to workout to handle this updatepanel tag as well with my customized form tag.
If I get it solved, I will submit the solution.
Thanks.

AJAX Add a dynamic form and AJAX Post data

This is what I'm trying to do with AJAX:
[DropDownList]
I have a DropDownList (not inside an UpdatePanel), populated by different Products to "Add" to the database.
[UpdatePanel #1]
Below, I have an Conditional UpdatePanel that listens for "SelectedIndexChanged" on the DropDownList, when that event is triggered it adds TextBoxes to a div "productForm" inside the UpdatePanel. It creates the Form according to the Product to add.
[Button]
Below the UpdatePanel I have a button that "should" submit the form above.
[UpdatePanel #2]
I have an update panel that listens for the event on Button "Click" event. I also have a div in the ContentTemplate that should post out data that was submitted from the "Add Product Form" in the first UpdatePanel.
The thing is, when I submit (and the Controls are still visible in the first UpdatePanel. It can't read the data from the TextBoxes becaus they aren't there. Also, if I try to add all this to the same UpdatePanel, the Controls disappear whenever I click the Submit button.
Any ideas how to make something similar work?
Without the code I can suspect that when you dynamically populate first div on dropdown selected index changed event, since its within update panel, viewstate is never made aware of new controls and on submit can't post them back to server.
I've had some bad experiences with update panel and never use it other than very simple scenarios. Try getting familiar with jQuery ajax. I would do what you want to do using jQuery and web methods.

In server side, how to determine ModalPopupExtender is currently hidden?

I have a page like that and the control structure is like that.
UpdatePanel
Button
ModalPopupExtender
ModalPopup Content Container
Initially, ModalPopup Content Container is an empty control.
After user clicks on the Button, a async postback will be triggered. During the postback, the server generates the content and appends to ModalPopup Content Container. Also sets the properties of ModalPopupExtender. Finally, calls ModalPopupExtender.Show() method and UpdatePanel.Update() method to show the modal popup.
This method works fine if all controls in ModalPopup Content Container contains simple control. If a control is a button that needs to postback to server side, that is a problem.
Since the controls in ModalPopup Content Container is dynamically created. If a control in ModalPopup Content Container triggers a postback event, the control must be created before RaisePostBackEvent is called in server side.
My idea is to determine whether the ModalPopupExtender is hidden or shown in client side in order to re-generate the dynamic control in ModalPopup Content Container.
So my question is how to determine a ModalPopupExtender is hidden or shown.
Of coz, if you think my method does not work at all, please give me some suggestions. Thanks!
One way is using a boolean property in ViewState to keep track of the popup condition i.e. before or after you call .Show method set it to true. Then upon closing dialog you set it to false.
You can use HiddenField as well if you want to do something on client-side.

Passing data to server code from a client-side control using ASP.NET AJAX

I have a ListView on a page that displays a list of widgets. When a user clicks on one of the items in the list, I want to display a ModalPopup that contains controls allowing the user to operate on the item they selected.
I could easily accomplish this by placing a Panel and a ModalPopupExtender in the ListView's ItemTemplate, but this mean one set of hidden controls for each and every widget, which would massively bloat the page size. (There are going to be some rather heavyweight controls in there.) Instead I want to reuse a single ModalPopup for each of the widgets in the list.
I've done some searching but I haven't found anything that applies directly to my situation before. From what I've been able to figure out, however, I have to do something like this:
Place a Panel and a ModalPopupExtender on the page inside an UpdatePanel.
Build a custom WidgetManipulator user control that has a WidgetID property. Put this in the Panel, along with a couple OK/Cancel buttons.
In Javascript on the page, attach a click handler to each widget in the ListView that triggers a postback on the UpdatePanel.
On the UpdatePanel_Load event on the server, display the ModalPopup and then set the WidgetID propety on the WidgetManipulator to the ID of the clicked widget.
On the OKButton_Click event or CancelButton_Click event on the server, hide the ModalPopup. If OKButton was clicked, call WidgetManipulator.SaveChanges() first.
The part I haven't figured out is: How the heck do I know what widget was clicked on, and how do I pass that back to the server when I refresh the UpdatePanel? Is this even the right approach at all?
If you can use jQuery instead you could do something along the lines of these two posts:
Modal Delete Confirmation Version
Two Using jQuery SimpleModal Plugin
Demo
Inserting Content Using
jQuery SimpleModal Plugin Demo
When I need to pass data from client to server in ASP.NET AJAX, I generally use an asp:HiddenField with runat="server". Both can see it freely, but beware potential postback asynchronicity.
Sounds like you need to notify the server the widget was clicked - You may use a Timer to postback; or I'd go with option 5.

Why does a button control need to be clicked twice?

I've got a web application working using VB and Ajax. I'm using updatepanels to avoid the irritating "flicker" on postbacks to the server.
I would like to have a button control defined within the updatepanel itself (tried moving it outside and got some catastrophic error, so left it there) that makes the current panel not visible and a sibling panel visible. This works with the exception that the button must be clicked twice. Not double clicked, but clicked once than clicked again.
In setting breakpoints I discovered the code behind that's attached to the button is actually being executed on the first click, but the panels don't switch as expected. If I click the same button OR worse yet, a different button, the expected behavior of the second panel appearing occurs. However, with the second button being clicked there's an unwanted bonus of a third panel being displayed, the third panel being made visible due to the second button being clicked.
I'm assuming this behavior is due to the updatepanel and its Ajax nature. Is there a way to avoid the second click? Am I misusing the updatepanel? I really wanted to use a modal popup (right out of the AjaxToolKit) but had problems with posting back the data so I opted for this approach. Any insights, assistance, even criticism would be welcome as this has plagued me long enough. Thanks
If you get rid of the UpdatePanels do things work as expected with PostBacks? Chances are something in your Page_Load or other event higher up the chain are "resetting" things in some way before it gets to your click event. Could this be the case?
I think your problem is that only the update panel is receiving data from the server after the method executes. The panel your are trying to change is outside of the update panel so it does not know that its properties have changed.
You either need to do a full page postback or have the panel you wish to modify inside the update panel.
I have run into this before and resolved it, I just can't remember how. I will try to find my old code and get back to you. one thought, do you have EnablePartialRendering enabled in your scriptmanager? maybe try wrapping both containers in a third panel.
Your update panel is sitting inside the other panels.
Should that be the other way around? AFAIK only controls within the update panel will get updated in via the AJAX call.
Here's a fairly simple solution. (I was having the same problem this morning.)
The UpdatePanel can't render stuff outside itself. So, as you noticed, the updates are happening, but you're not seeing the result.
The easiest solution is to force a full postback. You can do that like this:
protected override void OnInit(EventArgs e)
{
var scriptManager = ScriptManager.GetCurrent(this);
// or this.Page in a UserControl, etc.
scriptManager.RegisterPostBackControl(someButton);
scriptManager.RegisterPostBackControl(someOtherButton);
// etc. for each control that needs to update something outside the UpdatePanel
}
This still allows the buttons themselves to be updated in the UpdatePanel by Ajax (e.g. changing their state to disabled or enabled). The full postback only happens if the buttons are clicked.
Like others have said an update panel only updates its contents, thats one of the main benefits of using it.
Panel2 and pnlPrvCmt need to be inside your update panel for your button click method to work. Another option would be to put Panel2 inside one update panel and pnlPrvCmt inside a second update panel. Then any control inside either update panel will cause both to refresh, as long as the UpdateMode=Always (which it is by default).
Try giving the dynamic control an ID when it is created. For some reason this is required by .net for a dynamic control to work in this context.
myControl.id="newID"
I have found this to occur under 2 different scenerios:
No ID set on the control. Either the ID is left off of the markup or the the ID was not set when a dynamic control was created. ASP.Net uses the ID to track actions.
Nested UpdatePanels. Scenerio: When using a Masterpage, you might have a content placeholder that you wrap in an UpdatePanel so that an UpdatePanel is not needed in the content on the page. Then, in developing your page you might, as a habit, add an UpdatePanel.

Resources