Problem with ajax modal popup extender - ajax

I have a Button which is having modalpopupextender which is working absolutely fine no problem at all, but before the modalpopup appears i want to validated text box control if it is not valid then modalpopup should not appear other wise it should work as usual..
does anybody having idea.

We use following function. On the button click you can call this function. This will validate validation group that is passed to this function and it is work will pop the modal popup otherwise validation error will appear.
function ClientSideValidate(modalId,group)
{
var modal = $find(modalId);
Page_ClientValidate(group);
if(!Page_IsValid)
{
modal.show();
}
}

Something I've done in the past is manually show/hide the modal popup. I realize the ModalPopupExtender control requires a target, so you'll need a dummy target which will remain inactive:
<asp:LinkButton id="btnDummyTarget" runat="server" />
<asp:Button
id="btnActualButtonTiedToValidation"
ValidationGroup="SomeValidationGroup"
OnClick="MyButton_Click"
runat="server" />
<ajaxToolkit:ModalPopupExtender
id="mpeMyPopup"
PopupControlID="pnlSomePanelToShow"
TargetControlID="btnDummyTarget"
runat="server" />
Then, in your codebehind you can do the following:
protected void MyButton_Click(object sender, EventArgs e)
{
if(Page.IsValid)
mpeMyPopupExtender.Show();
}
This is also handy for delete confirmation dialogs.

Related

ItemInvoked vs SelectionChanged

In Windows UWP, what is the difference between the ItemInvoked and SelectionChanged events for a NavigationView? The API reference states
ItemInvoked
Occurs when an item in the menu receives an interaction such as a click or tap.
SelectionChanged
Occurs when the currently selected item changes.
It seems to me that SelectionChanged can detect when navigation occurs even by some method other than clicking a NavigationView.MenuItem, so would be the better, more encompassing option to use?
Or are there different use cases for each?
The main difference would be that the SelectionChanged event is executed only once, but if you click the selected item repeatedly, it is not fired. ItemInvoked on the other hand will execute each time an item is clicked even if it is selected already.
Also - SelectionChanged event will execute when you manually set SelectedItem in code.
Another thing that might be useful to note is that ItemInvoked fires before SelectionChanged when you click on a NavigationView item
I was recently struggling with this question and having a problem when using the SelectionChanged Event. Successive clicks on the same Menu Item yielded no result.
Then I found this blog post (https://blogs.msdn.microsoft.com/appconsult/2018/05/06/using-the-navigationview-in-your-uwp-applications/) which suggested using the ItemInvoked Event for the same reason given in answer #1.
This did not work for me as posted in the Blog but after changing the code to use the InvokedItemContainer Tag property the solution worked just fine.
I have included the test code I used to verify the solution.
private void NvTopLevelNav_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
{
if (args.IsSettingsInvoked)
{
contentFrame.Navigate(typeof(SettingsPage));
}
else
{
string navTo = args.InvokedItemContainer.Tag.ToString();
if ( navTo != null)
{
switch (navTo)
{
case "Nav_Home":
contentFrame.Navigate(typeof(HomePage));
break;
case "Nav_Shop":
contentFrame.Navigate(typeof(ShopPage));
break;
case "Nav_ShopCart":
contentFrame.Navigate(typeof(CartPage));
break;
case "Nav_Message":
contentFrame.Navigate(typeof(MessagePage));
break;
case "Nav_Print":
contentFrame.Navigate(typeof(PrintPage));
break;
}
}
}
}
<Grid>
<NavigationView x:Name="nvTopLevelNav"
Loaded="NvTopLevelNav_Loaded"
Margin="0,12,0,0"
SelectionChanged="NvTopLevelNav_SelectionChanged"
ItemInvoked="NvTopLevelNav_ItemInvoked"
IsTabStop="False"
Header="Lets Go Shopping">
<NavigationView.MenuItems>
<NavigationViewItem Icon="Home" Content="Home" Tag="Nav_Home" />
<NavigationViewItem Icon="Shop" Content="Shop" Tag="Nav_Shop" />
<NavigationViewItem Content="Shopping Cart" Tag="Nav_Cart">
<NavigationViewItem.Icon>
<FontIcon Glyph="[Insert Hex Decimal Value Here. See Segoe MDL2 below for details.]"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Icon="Message" Content="Message" Tag="Nav_Message" />
<NavigationViewItem Icon="Print" Content="Print" Tag="Nav_Print" />
</NavigationView.MenuItems>
<Frame x:Name="contentFrame"></Frame>
</NavigationView>
</Grid>

Primefaces 3.5 dialog's 'visible' attribute does update correctly after ajax 'close' event

Solution here. (Showing and hiding dialog from within bean.)
I have a dialog and show/hide buttons which works fine. Dialog reads boolean value from backing bean and updates it's visible attribute (which makes it show or hide). Everything works fine until I close dialog using default close button, which fires ajax close event. From that moment on show/hide buttons does not work, or rather dialog does not update it's visible state. It stays closed forever.
I found out that, after ajax event is fired, everything updates correctly except dialog visible attribute. Buttons works fine, they updates backing bean correctly (I can see it in log file), and also dialog panel is updated correctly (I can see correct showDialog value displayed on screen).
I know there are other ways to show/hide dialogs, yet I am really curious what is happening in this case - why it works that way? Is there any way to display dialog by reading visibility value from bean (and what's more important to update bean value when dialog is closing)?
My XHTML:
<h:form>
<p:commandButton value="show d1" actionListener="#{testBean.enableShowDialog()}" update=":dialogId"/>
<p:commandButton value="hide d1" actionListener="#{testBean.disableShowDialog()}" update=":dialogId"/>
</h:form>
<p:outputPanel id="dialogId">
showDialog value = #{testBean.showDialog}
<p:dialog header="d1" visible="#{testBean.showDialog}">
<p:ajax event="close" listener="#{testBean.disableShowDialog()}" update=":dialogId"/>
test
</p:dialog>
</p:outputPanel>
And backing bean:
#ManagedBean
#ViewScoped
public class TestBean implements Serializable {
private static final Logger LOGGER = LoggerFactory.getLogger("TB");
private boolean showDialog;
public boolean isShowDialog() {
LOGGER.info("getter isShowDialog={}", showDialog);
return showDialog;
}
public void enableShowDialog() {
showDialog = true;
LOGGER.info("isShowDialog set to true");
}
public void disableShowDialog() {
showDialog = false;
LOGGER.info("isShowDialog set to false");
}
}
Maybe you can hide that close button:
closable="TRUE"
or maybe you can update variable through onHide attribute.
I just noticed that dialog is not in FORM?
found similar post HERE
And here is I think hint for you, which gave me answer:
just add oncomple="someDialog.show()" event to buttons and widgetVar="someDialog" to dialog
as I understand close changes rendered attribute, thats why you can't show it.

How to reset telerik dropdownlist control value on client side

I want to reset dropdownlist selection on clear button click and set default message.
<telerik:RadDropDownList ID="radDrpDwn_User" runat="server" Width="325px" DefaultMessage="--select--">
</telerik:RadDropDownList>
First of all there isn't any control in telerik called (RadDropDownList) , the compatible control is RadComboBox control
so you define it using the Following ;
<telerik:RadComboBox ID="radDrpDwn_User" runat="server" Width="325px" DefaultMessage="--select--">
</telerik:RadComboBox>
and in the clear Button :
protected void Clear_Click(object sender,EventArgs e)
{
radDrpDwn_User.ClearSelection();
}
regards

JuiceUI Slider - ValueChanged event not firing

I'm trying to include a JuiceUI Slider control inside a ASP.NET GridView control where each row will have a unique slider control. As a test I created a Slider control:
<juice:slider ID="MasterThresholdSlider" Value="50" Min="0" Max="100" runat="server"
Step="25" ValueChanged="MasterThresholdSlider_ValueChanged"></juice:slider>
<asp:TextBox ID="MasterThresholdText" runat="server"></asp:TextBox>
Now from the documentation I have read, I can detect the value being changed when the ValueChanged event is raised. So in the code behind I have created the following:
protected void MasterThresholdSlider_ValueChanged(object sender, EventArgs e)
{
Juice.Slider slider = (Juice.Slider)sender;
MasterThresholdText.Text = slider.Value.ToString();
}
For some reason the event doesn't fire when I run the application (breakpoint is at the beginning of the event). Anyone know what I'm doing wrong?
You'll need to add AutoPostBack="true" to the juice:slider control to initiate an autopostback. Otherwise that event won't fire until something else on the page triggers a postback.

Telerik RadAlert back button cache problem

I'm sure you have had this one before so if you could point me to something similar....
I have a server side creation of a RadAlert window using the usual Sys.Application.remove_load and add_load procedure however the alert keeps popping up as it seems to be caching when the user hits the back button after it has been activated. I have tried to put a onclick event on a button to clear the function using remove_load before it moves to the next page however it still doesn't seem to clear it.
Its used in validation so if a user inputs failed validation it pops up. If they then go and enter correct validation it then moves onto the next page. If they then use back button this is where it pops up again. Any ideas?
Server side:
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
btnSearch.Attributes.Add("onclick", "Sys.Application.remove_load(f);");
}
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
string radalertscript = "(function(){var f = function(){radalert('Welcome to RadWindow Prometheus!', 330, 210); Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()";
RadAjaxManager1.ResponseScripts.Add(radalertscript);
}
Ive also tried using
RadAjaxManager1.ResponseScripts.Clear();
before it moves on to the next page on the postback event
What lingvomir says is correct. What I would suggest as a solution is to ajaxify that Search Button.
e.g.
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="Button1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<asp:Button ID="Button1" runat="server" Text="show radalert" OnClick="Button1_Click" /><br />
and in codebehind:
protected void Button1_Click(object sender, EventArgs e)
{
string radalertscript = "radalert('Welcome to RadWindow Prometheus!',330,210);";
RadAjaxManager1.ResponseScripts.Add(radalertscript);
}
I don't think the problem is with the radalert() function - You will get the same behavior if you use the normal browser alert() as well. The Sys.Application.Load event is raised each time the page is loaded in the browser - including when you use the back button to open it again. If the code that adds the radalert() is also on the page, it will run as well and the alert will be displayed during Load.
You need an intermediate page that loads the client version of the
alert, the callback function could then navigate to the correct page
using location.replace(...) - using location.replace will remove this intermediate alerting page from history
hope that helps

Resources