I have the following situation:
I coded a aspx app c#, the user has 4 dropdownlists, one textbox and two buttons (cancel, save) in a page. I need the user to be remembered to save any changes to the textbox before allowing him to change the index of any dropdownlist. So, if the user changes the textbox value, he only have the option to cancel or save those chhanges. If he tries to do something else, like changing the index of a dropdownlist, I need to cancel this event and give him a message to save or cancel before do this.
I've tried many ways, but they all seem amatours to me and give lots of colateral efects. Is there any decent/elegant way to do this?
Create a custom validator for the TextBox. In the DropDownList's SelectedIndexChanged event handlers check the status of the TextBox and set the validator's args.IsValid property appropriately - you can notify the user via the TextBox CustomValidator ErrorMessage property to click Save if the value of the TextBox has changed.
Related
I have a textbox called 'Value' (among other textboxes) on an ASP page. I have an event handler hooked up to the textbox so that when the textbox contents are changed, the event handler runs (control.textchanged event)
I have another command button ('Save') which saves the textbox value to the database and then calls window.close() via javascript. The problem is that when the textbox is changed and the user clicks on the 'Save' button without clicking off the textbox, the value is somehow saved in the database but the javascript does not run. Then, the user will think the value did not save because the window did not automatically close, and when they click 'save' again, the value in the textbox saves for a second time and then the javascript runs which closes the window.
It is very similar to this issue (http://forums.asp.net/t/523981.aspx?Pending+Postback+Troubles) but i do not understand the solution provided there.
Can anyone provide a method which may prevent the record being created twice in this instance?
Thanks,
c
I have many (around 20 - 30) NumericUpDown controls, that i have added in to user control and they are associated with their appropriate textboxes. These NumericUpDown controls work fine and allow me to adjust the numbers in the textboxes. However, I need to be able to calculate a quantity if items as user changes text box value (withour post back) and need to set it on a label/textbox on the webpage. My problem is that I can't find an event or another way to do those calculations when either the NumericUpDown control is pressed or when the textbox value changes. I've tried:
Using an event of the NumericUpDown control but it seems there are no events that fire when the value is changed
Using the OnTextChanged event of the textbox control, but that will not fire it seems, even when I have the AutoPostback property set to true
Calling a javascript function in the onchange event of the textbox control, but it seems that the onchange event is not called unless the textbox loses focus. The only way the user can change the value is through the NumericUpDown control and thus the textbox never has focus so this event is never fired.
Does anyone have any advice to get this to work? Just a note, I do have this contained in an update panel because I don't want a full page postback when a value in my NumericUpDown control is changed and the percentages are calculated.
Thanks ...
Via this: http://www.asp.net/ajaxlibrary/act_NumericUpDown.ashx
It has a currentChanged event that you can add an event handler for. You can also add an event handler on the textbox, using onblur (when it loses focus) or keypress (as the user types a key). Both event handlers are necessary.
To add the event handler for the AJAX control toolkit control, you add the name of the method to the OnClientCurrentChanged property on the control, or similarly named.
I have a button on my page and and few textboxes which alters their context on page_load event. when I open the page for the first time it loads random data from a database to textboxes with a function in pageload and also I create those textboxes dynamically. what I want is to make some changes on textboxes texts and click the button than send new context of textboxes to database. But when I click on button, PageLoad event fires again and It regenerates the textboxes and the context of them alter naturally since they are newly created textboxes. I tried to use "if(!Page.isPostBack)" in pageload but then the textboxes and related objects are not being created and they become null.
how can I overcome this problem?
best thing I can think of is to find some way to fire buttons click event without firing PageLoad event, but I dont know how can I do it.
any help would be appreciated;)
From Comments
Can you regenerate the Textbox on each Page load Execution? and data assignment to these Textbox should be under !Page.IsPostback. All you have to do is to keep the IDs of the Textbox in ViewState only first time page load and next regeneration of Textbox will have the previous stored ID and you also have to store the ID corresponding data in ViewState. Makes sense?
I would like to like to trigger a postback after user selects a date. Am using the AjaxControlToolkit's CalendarExtender control. The date textbox which is associated to the extender is editable too which enables the user to manually enter the date in a particular format. Values of quite a few controls which reside on that page are to be updated depending on the newly selected date and hence going to the server is a must.
I did try using the OnClientDateSelectionChanged property of the extender which lets me hook in my custom javascript, using which i was planning to trigger a postback but for some odd reason the function gets called only if the date is selected using an extender and not when manually edited (Hoping that it doesn't catch the click event over textbox's change).
Am sure many have tackled this issue before. Please do share. Thanks.
Here it is, Keep It Simple as they say. Set AutoPostBack of the text box to true and capture the OnTextChanged event on the server side.
I have a listbox which acts as a list of items. If you click on some item, it's contents are shown in the panel on the right (few textboxes etc.).
I need to have a validation on these controls as all of them are required fields. And I do have it. The problem is that, even when the validators are not valid, user can click the listbox and change active index (that doesn't have impact on the panel on the right, as SelectedIndexChanged isn't fired).
The validators are standard RequiredFieldValidator with their Display property set to "Dynamic". So, what I want is to disallow the user clicking on the listbox and changing the index untill all validators are Valid.
What would be your solution for that? Is that even possible?
Did you try setting ListBox.Enabled = false when you actually do fire off the SelectedIndexChanged, and reenabling when your required fields meet the Page.IsValid requirement to proceed in code execution?