Hi i want to assign two string values from popup window back to parent window which open the popup window.
for which i take two hidden field both in parent and child window as runat server,
and on button click event i assing these hidden field some text value
/*(Hidden field 1 ->)*/ c_value.Value = Treeview.SelectedNode.Parent.Value;
/*(Hidden field 2 ->)*/ c_text.Value = "File selected";
and on body unload event i assign these value to parent's hidden field through javascipt
(HTML)
<script>
function assgin()
{
window.opener.document.getElementById("ctl00_ContentPlaceHolder1_p_value").value = document.getElementById('c_value').value;
window.opener.document.getElementById('ctl00_ContentPlaceHolder1_p_text').value = document.getElementById('c_text').value;
</script>
<body onunload="assign()">
but when i try to get these value on parent form it is showing empty.
i not understand why these values become empty may be due to onunload event, if this is the reason then tell me on which event i assign these values to parent form .i want to assign these values before closing child window.
Maybe your problem is due to a typo of "assgin()" function. But if not, here is a small example that works for me. NOTE: you can't test this on a local disk, because in that case the browser will prevent access to window.opener for security reasons.
parent.html
<input type="button" onclick="window.open('popup.html','My Popup')" value="Open popup" />
<br/>
Result from popup: <input type="text" id="result" />
popup.html
<script>
function assign() {
window.opener.document.getElementById("result").value = document.getElementById("mystring").value;
}
</script>
<body onunload="assign()">
Enter string and close the popup: <input type="text" id="mystring" />
<body>
Related
I am building a mvc 5 application.
I have two .cshtml views.
View1 with Layout1 and View2 with Layout2.
On Layout1 under some conditions i am showing a popup like
<input type="button" id="btnpopu" value="Open Modeless popup" onclick="ShowPopup();" />
<script type="text/javascript">
ShowPopup = function () {
window.open('/Home/OpenPopup', "PopupWindow", 'width=400px,height=400px,top=150,left=250');
}
</script>
When user changes to View2 by a button click or something like that, i need the popup window to stay in place.
Means still visible on Layout2
Any suggestions ?
You should create the same popup at layout1 to layout2 onload also and send to it the specific conditions that you want, I think that the only way you can't keep state of view per request only by the same layout.
I have an ASP.Net form which looks like the following when rendered (many lines of markup removed for brevity):
<form onsubmit="document.body.style.cursor='wait';showLoader();" action="mypage.aspx">
<!-- form elements and controls -->
<input type="submit" />
</form>
In mypage.aspx.cs's Page_Load I am doing:
if(Page.IsPostBack)
{
Foo();
} else {
Bar();
}
Quux();
Without modifying the HTML page using the Chrome Dev Tools, if I submit the form it executes Bar(). But If I removed or replaced the onsubmit attribute in the form with my own, ASP.Net thinks that the page is doing a post back and executes Foo().
I find this behavior weird because the inline JS code in onsubmit does not change anything related to the form submission. Its function is only to add a loading GIF while the form is reloading. Could there be something I am missing here?
Instead of adding a submit button, try adding a regular button, and call your gif functionality from it:
<input type="button" onclick="document.body.style.cursor='wait';showLoader();" value="Click Me" />
This will not post anything, which is what you want. <input type='submit'> will always cause a postback, unless you cancel it with JavaScript.
JSFiddle: http://jsfiddle.net/0gd8t7ew/
Following the code on Angular UI, I was able to integrate the Radio & Uncheckable Radio buttons into my solution. I have 2 radio buttons, both of which can be toggled and then I have an asp:Label to display the output.
I would prefer setting the label's visibility to false in the long run but for now it is visible.
By setting the asp:Label Text property to {{radioModel || 'null'}} I can see the value of the selected radio button on the client side page and viewing the page's source. Problem is, when I post back to the server, specifically attempting to store the value in a database, I only see the {{radioModel || 'null'}} declaration, rather than the value of my selection.
I'm new to Angular but the idea seemed pretty straight forward. I just need to figure out how to retain the label control value when storing to a database.
Here is my asp.net code with the angular declaration within the label.
<div ng-controller="EmployeeTypeChoiceRadios">
<div class="btn-group">
<label class="btn btn-primary" ng-model="radioModel" btn-radio="'Employee'">Employee</label>
<label class="btn btn-primary" ng-model="radioModel" btn-radio="'Contractor'">Contractor</label>
<!-- Pull Results from this label on form submit -->
<asp:Label ID="EmployeeTypeChoiceLabel" runat="server" Visible="false" Text="{{radioModel || 'null'}}" />
</div>
</div>
Here is how I have my JavaScript set up. I think this has more to do with the default radio selection however
// New Form - Employee Type Employee/Contractor - Radio Button
var EmployeeTypeChoiceRadios = function ($scope) {
$scope.radioModel = 'Employee';
$scope.checkModel = {
employee: true,
contractor: false
};
};
Finally, here is how I am collecting the label's data - Really just adding to a stored procedure parameter.
newformsqlCmd.Parameters.AddWithValue("#empEmpType", EmployeeTypeChoiceLabel.Text); // Employee Type choice
For the record, I've also tried basic HTML inputs (Labels) and to get their values like this..
BasicHtmlInputLabel.Value
I appreciate it in advance.
ngModel is only supported on the following elements:
input
text
checkbox
radio
number
email
url
date
dateTimeLocal
time
month
week
select
textarea
Using one of them instead of a label should solve the problem.
I am trying to open a new window with same session as the current one. I wrote some code below but its no luck yet.
For example lets say i have a form with a label (Name), textbox (where the text goes in)
and a button when pressed takes me to a new window.
If i press the button it should open a new window with the same form elements and text in the textbox if it was put in before.
Also please note the new window must be opened as a new tab in the browser with the same state and same elements as in the previous browsers.
Anyone got an idea on this (using razor view engine or jquery/javascript) ? Thanks in advance.
<label for="Name">Name</label>
<input type="textbox" value="nothing" id="text" />
<input type="button" value="press me" id="submitButton" />
$(document).ready(function()
{
$('#submitButton').click(function()
{
var currentUrl=document.URL;
window.open(currentUrl,"newWindow",300);
event.preventDefault();
});
});
You may be able to accomplish this by using modals instead of popup windows. Jquery UI has built in modal support: http://jqueryui.com/dialog/
The advantage to this approach is that no data needs to be passed into a separate page. Your modal code would look something like this, with jQuery Dialog. This would go on the same page as your initial inputs:
<div id="dialog" title="Basic dialog">
<input type="text" id="popupText" name="popupText" />
</div>
and your click event would modified update the modal input and show the modal:
$(document).ready(function(event)
{
$('#submitButton').click(function()
{
$("#popupText").val($("#text").val());
$("#dialog").dialog();
event.preventDefault();
});
});
This could definitely be cleaned up but I believe it'll do what you need pretty simply. The dialog can contain any html elements, so you can add a separate form if necessary.
Here is what I need to do (in ASP.NET):
Solution A, Project A, Page A will have a textbox and a link that opens up another page. This other page is part of Solution B, Project B, Page B. Page B will have a textbox and a submit button. When you click submit it will close the window returning to Page A placing the text that was in the textbox on Page B into another textbox on Page A.
I could probably store the value of the textbox into SQL Server and then retrieve it, but I was hoping there was another, better way.
Any help will be extremely helpful, thanks.
Using the following: ASP.NET, C#, JavaScript, jQuery, SQL Server, HTML, CSS, etc.
What if you use a jQuery modal window to display Page B and have a trigger within page B to send the data back to the element on page A
Page A:
<div id="page_a">
<form>
<input name="page_a_box" id="page_a_box">
</form>
</div>
<div id="container_for_page_b">
</div>
<script>
$.ajax({
url: 'page_b.asp'
,cache: false
,dataType: 'html'
,success: function(data){
// fill the container with html data
$('#container_for_page_b').html(data);
// invoke jQuery UI's dialogue window
$('#container_for_page_b').dialog();
}
});
</script>
Page B:
<div id="page_b">
<form onSubmit="$('#page_a_box').val($('#page_b_box').val()); $('#container_for_page_b').dialog('destroy');">
<input name="page_b_box" id="page_b_box">
<input type="submit" value="submit">
</form>
</div>
Check this out for more ideas:
http://jqueryui.com/dialog/#modal-form
I think you can easily achieve this by using query parameter's.
On Page B, during the Click event of the button, set a Session variable:
Session["TextBoxB"] = textBoxB.Text;
and then on Load in Page A, add the code to look for it:
if (Session["TextBoxB"] != null)
{
// it has a value so use it
textBoxA.Text = Session["TextBoxB"];
}