PDA

View Full Version : Rokkie Question



Ivan Sammut
14-Jan-2006, 07:55 AM
Hi I am trying to create a form which display details about my users. The screen consists of 2 textboxes & 2 buttons (Next - Previous) whiuch scan thru my records. My problem currently is that I have to click twice on my buttons before the record goes to the next or previous record. Here is my code, could you pls tell me what I'm doing wrong.

<%
RecId = request("RecId")
%>
<html>
<body>
<!-- #INCLUDE FILE="inc/SetChangedStates-script.inc" -->

<!-- #INCLUDE FILE="inc/ddValue_Constants.inc" -->

<% ' DebugMode =1 ' uncomment this for page get/post debug help %>
<!-- #INCLUDE FILE="inc/DebugHelp.inc" -->
<form action="oUser.asp" method="POST" onsubmit="SetChangedState(this)">
<table width="75%" border="1">
<tr>
<td width="20%"><font face="Verdana, Arial, Helvetica, sans-serif">Login :</font></td>
<td width="80%" Class="Data"><%=oUser.DDValue("Users.Loginname",DDForm)%></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif">Full Name :</font></td>
<td Class="Data"><%=oUser.DDValue("Users.Full_name",DDForm)%></td>
</tr>
</table>

<input name="findnext" type="submit" id="findnext" value="&gt" />
<input name="findprev" type="submit" id="findprev" value="&lt" />
</form>
<%

If RecId <> "" Then
Err = oUser.RequestFindbyRecId( "Users", RecId)
else
Err = oUser.RequestClear("Users",1)
End if

If request("Request_method")="POST" then


if Request("findnext")<>"" then oErr = oUser.RequestFind("Users",1,GT)
if Request("findprev")<>"" then oErr = oUser.RequestFind("Users",1,LT)

end if
%>
</body>

</html>

The code marked in red is what I think its not working.
Thanks
Ivan

Knut Sparhell
14-Jan-2006, 09:06 AM
Ivan Sammut wrote:
> Hi I am trying to create a form which display details about my users. The screen consists of 2 textboxes & 2 buttons (Next - Previous) whiuch scan thru my records. My problem currently is that I have to click twice on my buttons before the record goes to the next or previous record. Here is my code, could you pls tell me what I'm doing wrong.

> <form
......
> </form>
> <%
> If RecId <> "" Then
> Err = oUser.RequestFindbyRecId( "Users", RecId)
> else
> Err = oUser.RequestClear("Users",1)
> End if
>
> If request("Request_method")="POST" then
>
> if Request("findnext")<>"" then oErr = oUser.RequestFind("Users",1,GT)
> if Request("findprev")<>"" then oErr = oUser.RequestFind("Users",1,LT)
>
> end if
> %>
> </body>
> </html>

Always put the interface calls above your html form. Your code, as it
is, will manipulate the DDOs (find a new row) after the original values
are displayed. That's probably not what you want.

You have also forgotten the hidden input containing the Recnum, like this:

<input type="hidden" value="<%=oUser.ddValue("User.Recnum")" />


Longer answer:

Remember, that in a web application, the ASP script is the driving
primary program, run whenever the user sends a request to the page, and
it runs from the first line and downwards as usual. The script will in
it's turn call methods in your VDF process in the order they are placed
in your file. The responsed ddValue's must therefore do their job after
the find operations are completed, at least to produce a predictible result.

Hence, a click on a button does not make the script continue down from
it's html representation. A click will send a new request that starts
the script form the top, with new parameters like the recid, and it will
not stop before it reaches the very last line. Then, not before, are
the resulting web page presented to the client user.

(this is quite a common mistake among beginners in server side scripting
techniques)

At last, remember, that every DDO operation (finds, save, delete) are
always based upon the posted recnum (or rowid) of your currently
displayed record. So don't forget to include this, or you may get
unpredictable results.

A web apllications doesn'r have a current record in it's memory while
the users is contemplating about what to do, at least not one to be
trusted. The basis of a teh find must be taken from the display at the
client. Hence, the mandatory hidden input field.

--
Knut Sparhell, Norway