Alright so I want to create a form, where the text in the textboxs will be sent to my database, after the user hits sumbit. The problem I am facing is i am used to using a detailsview or formview to do this for me, but how can I do this myself, where I manuelly update my database.
If I understand you right, write in OnLoad event code which will generate all controls which are needed.
Related
if you have not encountered this problem and I have to upload my code in order to explain it for you or for you to be able to debug it, then this question is not for you.
I know I can solve this problem by using code-behind, but I don't want to do it. Eventually I will have to do it if nothing works.
I am not using any databound control (gridview,Formview,Detailview etc). Everything is a general form control: textbox and ListBox. I am using their Text and SelectedValue properties to supply values to Updatequery's ControlParameters. Everything should be working as expected. I have played with the ViewState property of the texbox control and the sqldatasource control itself, to no avail. The stored procedure used for the update command is logging the values supplied from the ASP.Net side and amazingly it shows the old values of textbox that were there when the form loads and not the changes I make.
Whats going on here?
Thanks!
Seems like you are missing something in the asp.net life cycle.
Remove any DataBind calls to your sqldatasource on page Load.
If you are using DataBind on Load to populate those text and select controls, a databind will just overwrite any values you entered.
Don't be so shy to show your code, it helps a lot in providing good answers.
I have an ASP.NET page with a Wizard control containing several steps and about 80 form fields. The data is collected and inserted to a database from the code behind page. I need to set this form up so you can not only insert, but edit a record as well. So I want to databind the fields. I'd rather not use a FormView because then I would have to revise my existing code, since you can't access controls inside a FormView directly. Is there a way to databind the fields without using a FormView? I'm new at this by the way so sorry if the answer should be obvious.
A wizard is just a UI control with many steps in it. You can use it to insert, edit, delete or anything else you can think of. You can have an INSERT wizard and an EDIT wizard. The difference would be that there would be two of them and that the code behind for each one (presumably on the CompletedStep) would have slightly different code to persist the data. The insert wizard would call an insert database query and the edit one would call an update query.
That being said, you can access the control inside a FormView, I'm not sure why you said that you can't access controls indie a FormView. You can. See Using FindControl: Accessing Controls in a Formview.
You could even put the two wizards inside the two states of the formview - InsertTemplate and EditTemplate but thats getting a little crazy :)
I have a dropdown list which retrieves data from a datasource. I must to update the dropdown when I add new data to the database through another page. I've not found documentation for this kind of updating, that would be like the requery method on DAO databases for VB6.
it really depends on how you have designed your page, you could refresh the page with a refresh button or with the refresh of the browser or even via JavaScript which reloads your page every x minutes, then you will query again everything because the page will have a full life cycle again.
if you want to do more sophisticated things you can of course use Ajax ( PageMethods or UpdatePanel approaches ) to have a partial render.
Using the databind method for the dropdown will force the update of the control. But the combo will be updated only when the page is reloaded. Maybe the best way should be using Ajax...
Can anyone help me regarding updating data in the gridview by using AJAX?
Once values are entered into textboxes and saved into Database, then gridview has to update the new changes. And not by using the ajax updatepanel
Why exactly are you avoiding an updatepanel? It is the simplest option.
You can use Ajax functions for several things like keyboard support or bringing a popup for data editing, but for refresh, I have found that updatepanel works the best.
I have a simple user control containing two text boxes which I am adding to placeholder on Button Click event. I am storing the number(count) of clicks in View state and running a loop using count to create all previously added user control. I am also adding IDs to each User control (appending "UC" and count). I have also checked in view source the ids are same each time they are created. I have another button which basically does an post back. I have EnableViewState enabled ="true" in all controlls all the way up to Page Level.
My problem is that User Input does not persist on postback. please advice. Should this not be happening automatically for me?
Have a look at this:
http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx
I've encountered minor problems with it on a web farm, but for simple deployments its use is pretty straightforward. (Comes with source code, and the web farm glitch is a pretty simple fix.)
You need to create your dynamic controls in the Page_PreInit event rather than Page_Load or in a Click event handler. That way, they'll be there before ViewState, and then your posted values are applied.
I thinks what is happening is that you are creating your controls during the click event handler which happens AFTER ViewState and PostBack have been applied. This means your controls will be created empty each time.