aspx/c# Refresh on closing popup - javascript

I have a little problem with my code.
I have an asp:Wizard element, in which I have few steps.
In one step, I click on a button that open a popup with window.open to select a datetime.
When I selected one, the popup is closing, but the datetime is not visible in my parent window (but it's there, because when I click again on my window.open it's "reloading" my page and the date is now visible)
I already tried to reload my parent's page when I close the popup with window.parent.opener.location.reload but this solution make me lose the active step of my wizard.
So what I need is a partial refresh of my page that keeps the current step.
below is the code
My opener:
var childWindow = window.open("../../Utils/CalendarPopup.aspx?DatePred=Stateme‌​‌​ntDateFrom", "", "height=280; width=285;);
childWindow.onunload = function ()
{ // Where i need to reload }
My popup:
Session[Request.Params["DatePred"]] = CalendarSelectDate.SelectedDate;
Session["CalendarPopupCanceled"] = 0;
this.ClosePage();
The data loading:
if (Session["StatementDateFrom"] != null)
{
{
(WizardProcess.FindControl("DtTxtBxStatementDateFrom") as Syncfusion.Web.UI.WebControls.Shared.DateTimeTextBox).IsNullDate = false;
(WizardProcess.FindControl("DtTxtBxStatementDateFrom") as Syncfusion.Web.UI.WebControls.Shared.DateTimeTextBox).Value = System.Convert.ToDateTime(Session["StatementDateFrom"]);
}
Session["StatementDateFrom"] = null;
}
Thanks in advance

i don't know how you wrote your code, but why you need to reload the child window. If you have a control (for example a textbox) that displays the datetime you selected from the childWindow, then you can set the control's value equal to the selected datetime. This should be easier than trying to refresh only the wizard!

Related

HtmlUnit button click not submitting

I am trying to click a button in HtmlUnit to login to a site (m.pge.com) but it is not working. The browser stays on same page. I had similar issue with another site. I tried searching but didn't get a definitive answer.
Any ideas what I might be doing wrong ?
Here is code..
Web_Client = new WebClient(BrowserVersion.CHROME);
Web_Client.getOptions().setCssEnabled(false);
Web_Client.getOptions().setThrowExceptionOnScriptError(false);
Web_Client.setJavaScriptTimeout(15000);
Web_Client.getOptions().setRedirectEnabled(true);
//Web_Client.setAjaxController(new NicelyResynchronizingAjaxController());
// load home page
HtmlPage page = Web_Client.getPage("https://m.pge.com/#login");
HtmlTextInput userName = loginForm.getFirstByXPath("//*[#id=\"usernameField\"]");
HtmlPasswordInput passWord = loginForm.getFirstByXPath("//*[#id=\"passwordField\"]");
userName.setValueAttribute(user);
passWord.setValueAttribute(password);
HtmlButton button = null;
DomNodeList<DomElement> buttonList = page.getElementsByTagName("button");
for (Iterator buttonIter = buttonList.iterator(); buttonIter.hasNext();) {
DomElement domElement = (DomElement) buttonIter.next();
if(domElement.asText().equals("SIGN IN")) {
button = (HtmlButton)domElement;
}
}
loginpage = button.click();
It is too tedious and unclear to type in comment so i type it as answer and will update with progress.
Part1: login
The first thing is that are you sure you target the button correctly and where did you initialize the HtmlPage loginpage. Normally, when you assign
loginpage = button.click();
It will get you the login page,but sometimes it is weird that it doesn't assign new page but rather change the current page. that is your
page
You may try to print it out before button click and after button click to see if this page changes? that is
System.out.println(page.asText());
button.click(); // no need to assign page, if the page changes itself
System.out.println(page.asText());
Part2: Search
When you have done input textbox and button click, you will have to target the changes element after search again and get its content, for example, if it is a element, you should probably target the element after button click and get the content you want afterwards. If you target it before button click, the content in that element won't changes itself, you need to get that again.

Firefox extension: get click data when context menu

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.

How to use JavaScript variable from popup window in code behind?

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;

How to refresh parent browser window on GridView page change

I'm using ASP.net; I have a popup browser window that contains an databound gridview with textboxes. It has an "Add to Order" button which takes the values entered and updates the database, then closes the popup and refreshes the parent. This currently works perfectly using window.opener.document.forms[0].submit();self.close(); in a RegisterScriptBlock
I now need to update the database on gridview page chage so that textbox values are not lost. I put window.opener.document.forms[0].submit(); into the PageIndexChanging event of the datagrid, but it does not refresh the parent window. Refreshing the parent window with the order lines helps the user see what they have already ordered. My update database method runs fine, just not the parent browser refresh. I also tried "window.opener.location.href = window.opener.location.href" to no avail.
Thank you in advance!
In parent aspx page write one JavaScript function
function fnReload() {
alert('hi')
window.location.href = window.location.href;
}
Protected Sub grdDisplay_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdDisplay.PageIndexChanging
Dim strScript As New StringBuilder()
Call addItems()
grdDisplay.PageIndex = e.NewPageIndex
Call search()
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "reload", "window.opener.fnReload();", true);
End Sub
Also insert on alert in fnReload() function to check that this function called or not.

how to stop reloading parent window while child window gets open

I have a form submit, where it get the values from the form and goes
to next page... here I have a hyperlink to open a child window, while
I click, it opens the child window and simultaneously it reloads the
parent window. I have a action configured to the parent window which
has a Database insert statement too.
The problem is that while I click the link it call my action
again(because of page reload), in this action I wrote if condition to
check null/empty string from the previous page form submit. since this
is the second time the action loads it looks of the fields(but
actually those fields are in my previous page form). so it take null
while checking my if condition.
Another problem is that when I solve the above problem here comes the
SQL insert statement, which is about to execute 2nd time. I dont want
this to happen or I dont want my action to execute while I open the
popup window and I want to populate the selected value from the popup
to the parent window.
code used for opening the popup
function select_reactant()
{
window.open ("SeriesTab.action?component=reactant",
"mywindow","scrollbars=1,resizable=1,width=1000,height=1000");
};
This is the place where I open the popup and want to populate the value selected from the popup to the textfiled here
<tr>
<td>reactant</td>
<td><s:textfield name="reactant" id="reactantId" readonly="true" theme="simple"/></td>
</tr>
jquery to get back the value form popup to parent window
$(window.opener.document).find('#reactantId').val(rxn);
the code inside action below is what the action that I mention at the beginning
if(Rxn!=null||!Rxn.equals("")) //Rxn is the field variable for previous page
{
//my insert statement
}
while I run I get nullpointer error since the value for Rxn is reset to null by the page reload due to popup opening done by
window.open
You can do something like this
HTML
reactant
jQuery
$(function(){
$("#anchSelectReactant").click(function(){
select_reactant();
return false;
});
});

Categories

Resources