how to cancel customvalidators action? - c#

I have a webform with a textbox and 3 buttons (add, save and cancel), I'm learning how to use customvalidators (ASP.NET 4.0).
Once the page is loaded, you can only see the add button, after you click on it you can see the textbox and the other 2 buttons.
If textbox is empty I can't save the record (I get this done successfully with customvalidator and javascript, it shows me the error message "textbox can not be left empty"), but what happens if I don't want to save the record anymore and want to cancel instead (by clicking on the cancel button while textbox is still empty)?
I get the customvalidator error "textbox can not be left empty". I have to type something i it so I can do what i need.
Any suggestions?
Thanks in advance

For Cancel button set the attribute CausesValidation="false". That is it...

Related

c# pass parameters from a previous action

I'm writing an application that will have a datagridview control and 4 textboxes.
One requirement for the application is that when the user double clicks a row in the datagrid, the 4 textboxes fill with the corresponding textboxes with the data -> this is already done and working. Once the user has edited the field and clicks OK, they will be saved on the datagridview.
On the other hand, if the user clicks a button called "Add Register", the same buttons will be enabled and once they click OK a new register with the data in the textboxes will be created.
The thing is that I don't know how and I have not found any information about knowing if I should edit a row (and which one) or add a new one when OK is clicked.
In other words: how can I know if I'm coming from an "edit" request or an "Add register" request when the user presses "OK"?
Thanks!
Welcome to StackOverflow.
The simplest way to achieve this is to have a boolean field on your form, e.g. bool isEdit. When the user double clicks a line in the DataGridView (a handler for which you say you have working), then set the field to true. Within the Add register button handler, set the field to false.
Now within your OK handler, you simply examine the value of the isEdit field to know, if you are adding or editing!
I have done a lot (a very great lot!) of such DataGridView forms. Personally I do not like to combine the form with data entry. I prefer to leave my DataGridView form as totally read-only, and then when the user clicks edit or add buttons, I display a separate modal form to handle the data entry. On saving from the modal form, I refresh the grid.
HTH

Show PopUp with textbox when condition is met

I have a textbox, I need to check the text entered by user using textchange event to see whether it is the one I want, if it is not, I want to display to the user a notification like the one here example
I have tried the ModalPopupExtender in Ajax, and I made a panel as the PopupControlID, and I show the ModalPopupExtender only if the condition is not matched, the problem in this solution was that the popup panel is not shown under or next the textbox like the image in the example, I could not control its position to be near the textbox to tell the user this pop up message is for this textbox.
I have tried the BalloonPopupExtender too which will solve my problem regarding the place of the popup panel, but I found another problem, I could not control the show/hide of the BalloonPopupExtender, I can't show it when the condition is not met and hide it if met.
Please I need your advices..Thanks in advance

Get the Rad button that were clicked after Post Back

I'm using telerik Grid which has a command button that adds new row/record or another command button that edits selected row/record.
Each grid is inside a twitter bootstrap tab content (Yes, I didn't use telerik tab). What is happening is that when one of buttons that I mentioned above clicked, I expect the tab that contains that button be active at page load.
So is there anyway to get that button so I can use it to activate the proper tab? (ID of that button is enough for me, I will do the rest with jQuery)
Every control that posts back, in an ASP.NET web forms world, sets the __EVENTTARGET and __EVENTARGUMENT (if there is an argument) form values. The __EVENTTARGET form variable has the client ID of the button, so that might be the optimal way. If it's within the grid, I'm not sure, but the __EVENTTARGET may either be the button or grid ID.

passing data from Ajax Modal popup extender to a textbox on the asp.net page

I have a Ajax modal popup that displays a set of options for the user. On submit button click event on the ajax modal popup, i need to pass the user selected data back to a text box on the user control (which has the modal pop up) on the calling page.
Structure/flow is as follows. There is a page and two user controls. One is a search control that has another user control that contains the user options. The master page has the search user control. When the user chooses an option in a dropdownlist in the search control, it does a mpe.Show of the user control with options. User makes his selections and hit submit button. In the button click event in the popup, i delegate an event back to the search user control which tries to set the value in one of its text boxes. Everything is going fine until this step and i can see the value but the text box never changes. It seems like the user control is already rendered and the changes are ignored. Any idea how I can get around this?
In short, how to get back the data to a control from an Ajax modal popup.
Use jquery - when the user clicks a button on the modal - use jquery to set the value field to be the data that the user has selected.
e.g.
$('#modalButton').click(function() {
var userData = $('#tbUserData').val();
$('#textBoxElsewhere').val(userData);
});
for anybody's future reference, i did a work around for this. What was happening is that, on the final button click postback, the page/parent user control load events run first and then the button click event.. so the changes that were being made in the button click event did not make it back to the parent user control on the page.. i had to add a middle step to display the user selections for approval and force the user to hit a final confirmation hit. On that post back, the changes were already available for the parent user control, and not have to wait for the button click event to trigger to grab the data. I'm sure there is a better way to do this but this is what I could come up with.

I want to make reply control on the Reply button click

I wan to create reply control for the web site in which
if user click on the Reply button then he or she get textbox and button and after clicking on that button the textbox value is insert to the DataBase
I already write one script
the script is like this
Click me!
but this script give me textbox for the 2 to 3 second and after page post back the textbox and button is disappear
so some body help if its possible
You should disable the AutoPostBack property (not sure on the name by heart) on the button which calls your script.
This way, your button will only perform it's action on client-side, and not refresh the page.

Categories