Back Button for "Previous Page" - google-app-maker

Is there a way to set the onClick to return to the previous page, rather than a specific page?
I have a print friendly page that is linked to by multiple pages. It would be nice if when users click "Back" they are returned to the page they just came from.

Absolutely, here is a function that you can add to your client script file and call from any widget event handler:
/**
* Navigates user to a previous page.
*/
function goBack() {
window.history.back();
}

Related

Best way to access controls on parent page from a child page popup?

I have a parent ASP.NET page which has a link that opens a child ASPX page in the form of a popup.
I need to control the parent page from the popup page's code-behind. For example enablie/disable the visibility of a label in the parent page, or setting text value for a text box.
How can I accomplish this?
Code used to open the popup ASPX:
//JavaScript function:
function showPopup()
{
var strReturn = window.open("TaxReportInputsForm.aspx",'popup','width=390,height=120');
}
Button code:
Page.ClientScript.RegisterStartupScript(GetType(), "popup", "showPopup();", true);
The problem that you have is that HTTP is stateless and so each HTTP request/page is handled entirely independently - this means that there is no way to directly modify what is rendered on the parent page while processing a request from the child page.
What you can do however is indirectly modify what is rendered by having the child write out some flags/information to some place that both the child and the parent page can access, and then having the parent page look at that information to determine what to render. There are loads of different places that you could store this state, e.g.
Cookies
Session variables (i.e. in memory on the server)
In a hidden field / query string in the page
For example, your child page might write a ShowSomeLabel flag to a cookie in the code-behind, then when the child page returns to the client it forces a refresh of the parent page, then in the code-behind for the parent page it can read that flag from the cookie to determine what labels should be visible.
All of these methods will require at least some JavaScript to cause of refresh of the parent page, however some will need additional JavaScript to copy hidden field / query string values from the child page to the parent page before it submits. Exactly where and how you should store this information depends on your specific requirements.
you can try to use javascript,
suppose A.aspx is parent page and B.aspx is the open page,
you can use "opener" to contronl DOM of A.aspx.
A.aspx link tag and javascript :
open page B
<script type="text/javascript">
function fun_A() {
alert("hello");
}
</script>
B.aspx
<input id="btnChild" type="button" value="call function in Page A" onclick="opener.fun_A();" />
when you open B.aspx from A.aspx, and click the button from B.aspx,
you will see A.aspx alert message "hello".
hope this can help you.

jQUery Mobile - how can I pass back values on dialog close?

I have a form page that opens a dialog in order to enter new information. I open the dialog in the "standard" jQM way:
Open dialog
What I need to do is pass back some of the values that were entered so that I can update the page with those values. How do I do that?
As an added bonus, I also really need to be able to submit the values. It seems like jQuery Mobile is setup close the page on any link click. This is an ASP.NET application, and so I need for the page to last long enough to hit the Button_Click() event in the code behind.
Here's the pieces you need:
Html in the dialog:
Cancel
Submit
In pagecreate:
$("#btnSave", pagediv).live('click', function () {
var s = page.Model;
s.serverName = $("#txtName", pagediv).val();
s.Save(function () {
$('.ui-dialog').dialog('close');
});
});
s.Save is a function that writes to the datastore, updates a global model object that is accessible to all pages, then calls the callback function.
In the pageshow handler for the parent page, update the controls from the model. You can't update the parent page directly from the dialog as the parent page may not exist at that point - if data-dom-cache isn't set, it will be removed as soon as the dialog is displayed and will not be recreated until you call close.

is there any method for know on which hyperlink user has clicked in asp.net?

hi actually i want to store value that has been clicked by user on web page for instance.
suppose this is my web page content of list
**
**google.com**
**yahoo.com**
**facebook login**
**stackoverflow.com**
**
now suppose user click on facebook login
then how to know that user has clicked on facebook login actually i want to keep record for further processing.
Abatischev's suggestion will work, but there's an easier method that doesn't involve making AJAX calls if you don't want to go through the hassle.
Instead of having the link go directly to the page that you're linking to, you should have it submit to your asp.net page. You can then record the click there before redirecting to the destination page.
Client-side way:
Before finish the page render, add programmatically onclick event to each hyperlink, call on click an async JavaScript script to record url
Server-side way: (extending #Justin's answer)
<asp:LinkButton runat="server" OnClick="urlGoogle_Click">google.com</asp:LinkButton>
protected void urlGoogle_Click(object sender, EventArgs e)
{
DataBase.Record("google.com");
this.Response.Redirect("http://google.com");
}

How do I bind my Jquery function to a asp.net button and still allow Validation and PostBack?

Now I could be going about this the wrong way so if there is a better solution please post that as well. What I am trying to do is disable a button once it is clicked to prevent double clicks. In the past I have done my just disabling the button onclick but with webforms I am running into a little bit of a snag because there is validation on the page so I need that to fire and I need to post back.
So I have the following JQuery function to make a button disable itself on click. Here is the JQuery:
jQuery.fn.disableOnClick =
function()
{
return this.each(function()
{
$(this).click(function()
{
$(this).attr('disabled', 'disabled');
return true;
})
})
};
Intended usage would be:
$(document).ready(function()
{
$("#<%= btnSomeButton.ClientID %>").disableOnClick ();
});
This doesn't work... the button always disables, the validation is ignored and the postback doesn't even happen. I would assume because I am overwrittin the click handler. Suggestions?
UPDATE: I have tried just a basic function that is connected to the 'OnClientClick' of the button to do:
// In my Page_Load
btnSomeButton.OnClientClick = "return DisableButton('" + btnSomeButton.ClientID + "');";
// Javascript function
function DisableButton(id)
{
var bButton = $("#" + id);
if (Page_ClientValidate())
{
$("#" + id).attr('disabled', 'disabled');
__doPostBack(id, '');
}
}
This works as expected in a non master page setup but when I try to use it with a page that has a master page, the postback occurs and the Page_Load fires but the button click handler never gets called. It's like the __doPostBack is not sending which control event to fire correctly.
Any suggestions for changes or even a whole different approach?
One idea for a different approach (disclaimer: this is not a fully baked solution) is to go from the submit action of the form instead of the click handler of the button.
The validation all happens through the submit handler of the form. If everything checks out, the form is allowed to submit. If you could hook into that process, then when the form started to submit for real, you could find all buttons with the class DisableOnSubmit and disable them.
Validation could take some time, however, and some people (annoyingly) seem to like to double-click on web forms, so it might be best to blend the approaches. Disable the button immediately with a click handler, then if validation fails, re-enable the buttons that were disabled.
EDIT In response to comments
This description could be turned to be more like the signature in the question (where any button could be made to be click-once regardless of its CSS classes).
Create a jQuery extender where the buttons that fit the selector are given an onClick handler and (if not already done) the hook is added to the validation being complete. The onClick handler adds the clicked button to a collection of "currently in click evaluation" buttons. If validation succeeds, the form submits normally. If validation fails, the buttons in the collection are re-enabled and removed from the collection.
For the evil update panels, you might want to look into specifying these events with live bindings (used to be a plugin, but I think it's now part of the jQuery core depending on which version you're using) so that the event handlers are reregistered when the partial postbacks complete.
I get the feeling you can use GetPostBackEventReference to do the actual postback once you've done your validation dance.
Edit Oops, forgot the other half of the answer :-)
As for the double postback, I've used Postback Ritalin by Dave Ward in the past to curtail those pesky hyperactive users.
Add this to your startup code (ready event handler):
var elemButton = $('#<%= Button1.ClientID %>');
var fnExistingHandler = elemButton[0].onclick;
elemButton[0].onclick = function()
{
fnExistingHandler();
if (!Page_BlockSubmit)
{
$(this)
.hide()
.after('<input type="button" value="Please Wait..." disabled="disabled" />');
}
};
Basically you append new code to existing click handler. Note checking global variable Page_BlockSubmit.
Instead of disabling submit button you can hide it and immediately insert disabled button in its place. Because this happens very quickly it will look as button becoming disabled to the user. Details are at the blog of Josh Stodola.
Edit: fixed client validation.
Haven't tried it but what about something like this:
$("input[type=submit]").live("click", function() {
$(this).hide().clone().insertAfter(this).show().attr("disabled", "disabled").val("Please wait...");
return true;
});
This will ensure a submit button isn't disabled which ASP.NET doesn't like.

How do I stop a ModalPopupExtender from displaying?

I have a web service that validates some form data. The service is a ScriptService, and I am calling it from the client. I need to display a modal popup if the validation fails. If the user clicks "OK" on the modal popup, then I want to post back and save my data. "Cancel" should allow them to close the modal popup and let the user correct data, allowing one to resubmit. Currently, the modal popup displays every time regardless of the result of the validation.
I tried calling hide() and returning false, but neither worked.
I tried approaching this problem from a different perspective by assigning the TargetControlID property of the modalpopupextender to a hidden button and then calling show() on the modal popup if validation failed, but this did not cancel the postback. The modalpopup displays for approximately one second and the page posts back.
So you want to do something like:
function ValidateInput() {
MyScriptService.ValidateInput({however you are passing form data}, OnValidateComplete);
}
function OnValidateComplete(response) {
if ({response is bad}) {
$find('<%= ModalPopupExtender.ClientID %>').show();
}
}
You can then keep your TargetControlID, OnOkScript, etc. all the same. Perhaps with some code we can actually see what you are doing.

Resources