Automatically launch a popup window specified in JavaScript

Aim:- I am trying to automatically open a radwindow from the server-side based on a specific IF condition.

Snippet Used:-

In the aspx page, I have defined the radwindow as follows:

<telerik:RadWindowManager Skin="WBDA" ID="AssetPreviewManager" Modal="true" 
EnableEmbeddedSkins="false" runat="server"  DestroyOnClose="true" Behavior="Close" 
style="z-index:8000">
    <Windows>   
        <telerik:RadWindow ID="DisclaimerAlertWindow" runat="server" Width="720px" Height="220px" 
Modal="true" visibleStatusbar="false" VisibleTitlebar="false" keepInScreenBounds="true" title="Sourav">                                            
      </telerik:RadWindow>  
   </Windows>  
</telerik:RadWindowManager>

In the JavaScript section, there is a function defined to open the radwindow:

function openRadWindow() 
     { 
        var oWnd = radopen('DisclaimerAlert.aspx', 'DisclaimerAlertWindow'); 
        oWnd.set_title('Access Denied !');  
        oWnd.Center(); 
        return false; 
     }

Therefore, in the Page Load event on the server side of the aspx page, I check an IF condition and then call the 'openRadWindow()' function like this:

protected void Page_Load(object sender, EventArgs e)
{
if (fieldValue == "False") 
{ 
 string xyz = "<script type='text/javascript' lang='Javascript'>openRadWindow();</script>"; 
 ClientScript.RegisterStartupScript(this.GetType(), "Window", xyz); 
}
}

Issue:-

However, when running this code, I encounter the following JavaScript errors:

  1. Object doesn't support this property or method.
  2. 'undefined' is null or not an object.

I would appreciate any assistance on how to achieve my goal as I am currently stuck.

Answer №1

Greetings! Allow me to present to you my approach in creating a RadWindow dialog using solely Javascript code.

Our solution involves the development of two key methods: one for initializing the RadWindow dialog and another for retrieving the arguments passed back after the RadWindow is closed. The possibilities for actions in the second method are endless (e.g., postback).

Here is the code implementation:

Initializing the RadWindow dialog:

function createRadWindowDialog(url, args) {
    var windowManager = GetRadWindowManager();
    if (windowManager) {
        var radWindow = windowManager.open(url, "<your_dialog_name>");
        if (radWindow) {
            radWindow.set_initialBehaviors(Telerik.Web.UI.WindowBehaviors.None);
            radWindow.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Resize);
            radWindow.setActive(true);
            radWindow.SetModal(true);
            radWindow.center();
            radWindow.set_visibleStatusbar(false);
            radWindow.set_keepInScreenBounds(true);
            radWindow.set_minWidth(640);
            radWindow.set_minHeight(480);
            radWindow.setSize(640, 480);
            radWindow.set_destroyOnClose(true);
            radWindow.add_close(handleRadWindowClose);
            radWindow.argument = args;
        }
    }
}

Closing the RadWindow dialog:

function handleRadWindowClose(sender, args) {
    var returnedArgs = args.get_argument();
    // 'returnedArgs' stores the values passed back from the RadWindow
    // You can utilize these values for further actions
}

How to execute this?

You may integrate the open method into your desired function. In my case, I possess a method as illustrated below and I will invoke the RadWindow as follows:

function DisplayForeignKeyFrontEditSingle(param1, param2){
    var url = "ForeignKeyFrontEditSingle.aspx";
    var args = new Array();
    args[0] = param1;
    args[1] = param2;

    createRadWindowDialog(url, args);
    return;
}

Remember to define a RadWindowManager control in your setup

function GetRadWindowManager() {
    return $find("<%=your_radwindow_manager_control.ClientID%>");
}

Answer №2

If you're wondering about how to utilize the ScriptManager.RegisterStartupScript function, check out this helpful guide: http://www.example.com/how-to-use-scriptmanager-registerstartupscript. Remember to take note of using the ScriptManager's functionality and consider the Sys.Application.Load event to ensure your code doesn't run prematurely.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to remove the initial row of inline-block divs

My webpage is filled with inline-block divs that are contained within a larger div like so: <div class="container"> <div class="text">Text 1</div> <div class="text">Text 2 ... rest of the nu ...

"Use jQuery to toggle the slide effect for the first element of a

Below is the HTML code snippet: <div class="row header collapse"> Content 1 <i class="fas fa-chevron-circle-up" ></i> </div> <div class="instructions-container"> <div></di ...

Using request-promise from npm, send a request with a self-generated certificate in JavaScript

When trying to make a simple request using the request-promise library, I encountered an error due to having a self-signed cert in my chain. This is a requirement that cannot be avoided. Fortunately, with NPM, I was able to specify the cert for installing ...

Failed to build development environment: Unable to assign the attribute 'fileSystem' to a null value

I'm attempting to launch an Ionic 2 Application, but I keep encountering this error when running ionic serve Error - build dev failed: Unable to assign a value to the 'fileSystem' property of object null Here is the complete log: λ ion ...

Using Commas to Separate ChartJS Data Points

I am having trouble formatting numbers in a ChartJS graph to include commas. For example, my data points are currently displayed as 1032.05, 4334.75, 8482.46 but I need them to show as 1,032.05, 4,334.75, 8,482.46. If you would like to see the current cod ...

Tips for accessing child elements within an Angular component

I'm struggling to get a reference of child elements within a component. I have experimented with ElementRef, TemplateRef, QueryList, ViewChild, ViewChildren, ContentChild, and ContentChildren without success. <app-modal> <section #referenc ...

Why does json_encode() work for one string and fail for another?

UPDATE: Resolved the issue. Initially, someone left a comment with a solution that was later deleted. Interestingly, simply adding semi-colons after the two json_encode lines fixed the problem. I'm still puzzled as to why string1 worked without a clo ...

Using Rails 6 to trigger a JavaScript function after rendering a partial

Newbie in Rails and Javascript here, During a training project, I implemented a feature where flash messages automatically disappeared after a few seconds using JQuery. When a visitor added a product to their cart through an AJAX request, a flash partial ...

What is causing the newly generated input tags to disappear from the page?

I'm having an issue where my code successfully creates new input tags based on user input, but they disappear shortly after being generated. What could be causing this to happen? <form> <input type='text' id='input' /> ...

I currently have a set of 6 popovers that all open simultaneously, but I am looking to make them open sequentially, one after

My component generates a div with 6 different experiences, each with its own popover. However, when I click on an experience to open its popover, all 6 popovers appear. How can I assign a unique ID to each popover? This is the code for my experience compo ...

Using React to Filter cards according to the selected value from an Autocomplete feature

I'm currently developing a React application that utilizes Material-UI's Autocomplete component to filter cards based on selected car brands. These cards represent various models, and the goal is to update them when a user picks a brand from the ...

The issue with window.addEventListener failing to update state when the scrollY is not at zero persists during route changes

When using addEventListener in the componentDidMount lifecycle method to add a class to a header based on the scroll behavior, an issue arises when changing routes via a modal or browser back button. The scrolling state is not accurately reflected as the s ...

Implementing Firestore Read Limitations in a React Application

I have encountered an issue with Firebase billing based on the number of document reads. There is a daily limit of 50k reads per day in Firestore, but when I try to fetch documents in my React app, it triggers a quota exceeded error. FirebaseError: Request ...

Developing an intricate nesting structure for an object

this is my code snippet: "book" => {b:{o:{o:k:{'end':true} could someone please provide an explanation or a helpful link for this? const ENDS_HERE = '__ENDS_HERE' class Trie { constructor() { this.node = {}; } insert(w ...

Guidelines for incorporating ASP Controls into a jQuery Dialog box

In the setup I have, there is a division acting as a jQuery Dialog container. Inside it are two asp:ListBoxes and an asp:button. The desired action is to select an item from ListBox1 and upon clicking the button, that selected item should transfer to ListB ...

What is the reason for webpack adding "-es5" and "es2015" to my TypeScript files?

When Webpack converts my typescript files into Javascript files, it appends -es5 to the name. For instance, I expect the file to be named background.js, but it actually generates 4 separate files: background-es5.js background-es5.js.map background-es2015. ...

Showcasing a dynamic image as a task is being completed within a JavaScript function

Is there a way to show a loading image while waiting for a JavaScript function to finish? <script type="text/javascript"> function create() { //Perform operation } </script> I am looking for a solution to display a loading image until ...

Learn the steps for converting data from xlsx or csv files into JSON format

I am currently working on developing an application that allows users to upload xlsx or csv files from the frontend and submit them to a backend built with nodejs and express for processing. However, when I receive the data in the backend, it appears in th ...

Retrieve the values of a function using the Firebase database

Hey, I'm in a bit of a pickle trying to retrieve the values returned by my function. I can see them just fine in the console log, but how do I actually access them when calling the function? function getprofile(useruid) { return firebase.database ...

Managing State in React using Maps

As someone who is new to coding, I am currently facing an issue and seeking help to resolve it. I am using axios to retrieve a JSON file and store it in a state utilizing Redux for form population. I am then utilizing .map() to break down the array and dis ...