Web User Control

C

Chris

Hi,

I want to create a User Control that shows a registration page on first
visit, or if the visitor has already registered (this session)
shows a list of files for download. I will be using cookies to manage the
registered user's sessions.

In the Page_Load method i check if the cookie exists in Request.Cookies, if
so i Bind the data and show them the available files.

It the cookie does not exist, i want to show the user the form.

My question is this, is there a way programatically to do this using code
behind page? or do i need a big if statement
in my aspx page.

ie can i do something in Page_Load eg

if (!Page.IsPostBack && Request.Cookies["mycookie"] == null) {

// include the form ** how do i include my html form at this point?

} else {

if (Request.Cookies["mycookie"] == null) {

// store the users reg info

// set the users cookie
Response.Cookies.Add(new HttpCookie("mycookie", "testvalue");

}

// bind the appropriate data
}


The alternative i'm trying to avoid is mixing the code with the html,
something like

<html><body>
<%
if (......) {
%>
<form>...</form>
<%
} else {
// cookie setting and data bind code
%>

<%
</html>
</body>

Thanks for any comments
Chris
 
M

Mark Fitzpatrick

Sure thing, use Panels. You can put your code into two panels. Then, in code
behind, check for the existance of the cookie then you can set the visible
and enabled properties of one control to true, and the other control to
false.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 

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
473,780
Messages
2,569,611
Members
45,266
Latest member
DavidaAlla

Latest Threads

Top