Popupextender disappears after postback in Usercontrol - ajax

Dear Fellows i have a usercontrol which takes destination details from users with multiple dropdownlist controls...
e.g. Country Dropdownlist produces postback and populate states dropdownlist based on select values. State's Dropdownlist produces postback to get cities based on states.Furthermore everything happens in an Ajax UpdatePanel.
--Select--
I'm using this control in popupextender to be displayed. Each time dropdownlist postback popupcontrol disappears. Please help me with that
<asp:Panel ID="pnlhotelsearch" runat="server">
<div>
</div>
<uc1:SlimMainsearchpanel ID="SlimMainsearchpanel1" runat="server" />
</asp:Panel>
<ajaxToolkit:PopupControlExtender ID="PopupControlExtender1" TargetControlID="lnkbtnCriteriea" PopupControlID="pnlhotelsearch" runat="server">
</ajaxToolkit:PopupControlExtender>

There are several suggestions at ASP.net Modal Pop up extender and DropDownlist autopostback.
The way I solved it was to raise a new event, say DropDownChangedEvent, in the AutoPostBack event handler. The handler for the new DropDownChangedEvent calls PopupExtender.Show.

Related

RadioButtonList not triggering ajax postback

I have an ASP.Net RadioButtonList control with AutoPostBack set to true and a server side handler for the SelectedIndexChanged event.
<asp:RadioButtonList runat="server" ID="btnAcceptReject" RepeatDirection="Horizontal" CssClass="checkboxlist borderless" ValidationGroup="data" AutoPostBack="true" OnSelectedIndexChanged="radioButtonList_SelectedIndexChanged">
<asp:ListItem Text="The edition is hereby validated for conformity to standards" Value="0" Selected="True"></asp:ListItem>
<asp:ListItem Text="The edition does not meet standards and still has to be reviewed" Value="1"></asp:ListItem>
</asp:RadioButtonList>
I am using a RadAjaxManager, a telerik control, to handle ajax postbacks
<telerik:RadAjaxManagerProxy runat="server" ID="RadAjaxManagerPRoxy1">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="btnAcceptReject">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="pnlControls" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
pnlControl is a panel on the page containing controls that will be enabled/disabled depending on which radio button was checked.
The above always performs a full postback of the page.
how can i make it perform an ajax partial postback?
Could it be a result of you using RadAjaxManagerProxy instead of RadAjaxManager?
RadAjaxManagerProxy expects that there is a RadAjaxManager declared elsewhere within a Master Page etc.
If that fails then I suggest to alter the pnlControl to become a RadAjaxPanel and then remove the RadAjaxManagerProxy declaration as the RadAjaxPanel will do all the work for you.
Good luck!
In reply to your comments, I would now suggest to do the following within the referencing ASPX page (if that is possible under your scenario):
Add a RadAjaxManagerProxy to the client-side
Within the code-behind add a new Sub to be called during Page_Load (outside the postback check)
Within the Sub:
Dim panel As Panel = CType(myUserControl.FindControl("pnlControls"),Panel)
Dim radio As RadioButtonList = CType(myUserControl.FindControl("btnAcceptReject"), RadioButtonList)
RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(radio, panel, Nothing)
*Nothing - Optionally a RadAjaxLoadingPanelID if you have one declared on the .ASPX page
Hope it helps!

jqGrid custom pager search button

We have our custom button that is ASP.NET custom server control. We use it on all our pages for action buttons (< NS:OurButton ID='btn' runat="server" Text="Search"/ >).
Now we want to use that button to open our custom search form to filter the records in jqGrid.
Our business requirement that the search button must be a part of jqGrid pager.
How I can do it? I tried to search google and wiki help for jqGrid, but didn't found any way how to add that custom search button to the jqGrid pager.
If it's matters, the button rendered to the client in that markup:
<div id="btn" class="OurCustomButton">
<div class="LeftSide"></div>
<div class="ButtonContent">Search</div>
<div class="RightSide"></div>
</div>
Or maybe it's possible to create totally my own custom pager, with my own design and buttons and then to tell the jqGrid to use it's controls as triggers or to trigger events on my own with correct parameters?
One solution I can think of is to use jQuery's insertBefore()(or insertAfter) and have the html for your button inserted on the document.ready() event.
The code could be:
jQuery(document).ready(function(){
$('<div class="ButtonContent">Search</div>').insertBefore('.RightSide');
});

How to get a DropDownList select action to trigger submit button in MVC 4?

I have a DropDownList in an MVC 4 web application that is used as a filter. When a new value is selected from the drop down, the user then has to click the submit button. Is there a way to get the DropDownList to perform the same submit action when a new item is selected from the drop down so I can eliminate the submit button altogether? No custom methods have been written for the submit button, I am just using the generic one that is in MVC.
Update: Code is as follows:
#Html.DropDownList("userName",Model.Users) <input type="submit" value="Search" />
<select name="dropdown" id="dropdown" onchange="this.form.submit()">
p.s. first link in Google search results
Edit
#Html.DropDownList("userName",Model.Users new {onchange="this.form.submit()"})

Can button click event goes to controller instead in javascript

The click event is in javascipt. Can I make it to be in controller? I want to write in C#, not in Javascript. Here is the code for my button:
<asp:Button ID="btnAdd" runat="server" onclick="btnAdd_Click" Text="Add"
Width="112px" />
If I understand right your question, you have to use a Form tag in your page or via JQuery.onClick() send an ajax, post or get, to the controller and from it return a JSON with your data

custom usercontrol content in UpdatePanel disappears on button click postback

I have the following function that updates the UpdatePanel content by adding/loading an ascx custom usercontrol in the placeholder that is in default.aspx:
protected void NavigationTab_Click(string ascxpath)
{
Control ctrl = LoadControl(ascxpath);
//cphmaincontent is my asp ContenPlaceHoderId in masterpage
PlaceHolder phmaincontent = (PlaceHolder)cphmaincontent.FindControl("phmaincontent");
phmaincontent.Controls.Clear();
phmaincontent.Controls.Add(ctrl);
upmaincontent.Update();
}
Masterpage UpdatePanel:
<asp:UpdatePanel ID="upmaincontent" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lbmsg" runat="server" Text=""></asp:Label>
<asp:ContentPlaceHolder ID="cphmaincontent" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
I am calling NavigationTab_Click from my navigation control that is another custom ascx control, my ctrl Control object that is loading dynamically on each has button and label when I click the button it simply reassigns some text to the label.
and I have this following code on my masterpage just to get the ascx control path:
protected override void OnInit(EventArgs e)
{
//raising an event to set ascx path
mainmenu.NavigatePath += new usercontrols.mainmenu.NavigationHandler(NavigationTab_Click);
base.OnInit(e);
}
so far everything works good, after loading my ctrl object by calling NavigationTab_Click function I see my ctrl in the placeholder and has the button and the label but the issue is this if I click this button it should reassign the label to some text but instead the whole ctrl control content disappears, please help.
When you're adding controls dynamically you must ensure that it gets recreated on every postback. You also have to ensure that you assign the same ID as before, otherwise events will not be triggered correctly and values cannot be reloaded from ViewState. This must be done it Page_Load at the latest(better in Page_Init).
That's the reason why you should avoid dynamical controls whenever possible.
So you can add controls in event-handlers like you've done. But they must be recreated on the next Postback. So you need to store somewhere what(f.e. IDs) or how many controls are already created. That can be done for example in ViewState or Session. Then you can assign appropriate IDs to the controls(for example with the index or ID suffixed).
Here are some additional informations on this subject:
View State and Dynamically Added Controls *
ASP.NET Page Life Cycle Overview

Resources