Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve data from the database without submit()

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hi,

Please help me here with my knowledge gap.

From what I know, I can only access the database and retrieve the data on the form's Submit event. I can either submit the form to itself to stay on the same page or submit it to another page.

So, I guess my question is how can I trigger different functions that will retrieve the data from the database within the same page?

Example: the form has two buttons: GetName and GetLocation

When GetName is clicked, the routine that handles names fires, when GetLocation is clicked - a different routine that handles Locations fires. Both routines would bring back the data without going to the next page.

Please advise.

Thanks!
 
What you need is a combination of client-side scripting and CSS. You can use these to dynamically change the information displayed on the browser without having to request the data from the web server by doing a submit.
 
Let me give you some background information.

HTML tells the server to do certain things regardless of the user's input. HTML translates to commands like "make the page green" or "make this text bold".

ASP tells the server to write HTML, then combine the HTML it wrote with the rest of the HTML, then post the result. It says things like "If today is Thursday, write an HTML command to make the page green." You can see exactly what asp does if you do a view source on one of your pages. You will see the HTML that the server wrote, combined with the normal HTML. After the page loads, asp does nothing.

This is why asp pages often submit to themselves. You need to give the server a chance to rewrite the html using the user's input.

To do something like react to a button click without reloading the page, you will need a clientside technology....for example vbScript or JavaScript.
 
Oh, and I forgot to mention that the dynamic information need to be embedded with the page when it is first loaded. This could make loading of your page real slow (depending on the size of your database) as all the necessary information need to be loaded from the database.
 
Code:
<FORM METHOD="POST">
	<INPUT Name="Button1" TYPE="SUBMIT">
	<INPUT Name="Button2" TYPE="SUBMIT">
</FORM>
[highlight]<%[/highlight]

Dim bPostback
bPostBack = uCASE(Request.ServerVariables("REQUEST_METHOD")) = "POST" = True

If bPostback = True Then
	
	'Which Button was clicked
	If len(Request.Form("Button1")) > 0 Then
		Response.Write("Button1 was clicked.<BR>")
	End If
	
	If len(Request.Form("Button2")) > 0 Then
		Response.Write("Button2 was clicked.<BR>")
	End If
End IF
[highlight]%>[/highlight]
- J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top