I have 10 textboxes in Company page. 5 of them are common in Location page.
My goal is to ask user if he wants to update just company page or even location page. If the user changes 5 textboxes
that are common in Location Page, the popup shows as "Do you want to update Location Page as well" or if the user changes the other 5, then popup shows
"Do you want to save?"
How do we determine what textboxs are changed and which popup should be shown?? Could someone help me out. Thanks all :)
One of the methods is:
install jquery (just for easier access to controls)
assign a className like class='common' to the first set of textboxes
assign another className like class='other' to the second set of textboxes
handle onblur event for 'commons':
$(":input.common").blur(function() {
if ($(this).data("changed") && confirm("Do you want to update Location Page as well?")) {
// TODO: perform update
}
}).keydown(function(e) {
$(this).data("changed", true);
}).focus(function(e) {
$(this).data("changed", false);
});
handle onblur event for 'others':
$(":input.other").blur(function() {
if ($(this).data("changed") && confirm("Do you want to save?")) {
// TODO: perform save
}
}).keydown(function(e) {
$(this).data("changed", true);
}).focus(function(e) {
$(this).data("changed", false);
});
Got an idea?
Related
I want the user to click a button to add a row on my page before they post the form info.
Basically there is a button on the page which adds a string line to a div, and i want to make sure they've clicked this button at least once. If they have they can successfully post, if not i want to display an error message saying the div must have at least 1 item inside of it
Im not sure how to approach solving this issue. Should i use jQuery? Is there a way to do this with DataAnnotations
jQuery seems like a good fit for this:
/* Lets declare a global boolean variable to hold the status of having at least one item in the div */
var rowAdded = false;
// listen for the add-row click. When clicked, toggle rowAdded.
$('button').click(function() {
rowAdded = true;
});
// listen for the form submission and check rowAdded before sending the form.
$('#submit').click(function() {
if(rowAdded){
// submit the form
} else {
// user has not added a string row to the div, prompt them to add a row.
// prompt method 1, use alert()
alert('Please add a row before submitting this form.');
// prompt method 2, print string to the dom
var promptString = 'Please add a row before submitting this form.';
$('#prompt-div').append('<p>' + promptString + '</p>');
}
});
Will users know what to do?
Can you not just add a checkbox that indicates: [] check this to add a row, then a button to submit?
you can simply hide the submit button (or disable it) and show only the button to add that row and when it's clicked show the submit button
I have 2 webpages. In the 1st i hv 2 radiobuttons with images and a button. In the second aspx page i hv 2 divs. On selection of a radiobutton a particular div must be visible in second webpage and othr should hide. Am confused on how to work with these 2 webpages. Any suggestions ll be helpful.
You could just redirect to the second page passing a query string value indicating the 'state' the page should be in; for example, when your button is pressed and you've done processing everything else, do something like this:
Response.Redirect("/your/other/page?key=" + (myRadioButton.Checked ? "1" : "0"))
Then on your second page you can do something like this:
if (!string.IsNullOrEmpty(Request.QueryString["key"])) {
if (Request.QueryString["key"] == "0") {
// don't show some stuff
} else if (Request.QueryString["key"] == "1") {
// show some stuff
}
}
Store the radiobutton selection in some appropriate place and then on Page_Load read selection and hide div respectively.
I have an asp.net page which loads and writes values from a record to the controls on the page.
There is a link to another page and a save button.
If the user clicks save, fine, the changes are saved and they can navigate to wherever.
If they dont click save and click the link, any changes are lost.
Is there a way to check if the save has been clicked while the user has that page loaded?
I'm thinking along the lines of an OnClick Javascript function for the link such as -below, I'm not sure though how to test for the save button being clicked - can anyone point me in the right direction?
function handleHyperLinkClick(hyperlink)
{
confirm("You have not clicked save, any changes will be lost - click cancel then save your changes or ok to continue");
}
Add a bool variable, that is default false, set to true if the button has been clicked. Then check the value if user leaves the page.
You can do using hidden field. when user click on save button then set hidden field value.
You have to keep a temporary variable in javascript like state;
`
var state = 0;
//your function calls here
function yourFunction()
{
//// your coding
state =1;
//// your coding
}
`
In this case, you have to submit the value or navigate to other page when state=1, otherwise you shouldnt. This flag to be checked whilst clicking link (if its navigating via function) or onBeforeUnload event for page.
Please correct me know if you are looking for something other.
You can attach some value to a variable when the button is clicked. Then when the user tries to navigate, check whether that variable has that value. If so, it has been clicked, else not:
button = document.getElementById("button");
button.onclick = function() { clicked = true; }
document.getElementById("link").onclick = function() { if (!clicked) { alert("Sure?"); }
Assuming you are using ASP.NET server buttons like this:
<asp:Button runat="server" id="someButtonId" Click="someClickHandler" Text="Continue" />
If I were you, I would use jQuery to dynamically bind the click event of the button like this:
$(document).ready(function() {
$("input[type=button][id$=someButtonId]").on("click", function(e) {
if(!confirm("You have not clicked save, any changes will be lost - click cancel then save your changes or ok to continue"))
{
e.preventDefault()
}
});
});
Hope this helps.
I have a repeater and inside the repeater I have a textbox and button (together in an ASCX). The textbox is pre-populated with hint text, which is cleared on focus.
My issue is that if the when one textbox is filled by the user, and the user clicks the submit button, the hint text gets submitted inside the other controls.
I tried to do custom validation, but the validator tries to validate all the controls inside the repeater, and the other controls still contain the hint text, if it was not touched.
Since this is as ASCX, I don't want to go with a server-side solution that would force me to change the code of the ItemDataBound event of the page hosting the control.
Are there any client-side solutions or server-side solutions I can still keep encapsulated inside my ASCX?
If you are using public properties to pass the data out of the ASCX to the parent page for processing, you could account for the ghost text there...
public property TextValue
{
get
{
if (Textbox.Text != "Ghost Text")
{
return Textbox.Text;
}
}
}
For client side, you could bind to the click event of the button and clear the text if it matches the ghost text value...
$(function() {
$('#btnSubmit').click(function() {
var txt = $(this).siblings('txtValue');
if (txt.val() == 'Please Enter Your Name')
txt.val('');
});
})
You could register the script from your ASCX using a ScriptManager.
I am developing a web application where I am using a GridView control to load data from the database.
I have a row that is loaded in editable mode. I have a save button which the user clicks after making the changes, and I want to check the IsDirty flag to stop the user from saving and notify them via an alert box. I'm using a Web User Control (ASCX) to load the GridView. How can I check dirty rows in the grid and stop the user from saving when user clicks the save button or logout button??
P.S. I am using a LoginView for the logout button.
You need to handle the OnRowUpdating event in your grid, for example:
<asp:GridView id="a" runat="server" OnRowUpdating="a_rowUpdating" ... />
In code behind:
protected void a_rowUpdating (object sender, GridViewUpdateEventArgs e)
{
//Add logic appropriately to know whether you should allow the update or not.
//If you shouldn't, just set e.Cancel=true as below:
e.Cancel=true;//will stop from updating.
}
You have access to the Old and New values in the GridViewUpdateEventArgs object. For more details and sample code, check here.
I use a simple JS method to check for a variety of changes in ASP.net pages. I added it to a JS filer called CheckDirty.js and added a link to it on the page, in the file is this code:
var checkDirty = true;
var form_clean;
//this should be called when the save button is clicked, but prior to the page post
function onSave() {
checkDirty = false;
}
// serialize clean form
$(function () {
form_clean = $("form").serialize();
});
window.onbeforeunload = function (e) {
if (checkDirty) {
var form_dirty = $("form").serialize();
if (form_clean != form_dirty) {
return 'Your changes will be lost';
}
}
};
This will also work for changes to a gridview and will alert the user. I find this method best because it works with everything and I don't need to keep writing different methods for different controls.