link button and stored procedure

R

Rod Snyder

I'm trying to set up a page with an asp.net link button that would send a
user to a certain page and on page load execute a specific stored procedure
tied to the button on the previous page. The link would be in a nav area and
be something like "update". It would send the user to the main page and
execute the stored procedure associated with the update functionality. I'm
new to this area of .NET and would appreciate any suggestions, directions or
comments.

Rod
 
M

Mike Moore [MSFT]

Hi Rod,

The link button will post the page back to the server. In the link button's
click event, use Response.Redirect to redirect the user to your other page.
Now, the issue is how to communicate to the new page that it needs to run a
stored procedure and which one to run. There are several ways to accomplish
this.

Lets assume that the new page's load event has this variable:
Dim StoredProcToRun As String

* Query String
You can add information to the query string in your call to
Response.Redirect.
- In the link button click event:
Response.Redirect("NewPage.aspx?StoredProc=GetCustomers")
- In the new page load event:
If Not IsNothing(Request.QueryString("StoredProc")) Then
StoredProcToRun = Request.QueryString("StoredProc")
End If
We test if it is nothing before using it because an error will occur if it
is nothing and we try to use it.

* Session
You can instead redirect the user without the extra query string
information and supply the information with the session object. This
requires that you use sessions in your application.
- In the link button click event:
Session("StoredProc") = "GetCustomers"
Response.Redirect("NewPage.aspx")
- In the new page load event:
StoredProcToRun = Session("StoredProc")

* Cookies
Again skipping the extra query string information, you can supply the
information with a cookie. This requires that your users accept cookies.
- In the link button click event:
Response.Cookies.Add(New HttpCookie("StoredProc", "GetCustomers"))
Response.Redirect("NewPage.aspx")
- In the new page load event:
StoredProcToRun = Request.Cookies("StoredProc").Value

---
Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 
R

Rod Snyder

Mike:
Thanks so much for the comprehensive answer. Someone had suggested query
strings to me but it sounded link it might not be the best option concerning
security. I like the sessions option and will probably try to implement that
version. Thanks again for your help.
Rod


"Mike Moore [MSFT]" said:
Hi Rod,

The link button will post the page back to the server. In the link button's
click event, use Response.Redirect to redirect the user to your other page.
Now, the issue is how to communicate to the new page that it needs to run a
stored procedure and which one to run. There are several ways to accomplish
this.

Lets assume that the new page's load event has this variable:
Dim StoredProcToRun As String

* Query String
You can add information to the query string in your call to
Response.Redirect.
- In the link button click event:
Response.Redirect("NewPage.aspx?StoredProc=GetCustomers")
- In the new page load event:
If Not IsNothing(Request.QueryString("StoredProc")) Then
StoredProcToRun = Request.QueryString("StoredProc")
End If
We test if it is nothing before using it because an error will occur if it
is nothing and we try to use it.

* Session
You can instead redirect the user without the extra query string
information and supply the information with the session object. This
requires that you use sessions in your application.
- In the link button click event:
Session("StoredProc") = "GetCustomers"
Response.Redirect("NewPage.aspx")
- In the new page load event:
StoredProcToRun = Session("StoredProc")

* Cookies
Again skipping the extra query string information, you can supply the
information with a cookie. This requires that your users accept cookies.
- In the link button click event:
Response.Cookies.Add(New HttpCookie("StoredProc", "GetCustomers"))
Response.Redirect("NewPage.aspx")
- In the new page load event:
StoredProcToRun = Request.Cookies("StoredProc").Value

---
Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
From: "Rod Snyder" <[email protected]>
Subject: link button and stored procedure
Date: Tue, 20 Jan 2004 20:44:07 -0500
Lines: 11
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
NNTP-Posting-Host: pcp05147733pcs.epensb01.pa.comcast.net 69.139.82.193
Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontrols:17565
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

I'm trying to set up a page with an asp.net link button that would send a
user to a certain page and on page load execute a specific stored procedure
tied to the button on the previous page. The link would be in a nav area and
be something like "update". It would send the user to the main page and
execute the stored procedure associated with the update functionality. I'm
new to this area of .NET and would appreciate any suggestions,
directions
or
comments.

Rod
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,091
Messages
2,570,604
Members
47,223
Latest member
smithjens316

Latest Threads

Top