Conditional popup box in vb.net & asp.net - asp.net

I'm working on a piece of code at the moment that allows the user to enter values into fields. Once the user clicks on the 'save' button I am checking those fields against certain conditions (essentially calling a bunch of stored procedures to assess the values). If any of these 'rules' are met, I need to generate a popup that informs the user that certain values need to be fixed before they can continue for some of the conditions, and for others just to inform them of what conditions may need their attention.
The main thing I need help with is, how do I generate a popup box in my codebehind if the conditions are met?

While not a true popup, one option would be to use a CustomValidator to accomplish this along with the AJAX ModalPopupExtender. Server side you can do whatever you need to test validation rules and display a message to the user. I personally would prefer this over a popup window.
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ModalPopup/ModalPopup.aspx
The following article hits on this in more depth:
http://ashishware.com/ASPValid.shtml

Related

Asp.net controls losses the value

I am using two tabs in my page like the attached image.
.
Here, after selecting the value in all dropdownlist controls then, i click the generate button. so, the tab is moved from parameter to report. Then again i click the parameter tab. At this time all my dropdown controls shows null value.
but I want all the dropdown values which i selected before.
how can i get the dropdown control values?
It's important to remember that web pages like this are stateless. One request won't remember anything about another request.
So in your situation, you're putting in data, then it sounds like you're clicking a link (or button) that redirects you to another page, then you try and go back to the first one, and it has to fire off yet another request, with no knowledge of the first one's state.
Given that, it seems like you have two primary options (and dozens of others that I won't bother mentioning):
Move the tabs to be on the same page. (My recommendation)
There are lots of controls out there, or you could easily write one yourself, that don't separate tab pages via multiple requests. If you did that, switching tabs wouldn't lose the data.
Add a "save" button, and disable the other tab.
This way, the user actively has to save the data before being able to leave the page via another tab. The biggest issue here comes in the form of usability.
Which one of those you choose is dependent on a number of factors, not the least of which being code maintainability and the size of requests.

ASP.NET Validate all validators with different validation groups

I'm writing an ASP.NET page and trying to get validation working. My problem is that I've got a repeater that contains several custom grid controls, each of which has validators and a validation summary.
At first, I didn't assign any validation groups, but this ended up making validation summaries appear for every grid whenever there was an error in one (because the validation summary's validation group was not set, I suppose, which meant it captured all validation errors).
So I assigned a separate validation group for each grid, unique with respect to a certain property on the control. But I have a button at the bottom of the page (with no validation group) that needs to validate the input. Not having a validation group, it won't automatically validate the grids' validators, so I added a click handler that calls Page_ClientValidate(). No dice--validation appears everywhere.
Okay, so I iterate through the validation groups and call Page_ClientValidate(validationGroup) on each if it has any validators. Works fine when only one grid has validators, but when two or more do, it automatically hides all validation summaries but the last one checked. Is there any way to disable this behavior, or a better way to do this entirely?
If I need to, I guess I can go through and unhide the other validation summaries once I've finished iteratively validating (although that might possibly have other implications), but I'd also need to unhide the validator displays (I'm using an image to denote invalid fields). It seems like such an annoying and possibly fragile solution.
EDIT: Oh, a twist. I tried doing the approach I mentioned at the end--re-showing the hidden validators/validation summaries that are invalid--but the Microsoft code prevents that, too; in the first line of the ValidatorValidate(validator, validationGroup, event) method (called by Page_ClientValidate(validationGroup) on each validator in the page), validator.isvalid is set to true, and is only set to the return value of the validation function within a conditional that only runs if the validationGroup parameter matches the validator's. The upshot being, the hidden validators all are marked as valid, making it tough to determine after the fact whether a validator is valid because it's actually valid or because Microsoft was stupid in designing the client-side validation code.

asp.net event related problem

hello friends i have a check box list which contains all the courses kept in the data base(on page load) now i want that on some event of check box list all branches corresponding to each checked box of course check box list should be list in another check box list(that is the business logic i will do my own) but the problem is that i am not finding any event where i can send all selected check box list value and can generate appropriate result, if any alternate control or solution you can suggest then please suggest me this.
Set the AutoPostBack property to true and in the SelectedIndexChanged event you can loop over the elements that are selected and then bind your second control depending on that.
Another option would be to go for an ajax solution. For this I suggest you take a look at the change event in jQuery to bind to your checkboxlist and use the ajax stack to retrieve the extra information as html and plug that into a span as innerHtml.
I think you need to clarify where your logic sits, and where the information required for that logic to work sits - in order to even know whether you're dealing with a client-side or a server-side technology question
There's two basic possibilities:
Either all required inforamtion is already in the loaded page. In that case, this is basically a javascript problem. I'd dive a bit into jQuery here which has excellent capabilities of finding elements based on properties, and manipulating them
Alternatively, some of your logic and/or data remains on the server. In that case, you can
go with the AutoPostBack property XIII mentioned, resulting, as you correctly assume, in a reload after every click.
Have the user click all the checkboxes they like, and then have them click on a "do something now" button which performs a single postback
Transmit the information about the checkbox click to the server via javascript, get a response, and select other boxes accordingly. Again, XIII already mentioned that by "ajax solution".
So I'm just trying to elaborate on what different approaches do for you, and what questions you need to answer yourself before you can proceed to a concrete technical solution.

How do you make a HTML page determine which Button to click (when you press the Enter key) without JavaScript?

I have an ASP.NET page with two sections on it... one for registration, one for login... each having a submit button.
When i'm in the login part of the page, i want the first 'submit' button to engage when 'Enter' is depressed. When in the registration part, i want the 2nd 'submit' button to engage when 'Enter is depressed.
Problem: I need the page to be accessible (i.e. i'm not allowed to use javascript)
Anyone got any ideas? :) :(
If the two submits are in different forms (and it sounds as if they should be in this instance) there is no issue. Any sane browser will take the submit button from the form you are in.
Wrap your controls in panels, then set the default button property of the panel to the desired button.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.defaultbutton.aspx
They're in the same form... :(
Well, can you not change that? Unless they share fields, they shouldn't have to be in the same form. ‘login’ and ‘register’ sound like two different functions to me.
There is no pure-HTML way to specify a default submit button, much less different default buttons in different circumstances.
Including JavaScript does not in itself make your page inaccessible. As long as it still works with JavaScript off you're fine.
This should happen automatically, as long as the two forms are actually separate forms. In other words, there should be two separate <form> elements, one for login and one for registration.
Edit:
Browsers determine which submit button to "press" based on the form that has focus. If there are multiple submit buttons in a single form, which sounds like the case here, the browser will submit using the first submit button that it finds. I know of no way to get around that behavior.
You're really asking how to perform one of two actions with a single form, which kind of breaks the form model: a form is designed to perform an action (GET or POST) on a single URL. I can think of one way to work around this behavior, but it is not particularly clean.
Suggestion:
I made a crude drawing of what I'm talking about. You basically add two radio buttons to the top of the form, one for login and one for registration. Underneath those you have two fieldsets, one with fields for login and one with fields for registration. The form has a single submit button.
Click to view full size image http://img220.imageshack.us/img220/5923/boardc.th.jpg
Users without Javascript will check the appropriate radio button and fill in the appropriate set of fields. Users with Javascript have a better experience. If the login radio button is checked, hide the registration fieldset. If the registration radio button is checked, hide the login fieldset.
With proper styling, you can make it look nice. Your logic would have to check the radio button field's value to determine what action to take, but that shouldn't be too hard.
That's all I can come up with, given the single form limitation. This might not be a viable solution at all, depending on your other constraints, but it's all I've got. Good luck, and let me know if you have any questions about what I've discussed!

Using Yes/No Messagebox in Updatepanel AJAX

I have a requirement where I ask user for confirmation and also display messages.
The programmers used for this were from Windows forms background. Hence have used the MsgBox in every nook and corner. Even in business logic part they have used the Messageboxes which requires Yes/No style confirmation from user.
When we tested the site from the remote machine we found that it gives error of using DefaultDesktopOnly/ServiceNotification. But when tested we found that this is totally different from what we were looking for.
Now my requirement is a confirmation box is shown from the code like Delete record" yes no and based on the reply we take the action.
This is to be done using updatepanel.
As you use this code in several places, I suggest you make a custom control, that takes your message and displays and Update panel with message and yes/no buttons.
Internally set some value for yes, no, cancel... so that you get something just like MessageBox.
Update panel or not, you'll have to attach some javascript that would call confirm() javascript function. Based on it's result you cancel javascript default link/button behaviour...
This will give you something to scratch your head for a start:
http://www.dotnetfunda.com/tutorials/ajax/updatepanel.aspx
That's not really a question, but a requirement.
Anyway ... MessageBox is a Windows function, it is not an HTML or browser function. Now you can mimic it in one of two ways, via a javascript confirm function or via Yes/No buttons and the appropriate event.
Given that your requirements are for something that works in an update panel I'd guess that wiring up javascript events manually for this isn't going to be something you are comfortable with, so I'd suggest an asp:Panel inside the UpdatePanel which has yes and no buttons, with server side events bound to them. In the UpdatePanel logic show this when you want confirmation and hide everything else, the act accordingly.
If you want to do server-side confirms, you'll get into more complicated code generation. First of all, you'll have two views. The first one has a link/button delete but will actually be just a postback to the second view that will display confirmation form with yes/no. In this form, your yes button will actually be your delete action...
But I'd still chose a hybrid (especially if this is a grid we're talking about) of javascript and serverside (since alert() and confirm() are evil from user experience perspective):
you have a linkbutton delete
when user clicks on it, you replace this control with a div, that displays two linkbuttons yes/no
send a postback with one of the two
Addendum
No linkbutton could be just dummy, to hide this confirmation and display delete again - so it means there won't be any server round trip
you could even create a usercontrol that mimics this sophisticated delete link behaviour to make it reusable application wide.

Resources