Calling a web page from a GridView select button - asp.net

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

Related

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?

Display ASP.NET Control on Event

I'm looking to create a custom date picker with code examples from several sources.
Is the code to display/hide an ASP.NET control when a user clicks a button usually done with JavaScript or ASP.NET code? By display/hide, I mean within the page not a popup window.
Please provide a simple example. (If ASP.NET, VB example preferred over C#)
The answer is, it depends. Do you want the date picker show/hide to trigger a postback and thus some code on the server, or do you want it to act purely on the client?
If you want it to act purely on the client, then, modify the markup for your button:
<asp:Button runat="server" ID="myButton" OnClientClick="ShowHideCalendar()" Text="myButton" />
<script language="javascript" type="text/javascript">
var calendarVisible = false;
function ShowHideCalendar()
{
if (calendarVisible)
{
// Code to *SHOW* calendar here
// Show the DIV it's contained in, pop the window with it in, etc..
}
else
{
// Code to *HIDE* the calendar here
}
}
</script>
The key bit is the "OnClientClick" property of the asp:Button control.
Its best practice to do such thing asynchronously, rather than having a full postback that refreshs the entire page.
That means that you have two options:
Update an UpdatePanel in which your
control is placed. That gives you
the benefit of only re-rendering the
content in the UpdatePanel.
Use
clientside scripts to toggle the
control. You also need to perform a
callback, that tells your codebehind
that you just toggled the visibility
to asure your code is in the same
state as the webpage displaying it.
I'd prefer using the second one.

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?

Can you perform an action based on a seperate window in asp.net?

I have a page of search results, and clicking one opens a new window where they edit the information about it. Once they finish, they currently have to hit "search" again to refresh the results to ensure it saved correctly (it refreshes the search results and reflects the new status).
Is there any way to trigger the page to automatically refresh (ie. automatically click the search button) based on the popup window closing or through some other means?
I echo the sentiments to do this without popup windows, but if you really need to...
I would do this with an update panel wrapped around the results and some javascript added to your save button on the popup page.
On your popup page, I guess you have a button to save your work, something like:
<asp:button id="btn_save" runat="server" OnClick="Save" Text="save" />
on the codebehind:
protected void Save(object sender, EventArgs e)
{
// save code ...
// bla bla
// Add this
ClientScript.RegisterStartupScript(this.GetType(), "save", "<script language='javascript'>updateResults();</script>
}
On the results page add this
<script language="javascript">
function updateResults()
{
__doPostBack('updatePanel_results','');
}
</script>
and wrap your results control in an update panel (in this example called updatePanel_results). In your page_load, you'll probably need to code to call your refresh resutls method.
I'd really avoid having the application flow spanning two windows if possible. Why not impliment some kind of modal dialogue when the user clicks an edit link?
Check out jQuery's modal form implimentation to see what I mean:
http://jqueryui.com/demos/dialog/#modal-form
Opening window does not look like the ideal solution here.
In the new window you have access to parent window in javascript. You can use it to fire refresh/or some other function in mail window.
Is there any way to trigger the page
to automatically refresh (ie.
automatically click the search button)
based on the popup window closing or
through some other means?
You can register a JavaScript event handler for the OnUnload event. However, in my experience it's not reliable (browser-to-browser inconsistencies, etc).
Have you considered using Ajax to keep the search results on the same page as the original window? Or maybe a small Silverlight control?

ASP.NET Refreshing one Window from another

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... :(

Resources