|
I have a form that sends data to a Access Databse. and everything works great. When I click on the submit button, it clears the form and allows me to add another record. I want to have a few fields retain the same data from the previous record. My main question is, should I be doing this with a cookie?
|
|
|
|
|
A cookie is one way, but anyone who has cookies disabled in the browser would be unable to use it, or be forced to put your website in a more trusted zone (where cookies are enabled). A simpler method would be to use hidden fields on the form. When the form is posted, the same fields could be resent to the client as part of the new blank record. If this is user-type information, for instance, the hidden fields could be initialized at the session level to reset them for each user.
|
|
|
|
|
kashmir9999 wrote:
want to have a few fields retain the same data from the previous record. My main question is, should I be doing this with a cookie?
You could do it with a cookie but that probably is not the best way.
Here is how I would do it (and I am assuming you are using ASP, not ASP.NET, if not then just message back and I will show you how in ASP.NET):
<%@ Language=VBScript %>
<%Option Explicit%>
<%
Dim strNameFirst, strNameLast, dtmDateOfBirth
strNameFirst = Request.Form("txtNameFirst")
strNameLast = Request.Form("txtNameLast")
dtmDateOfBirth = Request.Form("txtDateOfBirth")
'- Now do your database code to save the record, but only if there is something to save
If Request.QueryString("mode") = "save" Then
'- save to db
End If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<link rel="Stylesheet" href="main.css" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
</head>
<body>
<form name="frmPerson" method="post" action="tet.asp?mode=save">
<table>
<tr>
<td align="right">First Name:</td>
<td><input type="text" name="txtNameFirst" value="<%=strNameFirst%>" /></td>
</tr>
<tr>
<td align="right">Last Name:</td>
<td><input type="text" name="txtNameLast" value="<%=strNameLast%>" /></td>
</tr>
<tr>
<td align="right">Date of Birth:</td>
<td><input type="text" name="txtDateOfBirth" value="" /></td>
</tr>
<tr>
<td align="right" colspan="2"><input type="submit" value="Save & Proceed" /></td>
</tr>
</table>
</form>
</body>
</html>
So basically when the page loads the first time it tries to retrieve the values of txtNameFirst and txtNameLast from the form POST data. However because this is the first time there is no data, but no worries because no error will be raised.
It then ensures that you don't save any new blanl records to the dB with the If.
Then the HTML and form is returned, if there is a value in the strNameFirst or strNameLast variables then they are shown in the text boxes, if not, then nothing is shown in the text boxes. Once again, no error if blank.
When you submit the form it does this all again but this time with values in the text boxes it can "retain state" and show what was typed in last time.
If you want default values then you can init the variables with a default value.
One nice thing about ASP.NET is that it does this kind of thing automatically! So swap to ASP.NET
Good luck Kashmir9999
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
"The greatest thing you will ever learn is to love, and be loved in return" - Moulin Rouge
Sonork ID: 100.9903 Stormfront
|
|
|
|
|
Does anyone know of any resources that compare the .NET framework with J2EE.
I'm interested in examples of which is more robust and scalable etc.
TIA.
Dave.
|
|
|
|
|
Unable to get syntax highlightning and command-completion to work in VS.NET with a regular *.aspx page
Anyone have any tips on how to accomplish this?! I tried to create a forms-page and separated the code to the file.aspx.cs-source, but it appears i manually have to compile the file and also get 2 files per page (*.aspx and *.aspx.cs).
..Mats
|
|
|
|
|
vs.net only supports intellisense with the codebehind model.
|
|
|
|
|
Anonymous wrote:
vs.net only supports intellisense with the codebehind model
That really sucks!
It makes regular aspx-editing a pain in the ass. Just hope there is a way around it and/or they fix it in the first service-pack.
|
|
|
|
|
I have a DataGrid in the web form,in Page_Load I bind it to a datasource.This database is very larg so I make the PageStyle availabe,when I run my form,
the first five rows appeare but if I click the next in pagerstyle nothing happend and it doesn't show next records.Should I add any code for this feature?
Thanks
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Yes, you have to handle the OnPageIndexChanged Event and bind the data again with setting the CurrentPageIndex property to the selected page index.
See, OnPageIndexChanged Event help in MSDN documentation. They have a sample also.
omkamal
|
|
|
|
|
Thanks
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Mazdak wrote:
Should I add any code for this feature?
Yes you have to add your own code (as the other guy said).
But on that note I was highly disapointed when I tried the DataGrid for the first time and figured out that all it did re: the Paging was put in the link really. What a cheek. It can't take MS more than a few minutes to add in the extra code.
Anyway. I was wondering if it was possible to inherit the DataGrid and make my own ASP.NET Webform Control which had the Paging code built in? I would think it is possible but before I start banging my head away at it I would like some confirmation.
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
"The greatest thing you will ever learn is to love, and be loved in return" - Moulin Rouge
Sonork ID: 100.9903 Stormfront
|
|
|
|
|
Paul Watson wrote:
I would think it is possible but before I start banging my head away at it I would like some confirmation.
This is my confirmation ;)
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Is is possible to change the cursor shape for netscape4.x ?
If yes, How ?
|
|
|
|
|
Sure, all you need to do is write a custom app that installs a hook on any running instance of NS and subclasses WM_MOUSEMOVE. You can then change the cursor for the app. Don't forget to force all your NS visitors to download and install the program.
Other than that... you're SOL.
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
|
|
|
|
|
While your at it, have your app uninstall NS and force the user to use IE. It will sure make my job (and many, many others) easier.
Nick Parker
|
|
|
|
|
How can I change browser window title dynamically using javascript in Netscape.
window.document.title = "abc"
does not seem to work with Netscape.
Is there any other way I can change window title dynamically in netscape ?
|
|
|
|
|
Unfortuantely the document.title property is read only in netscape (maybe different in 6+) hence why document.title = 'blah' will not work (pretty not annoying ).
Anyway I came up with this solution (although it's not ideal as it will nead a page reload).
Add this between the head tags:
<script language="Javascript">
var url = document.location.toString();
var posQry = url.indexOf('?') + 1;
var posTitle = url.indexOf('title=') + 6;
var posEnd;
var strTmp;
var arrSplits = new Array();
var idx = 0;
var strTitle = '';
if(url.indexOf('&') == -1)
{
posEnd = url.length;
strTitle = url.substr(posTitle, posEnd);
}
else
{
strTmp = url.substr(posQry, url.length);
arrSplits = strTmp.split('&');
for(idx = 0; idx < arrSplits.length; idx++)
{
if(arrSplits[idx].indexOf('title=') != -1)
{
strTitle = arrSplits[idx].split('=')[1].toString();
}
}
}
document.write('<title>'+ strTitle + '</title>');
</script>
When you want to change the title of the page you will need to reload it with a querystring key/value pair with a key of 'title'.
e.g.: <a href="myPage.html?title=A%20New%20Title">Change</a>
Your other alternative would be to do the same but server side.
e.g.(asp): <head><title><%=Request.QueryString("title")%></title></head>
hope this helps you.
|
|
|
|
|
I have a web form,when it loads,in Page_Load I open a connection to a database,and I use this connection in some functions,I don't know where should I clode this connection?In which functions? Should I open/close it in another place?
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
That really depends on the purpose of the connection on your web form. If this is the only place that you use your connection, you may consider leaving it where it is. Otherwise, if your application can use the same connection other places you may consider a function to be more adequate.
Nick Parker
|
|
|
|
|
Nick Parker wrote:
you may consider leaving it where it is
You mean it doesn't need to close it?????????
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Mazdak wrote:
You mean it doesn't need to close
Yes, of course you will still need to close the connection, I was under the assumption that you were still controlling the connection, knowing when to close the connection.
Nick Parker
|
|
|
|
|
Nick Parker wrote:
If this is the only place that you use your connection
No that's not the only place.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
I have to develop something for a programming competition. I'm considering doing an online shopping site, but I'm unsure about how to keep track of the items in the shopping cart. The user could be on the site for a while, so Session variables are not a good option. I could pass the Item IDs via the Request object, but that seems a bit unsecure - what if someone hacks the source code and changes the item IDs (or should I not worry as long as prices are not involved at that stage)? Any suggestions?
|
|
|
|
|
Why not to use a database to store all item IDs for example, that user want to buy?
Philip Patrick
"Two beer or not two beer?" (Shakesbeer)
Web-site: www.saintopatrick.com
|
|
|
|
|
I have a resizable window that I would like to place text in it. I'd like the text to always stay 90% of the window windth. So whenevery the window size is changed I'd like to change the text size.
Anyone know how please?
Thanks
Jeremy Davis
http://www.astad.org
|
|
|
|