Saturday, March 31, 2012

Submitting form doesnt update .Text

Hi!
I have this form that I use, both for adding records and for updating. When submitted, it checks if the Reuqest.Querystring("pid") i set, if not it adds a new record, otherwise it should update the current record (based on pid).
There are no problems if I add a record, but on update, the values in the form doesn't follow.
The basic structure is this:

Sub saveNews(Byval id)
'When I use this on an update, the values in name.Text and pbody.Text aren't the ones entered, but the previous values in the textboxes (or database).
If id <>""Then'Update dbElse'Add new recordEnd IfEnd SubSub btnSave()Call saveNews(Request.Querystring("pid")End Sub

Sub fEditFrm(ByVal id)
'Here I fetch the columns based on id
If objDR.HasRows Then
pbody.Text = objDR("pbody")
name.Text = objDR("name")
date_created.Text = objDR("date_created")
End If
End Sub

Sub Page.Load()'This checks which page you're onSelect Case Request.Querystring("page")Case"addnew" news.SetActiveView(editnews)Case"edit" news.SetActiveView(editnews)Call fEditFrm(Request.QueryString("pid"))'This one fetches the record and populates the textboxesEnd Sub


Is my problem understandable at all?
Thanks you alot!
/MartinI found the problem. Apparently the sub fEditFrm (which populate the form with db entry) executes before the update in saveNews(), so the textboxes reverted to the original values... I added an 'If Not Page.IsPostback' before the Call fEditFrm and it worked.
But then I have another question:
How can you check in which order things are executed? I come from classic ASP and it wasn't too hard to do things like this. Btw, I'm using VWD Express edition.

Enable tracing on the Page...

<%#@. Page Trace="true" TraceMode="SortByTime"%>

Then run the page. At the bottom you will see everything that is going on inside the page.


Thanks!
That was very useful, in Classic ASP I have this subroutine that spits out that info but this was much easier :)

Question though; is it possible to put that trace into a master page so you don't have to edit every single page?

Thanks again!
/Martin

You can enable trace for all pages in the web.config file, which looks something like this:

<configuration><web.config><trace enabled="true" traceMode="SortByTime" localOnly="false" /></web.config></configuration>

Thanks alot! I'll try it as soon as it's possible!

0 comments:

Post a Comment