I am working on a project in which on selecting a drop down list item the values from the database should appear in the respective two text boxes.
But, alongside I am placing an image which is actually getting created based on the two values. Now on selecting the next dropdownlist item there is a page refresh and the placed image dissapears.
How to I avoid the page refresh keeping in mind that the fields from the database must get displayed on the page in the two fields on select of drop down list.
Kindly help!
thanks...
In my case, there exists a table in which there are two halfs, the left has text boxes n a button n to the right side of the table the image appears.
If you are using ASP.NET WebForms, you could wrap the controls which you only wants to post back inside an UpdatePanel.
Alternatively, remove AutoPostBack="true" from your DropDownList, and use javascript/jQuery AJAX to perform your database request.
Disable autopostback.
<asp:DropDownList AutoPostBack="false" ... />
Without the slightest piece of code, this will be hard to answer.
To prevent default behavior in javascript, there is this method
e.preventDefault();
Where e is your event.
Your issue is to preserve the values fetched from DB.
The easiest and safest way is to store the values fetched from database into hidden fields. This way when your page postbacks the values persists and you can use them as you wish.
Happy Coding!!!
Related
So, basically my problem is that i have a series of tabs on my page, one of the tabs (not the default one) has two drop-down lists, the second drop-down list only populates after an item from the first drop-down list is selected, obviously without putting the autopostback = true value in my drop-down list, they wont automatically populate however adding autopostback = true causes the page to reload and changes tabs back to the primary default tab. Is there any way around this that people know as i don't really want the users having to change back to the correct tab 4 times to fill in a form. Thanks
I think your dropdown is asp:DropDown (server side). I recomend you to use html element and do your staff at front end with jquery,ajax etc. But in your case if you want to update part of the page without using front end tools (jquery-ajax), You should use asp:UpdatePanel for it. Search for it, it is not so complex. Good luck.
Introduction to the UpdatePanel Control
How do I use updatePanel in asp.net without refreshing all page
I'm facing a problem with one of my pages. I have a FormView control on the page that I use to enter new rows into a database table, and a GridView control on the same page to update/delete rows from the same database table.
The FormView control has validators on it to validate any input being thrown at the database, and it seems to interfere with the GridView when I try to edit a row. When I try to save the edit, the validation control on the FormView gets fired and an error comes up because the textbox input is blank, so the GridView cannot save the modified table data.
Perhaps a visible example will help:
I had an idea where I encase these controls in different forms, hoping that the submit of one form won't fire anything in the other but then I got an error saying I can't have more than one form on the page with runat="server", which as far as I can tell is required.
How can I get around this?
Thanks.
You can only have one Form.
Use different ValidationGroups for your FormView and GridView instead.
http://msdn.microsoft.com/en-us/library/ms227424(v=vs.100).aspx
Yes, this is a known limitation (feature?) of webforms. You can only have 1 form with a runat="server" tag.
In your scenario you can use ValidationGroup names to group validation together so only "like" validation is executed when a control of the same validation is triggered.
What I did is I had two forms coded as postback to the page and parsed out the postback variables in Page.Load myself. Weird? Yes. Works? Yes.
this is my second option regarding my first question I did a lot of searching in google and tried it for a couple of times. Do you think its possible to populate a gridview without any postback from a dropdownlist?
Use update panel and script manager. Change properties of update panel Update mod conditional. After you can call when you want "updatepanel.Update()" or select your trigers and it ll do it automaticly.
No. You need postback in some form traditionally or using AJAX. These kinds of things happen in the server and that is why you need postback. Or you can use extensive Javascript.
You can use JavaScript and draw the whole gridview since a gridview is a table with columns and rows.
I know this has been asked, but none of the numerous answers fit with my situation. So I will humbly ask if someone can walk me through this again gently.
Environment: .Net 4 web app using c#, javascript, jquery, sql server, and entity framework.
Question: I need to be able to allow a user to "quick add" a value into a table that is bound to a drop down box without losing values a user has already entered onto current page. I don't care if I have to do a postback or use jquery or use ajax, etc. I need the functionality first - prettiness later ... the scenario is described below if you care to keep reading. With all that being said, I would love for this to be smooth and not "clunky" for the user.
Scenario:
I have a page where the user is able to enter many pieces of information into textboxes, static drop down boxes, and drop down boxes that are bound to other tables that will all get combined and inserted into one table. Well, it never fails, a user could be filling in the page and when they get to one of the table bound drop down boxes - a value is missing or they haven't added something item yet. I would like to add a button or link or something next to that drop down box that would allow the user to "quick add" an item to the table that fills that drop down box and then refresh the drop down box so they can choose that new value from the list ... all while not losing the other data on the screen they already entered.
What I've tried:
-Tried WebMethod option. Currently, this web page calls some custom "bind" methods in the code behind to fill drop down boxes so they are not filled directly from objects from entity framework. So that means using a static method will not work for a solution because part of the static function would need to call the bind method to refresh the drop down box with the newly inserted values.
-Tried PageMethod option. Some of the other samples used Page Method settings, but my site uses master and content pages and the posts seem to state that the page method route was not going to work.
Make sense?
Add an UpdatePanel to the page. The update panel should wrap the drop down to be added, as well as the textbox/button for adding a new entry to that drop down. You would want to have a different UpdatePanel for each dropdown/button pair, if applicable.
When they click the button inside of the update panel you can read the textbox, add an extra item to the drop down, and send an update to the database. (I'd manually add the new value to the drop down rather than updating the database and re-binding, if possible, but it may not be.)
The magic of UpdatePanels will make sure that this is all asynchronous and so doesn't disturb the user working on the page.
I am creating online booking page.
I got some example page you can see in this link
http://www.parkercorporate.co.uk/webbookercc/OneForm.asp
I need the same behaviour in my site whenever user selects value in pickup dropdown list in the right side I need to change the text values or view.
To do this behaviour how should I write code in ASP.NET and c#.
Thanks
Ranam
First, use an UpdatePanel so you don't see any visual postback.
Second, set the AutoPostBack property on your DropDownList to True.
Third, handle the DropDownList's SelectedIndexChanged event. This will now fire after every change in the DropDownList, because you enabled AutoPostBack.
In the event handler, you can now change the ActiveViewIndex of the MultiView, or show/hide controls, change textboxes, etc.
First, create different blocks (i.e divs) and give ID's to them.
Then, for each value in the dropbox, fill the divs w.r.t it.
Assign "OnChange" event to the dropdown, and in the handler, set visible or invisible to corresponding block.
On the other hand, If you want to do this on client side, I strongly suggest you to use JQuery, to prevent a lot of requests going to server.
Check this out with JQuery:
make visible div on dropdown select in jquery
If you won't fetch values from database, there is nothing complex about this page. Because it just writes hospital if you choose hospital etc. and changes control's visible state.
Even if you think you need db queries when dropdown's selected change event, actually at this page there is no need. Just store db values in hidden controls (like Hospital- for Hospital) and when dropdown selection changes, write hidden's value completely in javascript