ASP.NET Refreshing one Window from another - asp.net

I have a page with a GridView on it that launches a popup, using Javascript. The user then selects an item, that updates the data connected to the GridView and closes the popup.
How do I refresh the first (ie the Calling page) so that I can refresh the data shown in my Gridview?

Try this inside your popup:
<script>
window.opener.location.reload()
</script>
That should refresh the page that opened the pop-up

If you simply need to trigger a postback on the calling page, this should work:
<script>
window.parent.document.forms[0].submit();
</script>
By explicitly submitting the form, you avoid the warning that appears if you just refresh the calling page.
If you need to trigger an OnSelectedIndexChanged event on the GridView during the postback, then things are a bit fiddlier, but you should be able to do it by calling window.parent.document.__doPostBack() with suitable arguments.

Here is the Solution:
Dim CloseScript As String = "<script language='javascript'>function closeWindow(){ window.opener.document.forms[0].submit();window.close();}closeWindow();</script>"
In .NET 2.0 you have to add this to the page to register above Javascript:
'register with ClientScript
'The RegisterStartupScript method is also slightly different
'from ASP.NET 1.x
Dim s As Type = Me.[GetType]()
If Not ClientScript.IsClientScriptBlockRegistered(s, "CloseScript") Then
ClientScript.RegisterClientScriptBlock(s, "CloseScript", CloseScript)
End If

Does this avoid the 'page cannot be refreshed' message
window.opener.location = window.opener.location;
(sorry I would have just left a comment on TonyB's post but I don't have enough SO points, so I'm not allowed... :(

Related

Calling a web page from a GridView select button

In an ASP.Net / VB.Net web page I would like to allow the user to Call another web page within my application passing some parameters to another page that uses these parameters as part of the DataSource "Select" statement from the "Select Button" of a GridView.
If this can be done, can you show the needed coding?
why do you need to call the web page do you want it as pop up? or you want to load the page?
ok here is it, the code tell me if it is working or not:
<script type="text/javascript">
function basicPopup()
{
popupWindow = window.open("yourpage.aspx", 'popUpWindow', 'height=300,width=600,left=100,top=30,resizable=No,scrollbars=No,toolbar=no,menubar=no,location=no,directories=no, status=No');
}
</script>
on client click of button call this function OnClientClick="basicPopup();return false;"
here is an answer i found in stackoverflow if you wish to open it as a page:
gridview select button to be a link to a page

TextBox keydown event at server side in asp.net

i have a textbox on a page, now whenever any age number is entered in that page, that page should be loaded in my datalist, i have created rest of the thing, but i am not getting how to trigger the textbox onkeydown event from asp.net, i know working with that from javascript, but the problem is i have below things done in that function:
it applies the currentpage value to the static variable from textbox
it binds the datalist
it enable disable the next previous buttons accordingly
and i dont think this i can do from javascript, anyone have any resolution, how this could be achieved from server side, onkeydown event
You can capture the keydown event in a javascript function then do a AJAX call to the server. If this does not suit you, then you could try manually do postback in javascript.
So in your textbox:
mytextBox.Attributes.Add("onkeydown", "return doDataListBind()");
Now in the javascript function:
function doDataListBind()
{
__doPostBack("myTextBox"); // etc, etc
// some other code here...
}
More info can be found here:
http://geekswithblogs.net/mnf/archive/2005/11/04/59081.aspx
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/
Try looking into or using either:
AJAX Control Toolkit, or
JQuery Autocomplete Plugin
Alternatively you could try to call _postback() function from a client side event/function for your textbox in javascript

ASP.NET / VB.NET: Reference a Textbox value without postback?

I have a child aspx page in an iFrame. There are a few textboxes, which are populated in the page load event.
There is also a LinkButton which the user clicks when s/he is finished editing the fields. There are some javascript functions and other things going on, so a full postback (ie: asp button) is out of the question.
Problem is, I need to reference the textboxes NEW values (user changes) after the linkbutton is clicked.
Is there any way to do this?
Thanks,
Jason
EDIT:
After playing with the interface a bit further, I realized the Page_Load event was firing as soon as the LinkButton was clicked. Of course this is where the data is initially loaded, so any changes the user made is immediately written over. Current plan of attack is to create an IsLoaded cookie value and check if true before the mentioned code executes. If anybody has a better idea, please let me know!
Thanks,
Jason
You can use jQuery to grab the textbox value on click of the button.
<script type="text/javascript">
$(document).ready(function() {
$('.btnSubmit').click(function(e) {
alert($("#txtName").val());
});
});
Then you may pass this textbox value to a server side method by calling it using jQuery AJAX. See the link below .
http://weblogs.asp.net/karan/archive/2010/09/12/calling-server-side-method-using-jquery-ajax.aspx
You want to access the new textbox values from the parent or from within iframe which has that webform opened?

Client script for displaying an alert is not working if I use the AsyncPostBackTrigger

I have a masterpage in my application. I'm using timer control based on the timer interval the page gets refreshed. And I don't want the whole page to get refreshed. So I'm using AsyncPostBackTrigger on the tick event of the timer. I want to display an alert/modal dialog box whenever it is triggered. I have written a client script for displaying alert/modal dialog box. The client script is not working if I use the AsyncPostBackTrigger. If I remove the trigger, then the whole page is getting refreshed. Is there any way that I can find a solution? Please help.
Try this:
var prm = Sys.WebForms.PageRequestManager.get_instance();
prm.add_endRequest(function() {
//put code here
});
http://www.asp.net/ajaxlibrary/Reference.Sys-WebForms-PageRequestManager-endRequest-Event.ashx

Ordering javascript code on a page executed with argument calculated in codebehind in ASP.NET

A situation requires me to order javascript code on a page be executed with an argument calculated in codebehind in ASP.NET
Here is the situation:
I have a page called search.aspx . This page contains a button and a textbox. Users put their arguments for search in the textbox and then click the button. The button posts back and runs a button click method. This code behind logic (running on the server) serializes and inserts the contents of the textbox to a DB.
Assuming a rowID or something to identify the serialized query by will be returned inside the button click method, how can I then tell the page (search.aspx) to open a new tab with results.aspx?query=.
I know I have to use javascript as the code behind can't open a new tab, but I am just wondering how to do so.
I've never used JS so a maximum amount of details in the answer is better.
Assuming your rowID is loaded in a variable named, well, rowID, then put this at the end of your click event (VB.Net):
ClientScript.RegisterStartupScript(me.GetType(), "results", _
string.Format("window.open('results.aspx?query={0}','Search Results','status=1')", rowID), True )
To directly answer your question, you can insert something like the following directly in the page output just before the body end tag.
<script type="text/javascript">
window.open("http://servername/pagename.aspx?queryid=blah");
</script>
by using Response.Write.
However, did you also consider simply opening a new window on the button click with the button's text passed in as a query string to an aspx page?

Resources