What I am trying to do is create a bit of reusable code that can write a modal popup, either through javascript or using the ajaxcontrol toolkit all from the code behind.
The modal would be a sort of login pop up for controlling access to more restricted areas of the website allowing certain users to re-credential in for higher access.
I was thinking of doing a user control but I forsee some problems with passing all of the appropriate information along without it being completely hoaky.
If anyone has any good links or advice for doing so it would be greatly appreciated!
Thanks!
EDIT: I know how to use the ajax control toolkit and its controls, and I know how to make login screens, I'm asking how to do this entirely from the code behind from a class that would be independent of its implementation
Write a server control or an asp.net extender control like ajax control toolkit does.
The best you can do is download the source of AjaxControlToolkit from CodePlex and explore the source of ModalPopup within that.
Another thing you can do is just simply call the popupExtender to show from the code behind file.
As we know the extender has to be somehow linked to a target control, just add a dummy control as a hidden textbox (actually to hide the control, do it from the asp file, as style="display:none" not from the control properties (visible=false) otherwise it won't work), and then just call from the code behind the extender like this:
DummyTextBox_ModalPopupExtender.Show();
You can call it in the page_load or with anyother trigger.
No need javascript neither client side, just, server side.
Xds.
There's a sample modal popup using the ajaxtoolkit on asp.net
The modalpopupextender in the Ajax control toolkit is easy to use, plus it has a server or client side method for showing the popup (in past versions, I had trouble with the server-side method, but it may have been resolved in the current version).
You could put the modalpopupextender inside the master page, and create a JS method in the master page you can call to invoke the modal popup extender, like:
function showPopup() {
var modal = $find("<%= mpe1.ClientID %>");
modal.show();
}
The contents of the popup can be replaced via javascript, as you control that content.
Add BehaviorID="my_cool_id" to your modalpopup extender and add this to any server function
ScriptManager.RegisterStartupScript(Page, this.GetType(),"id","function pageLoad(){$find('my_cool_id').show();}",true);
Related
I have a page where I am getting a popup on button click and popup it self is a page with usercontrol on it.Now my problem is that on user control which is on popup page I want to refresh parent page of popup page when popup is closed.Any help will be appreciated.
This cannot be done, should not be done, and anyone contemplating doing any such similar should be frogmarched out back and beaten until their buttocks are purple.
If I would do this personally, although I highly recommend avoiding this type of solution, I would not solve it solely on client side because it is difficult to verify that all browsers and all client will work as intended. Instead, consider signaling the server upon closing the popup-dialog - using the window.onbeforeunload event. You may then implement an asynchronous JS solution between your parent dialog and the server where the server can notify the client to update when the popup is closed.
But, please do consider implementing the "popup" as part of the parent page instead and maybe have a master user control that may update the page.
Simple use the below line while closing the popup it will automatically refresh the parent page.
window.location.href = window.location.href;
The Asp.Net's ajax implementation using UpdatePanel is really slow and experienced people know that the whole ViewState is sent to server even though we are only interested in doing partial postback. So I started using Jquery but I don't know how do I make a request from Jauery to server and get UserControl's HTML in output? The UserControl in turn may have some controls like textbox etc.
In short, I want some functionality that Asp.Net MVC has which uses RenderPartial.
In the context of Page, you can load a control and render its output.
Control myControl = Page.LoadControl("myControl.ascx");
myControl.RenderControl(System.Web.UI.HtmlTextWriter);
But that just gets the html that the control would output to the page. This is fine if your control has no more events and just does something onload, but if you want to postback from it, then this will not work (as mentioned in the comments.)
From my experience, sometimes ago, trying to invoke a user control directly is a pain.
I sometimes put my userControl in a blank page and simply do a $.get(
So, for each userControl, I have to make a dedicated blank page...
Other times, the userControl is already embedded in an existing page within a named div container. I then invoke $.load( on the page, targetting the container div.
In this case, I don't have to make a page, but I waste bandwith and lose script and style tags (jQuery cleans them up since v1.4)
I have an two divs in my web page i am able to show one div as modal popup using styles how is it possible to show the other dive as modalpopup to the existing one.
You can use the css z-index property to control the stack order of elements.
Also take a look at the JQuery plugin jqModal. Here are some examples. Specifically take a look at the Modal, Nested Modal section.
From their site:
jqModal is a plugin for jQuery to help you display notices, dialogs,
and modal windows in a web browser. It is flexible and tiny, akin to a
"Swiss Army Knife", and makes a great base as a general purpose
windowing framework.
Another JQuery plugin which may be of interest to you (if you create the modal dialogs yourself), is the BlockUI plugin.
I am making an ASP.NET application. I have a page which displays a list of data [as a GridView].
I need to display a list of objects [as a GridView] in a new view over the current view, not a new window but a kind of AJAX popup, so that the context shiftes on the page to the new view/form!!
Shall i use Modal Window for this? If so, how shall I do it, as the function to open the modal shall be fired when an item of the GridView is selected?
Is there any plugin which can simplify my task?
You could always try the ASP.net Ajax Control Toolkit
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpopup.aspx
It supported by the ASP.net team and it's really easy to use!
There is a good plugin called blockUI for jQuery that will let you achieve this quite easily.
You can use it to show any HTML that you desire or even load an iFrame using that. You can download this plugin and find examples here
http://jquery.malsup.com/block/
If you post some sample code I can probably help you create your modal pop up!
Please do vote up my answer or mark the checkbox next to it, if I helped you at all. Thanks :)
How do I create a Messagebox in ASP.NET web forms?
I can't add system.windows.form.
Please help. I don't want to do it in javascript.
To pop-up a message box you use alert() in JavaScript. You have to use JavaScript to do this.
You can use a ModalPopup from the ASP.NET AJAX control toolkit.
Of course, behind the scenes, it uses JavaScript, but you don't have to write the JavaScript yourself.
in web you have 2 chooices:
create a div and show / hide it with the message
use the alert or confirmation box with javascript
if you're using ASP.NET, and you want this kinda of things out-of-the-box I strongly suggest you to download and use the ASP.NET Toolkit
you will see many solutions in the left side that you can use in your project and one of them is the Modal Popup ... check them out!