How do I send data to another screen after selection - c#

I have a page where If you click a link, e.g. 'search' it will open a search page and you can then select an item from the gridview to use in the previous (parent) page.
I was wondering how I would go about sending back the information to the parent page and then refresh the parent page to fill in the other data?
I am guessing it will be some kind of javascript dynamically created in the code behind?

window.opener is the window that opened the current window.
So, if you popup a temporary window from some page, you can use window.opener from the popup window to reference the previous page objects or global variables in that page to put data back into the parent window.
Most web apps these days avoid popups because of the various popup restrictions in browsers. Instead, folks tend to use overlays in the same window which don't run afoul of popup blockers.
For example, from the popup window, you could do something like this:
window.opener.document.getElementById("result") = myHTML;
or:
window.opener.searchData.choice = "foo";
or:
window.opener.myFunc(data);

Use popup div showed when u change the value of the input , the necessary 2 steps : sending ajax data and receiving the data in the same page

The best way that I see is calling parent function from opener
I don't know which html has your popup page but maybe something like this:
//child
...
<table>
<tr>
<td>item 100</td> <td><input type="button" id="searchResult100" onclick="updateParent(100)"></td>
</tr>
</table>
...
function updateParent(id){
if(window.opener){
window.opener.updateData(id);
window.close();
}
}
I don't know how you want to use ID that is selected on the popup, you can hide all results that have different ID or put id inside some hiddenfield and do a postback to use the ID on the code behind. Need more information about the purpose.
//parent
...
function updateData(searchId){
// use searchId to update
}

Related

Passing values from a pop up to a page and then closing pop up c#

I have a pop up window doing some database queries(pop up popped up from the Default.aspx page).Now that I have the values I want to close the pop up and send these values to the Default.aspx page.
i tried Response.redirect(Default.aspx? + myvalues here) but it is opening the page in the pop up itself.
Any help please ?
Try to use Hidden value which store values hiddenly and again you can use it.
use it <asp:HiddenField runat="server"/> and store value in it from code behind
Opening and closing a popup is a client side event. After you have got your values from Db, you can simply close the popup using window.close(); and then open the the Default.aspx using window.location.href="Default.aspx? + myvalues;
Sorry, you cant to that purely in c# because popup are created on client, you will have to use java script. After your work is finished with the popup window get reference to the window that ipened it by checking the property 'window.opener'. have a look here Passing data between a parent window and a child popup window with jQuery and still you have any doubt ask it again. hope this helps.

Popup windows to select items on ASP.NET

I am new to the ASP.NET world and I need to do a popup to select some data.
The idea is that the user can select one or more options with a CheckBox. When he presses a button a popup appears with a list of options loaded from the database.
I don't know how to create a popup with those options and receive the selected options when the popup close. But I know how to do the option list from the database with a repeater.
there is no such popup control in ASP.NET.
However there are numerous 3rd party plugins, which provide popup controls.
ajax tool kit model popup extender
jquery built popups
you can create your own. popup is nothing but a hidden container, which appears upon some action, and whose location and background is as per your choice.
create a popup like this:
<div class="parent">
<div class="popup">
</div>
</div>
<input type="button" value="popup" id="btnpopup" />
and css
.parent
{
position:relative;
background-color:#CCCCCC;
width:200px;
height:200px;
}
.popup
{
width:50%;
height:50%;
position:relative;
top:20%;
left:20%;
background-color:#DDDDDD;
display:none;
}
and jQuery code
$('#btnpopup').click(function(){
$('.popup').toggle(200);
});
see this fiddle
You can use the OnClientClick of the button to open the popup. Depending on it being a normal browser popup or a jQuery dialog you have two general options:
Standard Popup
Standard popups open as if they are a separate page. When you click OK you may have to store the selection into the user's session if the data is needed on the page that triggered the popup, or store it directly in the database. If the former is the case, when you return to the page and submit it, the data from the popup will be available in the session to process.
jQuery Dialog or particularly any js-triggered html dialog. You can show it with the corresponding js again in the OnClientClick function, and perform the selection. On the OK button click of the dialog almost nothing is needed (except hiding it). Since the dialog input controls are part of the page, they will be posted on submit and be process-able on the server.
That's basically all you need to do, but some more reading on the topic won't hurt. Good luck.

How to pass values from an asp.net child page to the parent page

I have two web pages, Page1 and Page2, which can both open the same child popup page.
If the parent page is Page1 I want certain input from the Child page to returned to the parent page and if the parent page is Page2 I want other information to be returned.
I do identify who is the parent page and how do I return the input to it and have it show in the proper text box or DroDownList?
I tried using Request.UrlReferrer putting results in a string variable and I got an error 'object not set to an instance'.
As both the pages can be parent , write the a javascript function that works as receiver on both the page and write code in it as per your requirement.
e.g.
javascript on Parent page:
SetDataFromPopup(data)
{
document.getElementById('TextBox1ClientId').value = data;
}
On popup write the following line
window.opener.SetDataFromPopup(data);
this should be called on the event where you want to pass the data e.g. suppose you have a button on client click of it you want to pass the data , the code should look like:
<input id="btnSave" type="submit" onclick="window.opener.SetDataFromPopup(data);" >Save</input>

return PartialView to a popup windows at another view

I have an Index.aspx with a button inside which that button will call a controller, doing some logic and returning to a PartialView control - let's named it PopUpPartialView.ascx (as a popup). So to make it clear, the popup windows(PopUpPartialView) actually stays ON the top of Index.aspx when user clicks on the button.
In PopUpPartialView.ascx, there is another button, that returns say a GenerateList and now the problem is - how do I pass the thing back to the same popup windows in PopUpPartialView.ascx on the top of Index.aspx as it was before? How should my controller codes look like?
Here's what I have on the return:
return PartialView("PopUpPartialView", GenerateList);
this clearly NOT working as what I want, because it doesn't point back to Index page. I was thinking perhaps to use ajax so that I could stay on that popup ascx page. Confused~~ Someone please guide me.
Thanks.
My advice is to use a plugin which handles all the popup plumbing for you.
My poison of choice is jqModal.
It's very easy to work with - essentially a hidden container on the page, and you can load contents in there either on the initial render, or on a click event via AJAX.
So in your example, you could handle the button event click, show the dialog and load the contents of your partial view into the hidden container.

Any way we can passing a value from one page to another page (from difference window)?

Just wondering will it be possible to passing a value from one page (window browser 1) to another page (window browser 2) without reloading the page?
Example:
I have a page called test1.aspx, and inside this page with a button, when user clicked on this button, this will pop-up a new browser by displaying test2.aspx.
Inside test2.aspx will contain some data and when user clicked on the 'close' button there, it will passing the value back to test1.aspx without reload the page for test1.aspx (by fill in all data from test2.aspx into the fields in test.aspx).
Does anyone know will it possible? also any way I can find out some example? Thanks.
Yes you can do this by using AJAX and JQuery.
From the POP-UP window you can store the value in the Session variable, You have to do some code of Jquery when POP-UP Window is closed and then reload the particular portion in your page using AJAX. This is how you can do this.
You need to search the Jquery using which you can get the event of closing the POP-UP Window.

Categories