I am new to the ASP.NET MVC 3.0, trying to popup partial view using Jscript/AJAX. Any help is appreciated.
Thanks,
Srini
You can launch a popup window with either javascript or jquery. The popup then points to controller/view so that view is displayed in the popup. If you google opening a popup you'll find lots of resource. Its a client side action so really does not have much to do with mvc. You'll just show your view inthe popup.
You can see this article on how to attach code to launch a popup. This is for webforms but the javascript is still applicable for mvc
Also this SO post
Let's say you create a controller action that returns your partial view, something like this:
public ActionResul get_partial_view()
{
....some logic
return PartialView("partial_view_name");
}
Then in your view where you would like the popup to appear you could use some jquery to load the dom element that will contain the content of the popup window like so:
$.get('/controller_name/get_partial_view', function(html) {
$('#popup-content').html = html;
});
Related
I'm using ASP.net MVC and angular js to create a web. I used angular ng-route to render a View when click a link. The moment when render the View, i want fire the Controller event in order to bind the data and display it. (Similar with ASP.net web form, when page load then can call the data binding function).
I'm new in MVC, hope can get some help. Thank you.
As you are using MVC, it would be better if you use the return View(); statement on a Controller, and it would render the view that you want.
Here's a sample:
http://www.codeproject.com/Articles/806029/Getting-started-with-AngularJS-and-ASP-NET-MVC-Par
I do have an application containing JavaFX webview. Within the application I am generating a html page and it gets displayed.
Now, if the user clicks or selects text I would like to get the corresponding HTML code of the selection.
Is that even possible?
Thank you!
Sure, you need to handle selection and click events in your web page with JavaScript, i.e. with jQuery and in your event handler function to call you Java method handler. Here is an example of JS-to-Java call - Communicating between JavaScript and JavaFX with WebEngine. This will basically provide a Java object inside a WebView:
JSObject jsobj = (JSObject) webEngine.executeScript("window");
jsobj.setMember("javaBridge", new Bridge());
And this is how it can be accessed from a WebView:
here
I am looking into replacing the ReportViewer toolbar. Just doing discovery right now. I know about the JavaScript api for the report viewer. This does not include an API for the pagination controls.
I have dug around in the generated HTML and have figured out how to trigger a postback to do the pagination. Calling the following in Javascript works even with the toolbar not being displayed.
__doPostBack("ReportViewer1$ctl05$ctl00$Next$ctl00")
I don't know the gotchas of calling a post back like this. As the string being passed into the method is the name of the input button. It seems like the name may be able to change. I also don't know what the $ctl stuff means.
I am aware of how to get reportviewer to not page reports by setting the interactive height to zero. I am just exploring all my options at this time.
Is there an easier way to do pagination without the ReportViewer toolbar being displayed? If not, what are the gotchas of triggering a postback?
The final solution to this was to do a postback with customer arguments.
Client Side JS:
function loadPage(pageNumber) {
$('#__EVENTTARGET').val('pagination');
$('#__EVENTARGUMENT').val(<pageNumberToGoTo>);
$('#form1').submit();
}
The two fields that get populated are what is created by default for ASP.NET postbacks.
Server Side C# in the ASP.NET pages OnLoad event:
if (Request.Form["__EVENTTARGET"] == "pagination")
{
int pageNumber = int.Parse(Request.Form["__EVENTARGUMENT"]);
_reportViewer.CurrentPage = pageNumber;
}
I know my issue is very common and similar types has been asked many times over here, but my problem is somewhat different. I am working on ASP.Net 4.0 web application where on my required page i have ajax toolkit 4 calendar control, toolkitscript manager and few asp controls. Now from that pop up i am doing a save operation on button click. What i want is to close popup window after successful save. Problem is not in saving but after saving , automatically closing the popup screen. I have tried the following ways:
RegisterStartUpScriptBlock(this.GetType,"closeForm","return window.close();") and all other required params
ClientScript.RegisterStartUpScript()--- alongwith params and with both return window.close(); and window.close() also with self.close();
Also i have under the title tag...
I think i have tried all the ways , i can. I feel i am lost. Please help me out....
if your using a script manager on the page...
first create a function to close the calendar in js in your html...
function closeCalendar(){
....
}
then on the codebehind use this to call that js function
string script = string.Format(#"closeCalendar()");
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), UniqueID, script, true);
If the popup you mean is the AJAX Toolkit Modal Popup, you can just call popup.Hide(); in codebehind.
If it is a browser window, did you try to remove the return part from your code?
Note that windows.close() will not work unless the popup is opened via window.open();
Also, did you try to just put the script tag inside PlaceHolder control that is hidden (server-side Visible=false) by default and only shown when you need?
I am building a Web Application using asp.net (C#). I come from windows forms development and find myself in a hard spot. Im making an application where the user should edit some simple information about himself, and thus i need to create a new dialog. How do I do that in asp.net? I have a button which event is handled serverside, and when i click lthis button i want to popup a dialog where i can show my custom web control (or any web control, lets make it generic from the start). How do I go about with doing so?
I got some part of the way by looking at the internet, that i need to make a section and set the z-index to 1000, but how do i make it visible (block)? Please help here as i am completely lost...
/H4mm3rHead
If you're not concerned about using a library, try Microsoft ASP.NET AJAX Control Toolkit, they have several controls that can create something you want (the ModalPopup control).
The AJAX Control Toolkit has a ConfirmButton extender which will do exactly what you are looking for.
I used to do the following:
1. my new pop up is just a new aspx page like any other page
2. add a button (or just a link) that fires a client side java script function
3. in the function I use window.open and put params to open my popup page with no toolbars or scrollbars and proper size to its content
check this for more info on #3