i am creating textboxes when a button is clicked and again and again and so on
while accepting input i need to check if the boxes are all full,
i know how to do this using design view but how to do this using coding
that is add and validation control to the textbox when it created before initializing/adding it to the page.?
validation should be not null..
So as for validating the user input I would stay away from the ASP.Net Control Validators as hardly anyone in industry uses them. I would use the jQuery validator plugin which is included in a new Visual Studio project by default. You will still want Server side checking but it is much easier to call String.isNullOrEmpty(txtBox.Text) rather than using the Control Validators.
Related
Whenever the "Reserve" button is clicked in my web application (ASP.NET with C#, Visual Studio), a small window should pop up containing detailed options to choose from (drop down lists with values, comboboxes, etc), with a "Next" link, and "Finish", in the end. Changing the values in these controls should update tables I have in the database (Microsoft Sql Server).
Could you point me towards a detailed and useful resource/example of this? I am already using a book for inspiration (Cristian Darie) written in the form of steps / explanations, but scenarios as just described are not included. What should I be looking for? "Using Pop up windows with Visual Studio"? Is what I described known as a popup window?
I don't know JavaScript, is that needed here? Been practising lately a lot with classes, methods, stored procedures, masters, user control type files, handling db tables through Visual Studio classes and methods, etc but still new to these (a month old basically). Thanks a lot!
it's not necessary to use JavaScript, but if you want anything a bit more fancy than just a regular popup window, javascript will be a good friend to you. As I see it it's basically four main ways of doing it:
1
Create a new ASPX file with the "details", send a querystring to the url of the details view in order to connect the popup with the data from the main window. a key to this is the "target" property of the html "a" tag. For example:
Details
2
Create a popup window with some custom properties (i.e toolbars window size of popup etc) using regular javascript. Look for window.open in javascript.
Example:
Details
3
Using jQuery to open the popup in a modal dialog fashion using a lightbox. For this alternative I don't have any example, but google jQuery lightbox, there are heaps of them. Use that with an AJAX-call and achieve your goals.
4
And at last, use ASP.NET AJAX Control Toolkit (look here:
http://www.asp.net/ajaxlibrary/act.ashx) Download and install, use the ModalPopupExtender (tutorial here: http://www.asp.net/ajaxlibrary/act_ModalPopup.ashx) from the toolkit, in which case you design your "details" view in a <asp:Panel> control and then using CSS and the ModalPopupExtender to display and hide the details, the looks will be like the lightbox but you don't have to create a separate ASPX page for this option, but you can use the same ASPX.
I've worked alot with all four options, and i tend to like the 4th alternative the best, but we all have our own taste.
Good luck, and feel free to ask away for more detailed information. :)
let's take this step by step. In order to send that information, I think the
easiest way would be to store the parameters as session variables and then reload them
when the popup is closed, you can reload the parent window using the "onunload" event in
Javascript, for example
<body onunload="window.opener.location.reload(true);">
This would in
itself reload the parent window whenever the user closes the popup. IF you want it to close
when the user saves changes (and your session variables are set), use this code in order to reload
the parent window and close the popup. Put this code in the code behind, just before the
end of your method that saves the data:
Page.ClientScript.RegisterStartUpScript(this.GetType(),"close","<script language=javascript>window.opener.location.reload(true);self.close();</script>");
To learn javascript, have a look at codeproject.com, they have a lot of articles regarding
javascript (among other things), often with example code. :)
I made a quick example here: http://www.4shared.com/zip/LPtR1gbx/pop.html
I would recomment using a <div> element rather than an actual new browser window.
It eliminates the need to pass the contextual information from the pop-up window back to the original window along with all the complexities involved with it (including things like the user inadvertently clicking off the pop-up window, clicking multiple times and thus bringing up multiple copies of the pop-up window, and so forth).
By using a <div> that "pops up", via controlled visibility through CSS or JavaScript, the entire context is kept to the same web page, making life so much easier overall.
I am trying to implement a KeyDown event for a textbox in Visual Web Developer. I am using C#. I know how to do this in a windows form but the technique isn't portable to VWD. I want to capture the text in the textbox when the user hits Enter.
Any advice is appreciated.
Regards.
Sounds like you may want to read up a bit on Web forms in general. A quick summary:
Since web pages are all client side, you have to explicitly tell it when to talk to the server where all the major lifting takes place.
So you have the html form tags:
<form>
</form>
and all important text boxes and other form controls go between.
Then you need a submit button which under normal circumstances is the only way to submit the form to the server for processing. (The "enter" key activates the submit key also.). Submission always either reloads the page or causes a move to the next page, depending on the actions specified.
ASP.NET does take care of a lot of page events and such for you. as you have probably noticed by now, though, when you right click a text box and look at the available events, you only have a few, such as "textchanged". This is because anytime you do not actually submit a form to the server, you need AJAX to do a call to the server for you while not reloading the page. the "textchanged" event on a textbox is still going to be AJAX driven - it's just the Microsoft has built it in for you. You will want to look at either jQuery or the ASP.Net AJAX libraries.
You say you want to "store" the result - is it to generate new behavior later on the page? that's AJAX. Is it for longevity while the entire application is worked through? That can wait until the submit.
Actually the textChanged method waits for the Enter key to be hit.
I currently have two dropdown menus, and one gets filtered when the user selects a value from the other. But I will also need to support a non-javascript version and am wondering how to achieve a postback via onselectedindexchanged? I know that i can't use the AutoPostBack property for example, so how can this be achieved?
Thanks.
You can't use the post-back features (which SelectedIndexChanged is one) of ASP.Net and have javascript disabled. ASP.Net and WebForms have a tight coupling with javascript to perform most all its posting functionality including some basic things like maintaining ViewState.
If disabled javascript is a requirement, you might want to consider using an MVC approach, but even that will still be a very limited web user experience.
I think I want to show some kind of confirmation tick type thing by a textbox - (it's traditional windows forms stuff, not WPF) - but not sure if it's a bit naff. I would like some kind of slick way of showing that a value is incorrect or valid after some tests have been done i.e. a web service is valid with that name or SMTP server seems to running with that name etc.
Should there be even any visual stuff going on or should a simple message on a status strip at the bottom of the window be enough.....
Any ideas are most welcome.
PS - if the tick thing is a good idea what's the best way to implement this with a textbox control.
Example....
You could make a custom control which contains both a textbox and an imagebox. The custom control could raise a validation event which checks the text and then sets the imagebox graphic based on whether or not the validation passed (or sets it blank if there is not text in the textbox).
The .net centric way would probably be to implement validation providers and some type of custom error provider, like what Henrik is mentioning.
You can use ErrorProvider to show a little exclamation mark when the entered value is incorrect.
you can use the ErrorProviderComponent in order to show notifications. The naming of that component is slightly unfortunate in my mind but you can easily change the icon to show other things than the typical red error "X".
I have a website to which I need to pass 4 parameters and then extract data programmatically but there is a big problem. The website is built into ASP.NET with FORM inside AJAX. So, I can fill one field programmatically and then I fill second field. There is a need to click a button in order to fill third field so I press button programmatically then. The problem is that when I click the button, the second fill gets empty before calling the button event and causes error.
So is there a way I can sharply fill fields without causing errors?
Take a look at web automation library such as WatiN - this lets you do this kind of interaction.
I agree with Oded and would like to add that as an alternative Selenium RC in combination with NUnit might be an option.
I believe IRobotSoft web scraper can do this kind of work. You will use two form filling actions, and add a Click action between them.