Gridview inside a ModalPopUpExtender causes ModalPopUpExtender to close - c#

I have a gridview inside a ModalPopUpExtender, the grid view have the button add delete and edit when i clic one of the button of the gridview the popup is closed. I wont to close the popup when the close button is clicked.
This is the asp.net part:
< cc1: ModalPopupExtender ID="NamePopup" runat="server" PopupControlID="OptionPanel" TargetControlID="btnD" BackgroundCssClass="mpBg" DropShadow="true" OkControlID="btnSavePopup" CancelControlID="btnPostCancel" >
< / cc1:ModalPopupExtender>
Any ideas??

The click is triggering a Page Load, even though you're using the Ajax Controls.
Look at the last post here for one person's solution. Use google if that won't work for you.

You can get your popup panel to persist by calling ModalPopupExtender.Show() method from inside the server-side methods that handle postbacks from controls inside your popup panel.

Related

Navigating from div tags within the same page using buttons?

I am developing a website using asp.net/C#
I want to create a button that can save user data then move to a div tag at the same page.
I already did the saving part, but how do I make the same button to navigate to a different div tag within the same page?
some people use the response.redirect method to navigate to a different page. I want to navigate to a div tag within the same page. For example:
Experience
after I press that it will take me to:
<div class="panel" id="experience">
I want to do the same but with button that can do both that and saving to a DB. As I said, I already did the saving part.
I tried this:
<asp:Button ID="Button1" runat="server" Text="Save & Continue" OnClientClick="#experience" OnClick="Button1_Click" />
But it didn't work.
any ideas? I am trying to access that div tag from code behind
If this is WebForms and you don't want to use javascript, then, after you do the save, you can do a Response.Redirect to the same url, but with the anchor tag, e.g. Response.Redirect("myPage.aspx#experience").
This really depends on the rest of your code though. I suggest posting the relevant parts of your code behind so that we can better see what you have done. Also, don't try to avoid javascript - it is too useful to avoid.
ASP.NET has a Focus method that can be applied to the following ASP.NET server controls:
Button
LinkButton
ImageButton
CheckBox
DropDownList
FileUpload
HyperLink
ListBox
RadioButton
TextBox
At the end of your Button1_Click event handler code-behind, add something along this lines of this:
TextBoxExperience.Focus();
Note - The TextBox control with ID of TextBoxExperience control would be inside of the experience DIV.

ASP Multiview controls

i have some issues right here with ASP Multiview which i can't seem to figure out.
I have this page called Submit.aspx, it is fired up via iframe in AJAX toolkit popup modal extender. I have applied Multiview to this form. When it loads, it will display ActiveIndex 0. If user has clicked the submit button, it will change ActiveIndex to 1 which display "your form has been submitted, etc. and it will auto close via javascript. When i click on Submit link again, the ActiveViewIndex is still stucked at 1, how do i go about programming it to sort of reset/clear the ActiveViewIndex?
You could specifically set the MultiView value with MultiView.SetActiveView(view value)

While calling Modal Popup Extender the rest of the form gets cleared on cancel event

I need to use ModalPopupExtender for the main form to display a subform.
I need to trick the ModalPopupExtender without linking to button event hence used a hidden field as TargetControlID and PopupControlId
I have a submit button in the main form, when i click on it it first displays the Panel (subform) using the ModalPopupExtender (which also has cancel button in it).
I call the modalscreen by using Show() function.
The problem happens as soon as i click on Cancel button in the Modal Form to Hide the form, the rest of the values filled in the main form get erased.
Also other thing which I noticed if I use the ModalPopupExtender without Show & Hide function and link it to some temporary button click event, it works as expected and the values in the main form don't get erased. Can anyone help how to resolve this issue?
I think cancel button is causing postback.If you are using asp:button then change it to normal html button below
<asp:Panel runat="server" ID="popup" CssClass="panelStyle">
<input type="button" id="btnCancel" onclick="Cancel()" value="Cancel" />
</asp:Panel>
<script type="text/javascript">
function Cancel() {
$find("modalBehavior").hide();
}
</script>

Updating a control outside the UpdatePanel

So I have a UserControl with some cascading DropDownLists on it. Selecting from list 1 enables list 2, which in turn enables list 3. Once you've made a selection in all three lists, you can move to the next page.
The DropDownLists are all inside an UpdatePanel. But the "Next Page" button is outside the UpdatePanel. That button should be disabled until all three lists have a selection, and then it should be enabled again. But since the button is outside the UpdatePanel, it doesn't update when I make selections. (Edit: The "Next Page" button is on a page that also contains the UserControl.)
I know one way to resolve this:
var scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(dropDownList1);
scriptManager.RegisterPostBackControl(dropDownList2);
scriptManager.RegisterPostBackControl(dropDownList3);
This ensures a postback when any dropdown list is changed, so that the button can update. But if I do this, I might as simplify by getting rid of the UpdatePanel in the first place.
Is there another way, through some clever JavaScript or something, that I can update a control outside an UpdatePanel without having to give up Ajax?
Place an UpdatePanel around the next button and create a trigger for each of the dropdowns so that it fires an async postback. Ex:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="dropDownList1" />
<asp:AsyncPostBackTrigger ControlID="dropDownList2" />
<asp:AsyncPostBackTrigger ControlID="dropDownList3" />
</Triggers>
Could you not add a update panel around the "next page" and then add a trigger to the dropdownlist updatepanel for triggering the next page update panel?
Just throwing out ideas, without actually having tried it :)
you can upddate a control outside the update panel by placing it into update_panel2 and saying update_panel2.update().
Note the UpdateMode of the UpdatePanel must be set to conditionalfor this to work.
This would ideally be done in javascript, with a server-side validation check in the click event handler.
A quick jQuery example:
//assuming the dropdowns all have the css class "cascade"
$('select.cascade').change(function() {
If ($('option:selected',this).length == 3) {
$('input[id$=btnNext]').removeAttr('disabled');
}
});

How can I pass data from an aspx page to an ascx modal popup?

I'm fairly new to ASP.NET and trying to learn how things are done. I come from a C# background so the code-behind portion is easy, but thinking like a web developer is unfamiliar.
I have an aspx page that contains a grid of checkboxes. I have a button that is coded via a Button_Click event to collect a list of which rows are checked and create a session variable out of that list. The same button is referenced (via TargetControlID) by my ascx page's ModalPopupExtender which controls the panel on the ascx page.
When the button is clicked, the modal popup opens but the Button_Click event is never fired, so the modal doesn't get its session data.
Since the two pages are separate, I can't call the ModalPopupExtender from the aspx.cs code, I can't reach the list of checkboxes from the ascx.cs code, and I don't see a way to populate my session variable and then programmatically activate some other hidden button or control which will then open my modal popup.
Any thoughts?
All a usercontrol(.ascx) file is is a set of controls that you have grouped together to provide some reusable functionality. The controls defined in it are still added to the page's control collection (.aspx) durring the page lifecylce. The ModalPopupExtender uses javascript and dhtml to show and hide the controls in the usercontrol client-side. What you are seeing is that the click event is being handled client-side by the ModalPoupExtender and it is canceling the post-back to the server. This is the default behavior by design. You certainly can access the page's control collection from the code-behind of your usercontrol though because it is all part of the same control tree. Just use the FindControl(xxx) method of any control to search for the child of it you need.
After some research following DancesWithBamboo's answer, I figured out how to make it work.
An example reference to my ascx page within my aspx page:
<uc1:ChildPage ID="MyModalPage" runat="server" />
The aspx code-behind to grab and open the ModalPopupExtender (named modalPopup) would look like this:
AjaxControlToolkit.ModalPopupExtender mpe =
(AjaxControlToolkit.ModalPopupExtender)
MyModalPage.FindControl("modalPopup");
mpe.Show();
Sorry, but I'm confused. You can't call an ascx directly, so...
Is your modal code that you are calling from within the same page, like a hidden panel, etc;
Or is it another aspx page that you are calling on a click event?

Categories