I'm about to convert an app written in ColdFusion to ASP.NET. The CF code consists of many pages with 'if' statements sprinkled throughout the HTML code. For a simple example, say that a page had 3 dropdowns (each populated via a db query) and a submit button.
User A's privileges allow him to see all 3, while user B's allow him to only see the first 2, and user C can only see the first one. I see two ways to deal w/ this: Leave it as is. The disadvantages being: 1) The .aspx page is littered w/ if statements. 2)
Not a good separation of business logic and presentation code. 3) Since the user's privileges affect whether or not each db query is run, 'if' statements must exist in the code behind page (to determine whether or not to run each query), and also in the .aspx
page (to determine whether or not to output the HTML for each dropdown). Very difficult to maintain, and error prown. 4) Since the 'if' statements are nested, and indentation is used for each level of nesting, the HTML will be very hard to follow. Too easy
to miss end tags, and it's a nightmare to follow the source sent to the browser. Set the visibility of each dropdown to false, and in the code behind page, set only the ones that the user should see to true. The disadvantages being: 1) A lot more HTML may
be sent to the browser than is actually displayed, slowing down the page load. The above example was overly simplistic...in actuality, the pages are very complex, with huge chunks of HTML that may or may not be presented to the user. 2) A user could theoretically
save the HTML source from their browser, and set every non visible element to visible. This allows them to see what they're missing (which may or may not be any big deal). Perhaps there's another way to approach this. I'm certainly open to suggestions! Thanks,
Ross
Seperate the presentation layer, Busiess login layer, Data Access layer and your code will certainly be clearner and easier to support. seems to me that you could pass the userid as a parameter and return the results for all three dropdown from a single procedure.
This would produce a less chatty- connect/disconnect connect/disconnect .... application . Then traverse through your dataset and assign the recordset to each drop down. It all come down to this its trade off you have to decide if you already have it done
in ColdFusion why do you want to convert/port your code directly over. Look at the design and think in a more .net way of here is how I can provide functionalty that would have been impossible in coldfusion and I can do in less than 1/2 day in .net. Hopefully
you get the drift here. Your on the right track. Regard Tiny
While there are some disadvantages to your second option, the two you list are NOT true. Setting the visiblity of an object to false on the server side causes the object to NOT be rendered to the browser at all. So neither of those issues will be a problem.
The second option is definitely the best; its only real downside is the time it will take to do the conversion. AutoFed
Good point. I was thinking that the size of the file being passed over the wire could be much larger than it needs to be in the case of a user w/ limited privileges, but I guess the bulk of the time is in the browser's rendering of the file, not the transfer
itself. I'm actually new to stored procs, and didn't realize that I could not only perform 3 separate selects in a single call, but also only run them conditionally. In other words, User A's page would require that all 3 be run, User A's would only require
2 of them, etc. Do you know where I could find an example of how to do this? Thanks, Ross
You may also want to check the books online located in SQL Server. Search for Create Procedure. Pass the user's credentials as a parameter to the stored procedure and structure the stored procedure using deterministic code to evaluate the parameter(s) passed.
OH gobbledy gook. Provided You havn't removed the northwind database you can run this in the query analyzer. It's directly from books online in SQL Server so all props to MSFT. Books online is a great source of help by the way. :) USE pubs IF EXISTS (SELECT
name FROM sysobjects WHERE name = 'au_info' AND type = 'P') DROP PROCEDURE au_info GO USE pubs GO CREATE PROCEDURE au_info @lastname varchar(40), @firstname varchar(20) AS SELECT au_lname, au_fname, title, pub_name FROM authors a INNER JOIN titleauthor ta
ON a.au_id = ta.au_id INNER JOIN titles t ON t.title_id = ta.title_id INNER JOIN publishers p ON t.pub_id = p.pub_id WHERE au_fname = @firstname AND au_lname = @lastname GO The au_info stored procedure can be executed in these ways: EXECUTE au_info 'Dull',
'Ann' -- Or EXECUTE au_info @lastname = 'Dull', @firstname = 'Ann' -- Or EXECUTE au_info @firstname = 'Ann', @lastname = 'Dull' -- Or EXEC au_info 'Dull', 'Ann' -- Or EXEC au_info @lastname = 'Dull', @firstname = 'Ann' -- Or EXEC au_info @firstname = 'Ann',
@lastname = 'Dull'
I was actually wondering how to execute multiple select statements in a single proc, loading the results of each into a single dataset. Every example I've seen so far shows a single select filling a single datatable.
Dim cmd As SqlCommand Dim rdr As SqlDataReader cmd = New SqlCommand("SELECT * From Fish;" & _ "SELECT * From Food;", _ nwindConn) rdr = cmd.ExecuteReader() conn.Open() rdr.NextResult Do While myReader.Read() ' Fish records processing… Loop rdr.Close()
Note Look up NextResult within Ado. You really should consider stored proc's and returning multiple resultset. I like to keep reusable and not so specific so I usually don't then to combine mutilple results within a single call
Regard -Tiny :-)
rwozniak
Member
35 Points
7 Posts
To if, or not to if
Aug 08, 2003 03:22 AM|LINK
TinyPond
Member
739 Points
228 Posts
Re: To if, or not to if
Aug 08, 2003 05:01 AM|LINK
autofed
Participant
1789 Points
357 Posts
Re: To if, or not to if
Aug 08, 2003 08:02 AM|LINK
rwozniak
Member
35 Points
7 Posts
Re: To if, or not to if
Aug 08, 2003 11:31 AM|LINK
TinyPond
Member
739 Points
228 Posts
Re: To if, or not to if
Aug 10, 2003 04:22 AM|LINK
rwozniak
Member
35 Points
7 Posts
Re: To if, or not to if
Aug 10, 2003 01:35 PM|LINK
TinyPond
Member
739 Points
228 Posts
Re: To if, or not to if
Aug 11, 2003 06:54 PM|LINK
ohbajesus
Member
30 Points
6 Posts
Re: To if, or not to if
Aug 12, 2003 04:22 AM|LINK
rwozniak
Member
35 Points
7 Posts
Re: To if, or not to if
Aug 12, 2003 10:33 AM|LINK
TinyPond
Member
739 Points
228 Posts
Re: To if, or not to if
Aug 13, 2003 01:20 AM|LINK
Note Look up NextResult within Ado. You really should consider stored proc's and returning multiple resultset. I like to keep reusable and not so specific so I usually don't then to combine mutilple results within a single call
Regard -Tiny :-)