This is structure I have:
Master page -> Content page -> User control -> Telerik grid with its context menu, hidden field.
This means: Master page contains content page, content page contains user control, user control contains Telerik grid with its context menu and hidden field.
I open popup window by clicking option in Telerik grid's context menu. After I choose some option in combo box in that popup window I press OK and close it. But I don't know how to reference opener that should be user control with Telerik grid and hidden field. I want to set hidden field to some value.
This is JavaScript code I use:
<script language="javascript" type="text/javascript">
function ReturnValue() {
var choice = document.getElementById("DropDownList1").value;
if ((window.opener != null) && (!window.opener.closed)) {
window.opener.document.getElementById("HiddenField1").value = choice;
}
window.close();
}
</script>
But, it fails on this line because opener is master page:
window.opener.document.getElementById("HiddenField1").value = choice;
So, how can I make it work?
Related
I am creating an application in which
There is datalist for items which contains collapsible panels with edit and delete button in the header panel.
On click of edit button I opened a new browser window for edit details using window.open(); javascript, which contains item details of the respective item and save button.
So I need functionality like when user clicks on save button on edit window, edit window should get closed and the parent page which has datalist should get refreshed. Note: Please consider I have URL of parent page.
For Closing the window I have tried following code:
string closeScript = "<script type='text/javascript' language='javascript'>window.close();</script>";
ClientScript.RegisterClientScriptBlock(typeof(CmsManagementPage),
"cancelScript",
closeScript);
But the edit window is not closed, and is there any solution for refreshing the parent page?
You can create the following function in javascript and call on edit button:
function editClose(url) {
window.opener.location=url;
window.close();
}
I have a table in my page, for which I get the data from database. In some cells I have an edit icon.I want when users clicks on it, they see a pop up window.
In the pop up window, I want to show three option(check boxes), that user can select only one of them, and then click on OK button, and return the value of the selected option to the data variable.(as you see in the code below)
I have to mention, that right now when the user clicks on the edit icon, some information are sent to another file. Because I need to update database.
$(".SSO").click(function () {
var id = $(this).attr("data-id");
var data= HERE I NEED TO GET THE VALUE OF THE SELECTED OPTION IN THE POP UP WINDOW
}
So SSO is the value of class attribute for the image icon. data-id value helps to update the correct record in the database.
Right now this is the code in one file:
$(".SSO").click(function()
{
var id = $(this).attr("data-id");
// open popup window and pass field id
window.open('sku.php?id=' + encodeURIComponent(id),
'width=400,toolbar=1,resizable=1,scrollbars=yes,height=400,top=100,left=100');
}
and this is the code in sku.php
<script type="text/javascript">
function sendValue (s){
var parentId = <?php echo json_encode($_GET['id']); ?>;
window.opener.updateValue(parentId, s);
window.close();
window.close();
}
</script>
<form name="selectform">
<input type=button value="OK" onClick="sendValue(document.querySelector('.messageCheckbox:checked').value);"
</form>
Mu form right now has only OK button, when when I click on teh edit button, nothing happens. Should not I see a pop up window, with OK button inside it?
Typically a popup windows is shown with alert() or something similar, which causes the browser to make an actual popup window. That kind of popup window cannot have HTML elements added to it. You could do something like this http://www.codeproject.com/Tips/170049/Pure-HTML-CSS-Modal-Dialog-Box-no-JavaScript
I used those in a website and I liked them a lot, but I am not a fan of the css :target selector, so I opened it with Javascript instead, but it is pretty much the same thing.
In my extension I want to hide/show items on the context menu based on the url I get:
from a link if the user opens the context menu over one,
from the text selected, also if the user opens the context menu over the text.
In the function to show/hide items in the context menu I do the following check:
if (gContextMenu.onLink) {
url = gContextMenu.target.href;
}
if (gContextMenu.isTextSelected) {
url = content.window.getSelection();
}
If some text is selected in the page, and the user opens the context menu over a link, both conditions are true. Also, if some text is selected, and the user opens the context menu anywhere in the page (over the selection or not), the isTextSelected flag is also true.
Is there a way I can detect what is the real element over which the user has used the right click? How can I know if the right click was over the selected text or not?
First of all, there is gContextMenu.target, which contains the Node which was under the cursor, if any (aka. it might be null in very rare cases).
The gContextMenu code actually uses gContextMenu.target to initialize things like .onLink
As for checking if the the focused node is actually contained within the current selection, you can use .getSelection().containsNode() on the focused document.
var isFocusedNodeInCurrentSelection = false;
var selection = gContextMenu.focusedWindow &&
gContextMenu.focusedWindow.getSelection();
if (selection) {
isFocusedNodeInCurrentSelection =
selection.containsNode(gContextMenu.target, true);
}
// Do something with that information.
I have ASP.NET web application that contains master page. Master page contains content page. Content page contains user control. User control contains Telerik grid with its context menu.
I'd like to click the item in grid's context menu and open new popup modal window. In that window there's drop down list. I pick up some option from drop down list and click OK. I'd like to get the value selected from drop down list and use it in my ASP.NET code to proceed further.
I've tried to use hidden field to store the value from drop down list but it doesn't work because I'm not sure where hidden field should be placed.
This is my code:
Open popup window:
function ClientItemClicked(sender, eventArgs)
{
if (eventArgs.get_item().get_value() == "excel")
{
var retVal = window.showModalDialog("ExportToExcelChoice.aspx", null, "dialogWidth: 400; dialogHeight: 200; center: yes; resizable: no;");
}
}
Click "OK" to close popup window:
function ReturnValue() {
var choice = document.getElementById("DropDownList1").value;
if ((window.opener != null) && (!window.opener.closed)) {
window.opener.document.getElementById("HiddenField1").value = choice;
}
window.close();
}
It fails on this line:
window.opener.document.getElementById("HiddenField1").value = choice;
Because hidden field is placed in user control and the code can't get the reference to hidden field.
Could someone help me to make it work?
If you're using window.open(), you can see into the parent window via the property window.opener, which will let you communicate between your parent page and the popup.
If you're using window.showModalDialog(), see the second answer to this question: window.opener alternatives
Try this
window.opener.document.getElementById('<%= HiddenField1.ClientID %>').value = choice;
I have a form with a table that displays data from a mysql table,it has one field that requires user input. each row also contains a div. The form then has two functions.
the first function is to display information from an external PHP page which processes the values on the input fields in each row and sends the result to the row div in the form of an result
The first function works perfectly and here is the script:
<script type="text/javascript">
function get(row){ //row being processed, defined in onchange="get(x)"
$.post ('getpeopleinjobs.php',{ //data posted to external page
postvarposition: form["position"+row].value, //variable equal to input box, sent to external page
postvarjob: form["job"+row].value, //variable equal to input box, sent to external page
postvarperson: form["person"+row].value, //variable equal to drop down list, sent to external page
postrow: row}, //variable equal row being processed, sent to external page
function(output){
$('#training'+row).html(output).show(); //display external results in row div
});
}
</script>
The second function I require help with. I need to almost repeat the same javascript function again. however instead of sending the row variables to an external page, I want to send them to a popup page. This function should be triggered when I click the in the div.
I have the below javascript for the popup.
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open( url,'popUpWindow','height=400,width=1000,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes')
}
</script>
What I want to do is send the variables to the popup page, the same variables that were sent to the external page.
so what I am aiming for is something like this:
<script type="text/javascript">
// Popup window code
function newPopup(url) {
function get(row){ //row being processed, defined in onchange="get(x)"
$.post ('trainingneeded.php',{ //my popup page
postvarposition: form["position"+row].value, //these variables must be posted to the popup page
postvarjob: form["job"+row].value, //these variables must be posted to the popup page
postvarperson: form["person"+row].value, //these variables must be posted to the popup page
postrow: row}, //these variables must be posted to the popup page
);
}
popupWindow = window.open( //open popup with the above variables posted to it
url,'popUpWindow','height=400,width=1000,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes')
}
</script>
How can I get the above to work? is using an href the best idea or can the div have an onclick event.
Thanks for the assistance in advance.
No, it's not possible to post to a popup window. You can include those variables in the url and to it as a get.
Or you can add target="_blank' to the form, and let it open a new window that way.
It won't be a popup window, but these days browsers mostly block those, or open them in tabs anyway, so it may not matter.
One other option is to open the popup with blank, and then use javascript to simply write() the page contents to it.
See also: asp.net/jQuery: post data with jQuery to a popup [IE]