Tuesday, October 30, 2007
SQL Statements within SQL Statements
SELECT
d.*,
u.FirstName ,
u.LastName ,
(Select Count(*) as ResponseCount from DiscussionThreads dt where dt.DiscussionID=d.DiscussionID) AS ResponseCount
FROM
Discussions d,
Users u
WHERE
u.UserID=d.UserID
Tuesday, October 23, 2007
Themes in .net
Here's what I found:
http://msdn2.microsoft.com/en-us/library/950xf363.aspx - Had to investigate the web.config. In doing so, found the pages property maintainScrollPositionOnPostBack. I thought this was great. So, I set it to true considering all of the forms we have
- Set pages property smartNavigation="true" to see how it worked.
- Had issues because I couldn't understand how the theme and the master page interacted. I ended up reading this article...http://msdn2.microsoft.com/en-us/library/wtxbf3hh(VS.80).aspx After reading it, I found out that master pages inherit the theme from their calling pages. Here's an excerpt:
- Master Pages and Themes
You cannot directly apply an ASP.NET theme to a master page. If you add a theme attribute to the @ Master directive, the page will raise an error when it runs.
However, themes are applied to master pages under these circumstances:
If a theme is defined in the content page. Master pages are resolved in the context of content pages, so the content page's theme is applied to the master page as well.
If the site as a whole is configured to use a theme by including a theme definition in the pages Element (ASP.NET Settings Schema) element. - Also learned that you can set the master page based on the page level, folder level (interesting for admin backends), and the application level (web.config)
- It did appear that when I added a new stylesheet to the app_themes directory, it took a minute to load. Essentially, at one point, i thought i had to update the .master file to see the difference. Although, i think that was just timing.
- Cool thing. If I add a stylesheet to the app_themes folder theme, it is automatically added as a property for this theme. So, i don't have to reference it in my file.
Friday, October 12, 2007
Ajax: Text value blinks or changes back to what it was before
- I would choose the drop down value
- Textbox would change
- Change the drop down value again
- Textbox value would change
- within 1 second, the value would change back.
To fix this, i just put the treeview rendering within a !isPostBack block. This fixed the issue. Essentially what I learned which.. is obvious, is that each time Ajax makes an update it posts back, and, of course this IS a postback. So, make sure if you're loading controls through datasets, etc that you only run it once.
Setting properties in included controls
Ok, typical situation, basic quesiton. I had a page which included a control. This control contained a label and drop down. This was included several times on the page. So, what was happening is that the label showed the same thing every time. So, how did I get around this?
I added a public property to the codebehind of the included control. Once this was done, I used the codebehind of the parent page and set the label values.
Thursday, October 11, 2007
Ajax and form doesn't work when setting focus
Key to this whole issue: When Ajax does a postback, it completely rewrites the html for that portion. I had to take my individual text boxes out of one updatepanel and put it into multiple.
See a great description on it here: http://forums.asp.net/p/1062555/1529151.aspx
Wednesday, October 10, 2007
How to place non-html comments in an aspx file
< % - - whatever the comment is - - % > Remember there are no spaces between the < and the -
Tuesday, October 9, 2007
Update SQL Syntax
Allows you to update records in a database. You typically will want to update a record using the where clause.
UPDATE tablename
SET columnfield = [parameter/value], columnfield2 = [parameter2/value2] = expression2, ....
[ WHERE expression ]
[ LIMIT limit_amount ]
Example:
Note, this has been altered for protection
-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Joe Bailey
-- Create date: 10/09/2007
-- Description: Updates the values from the xyz database
-- =============================================
CREATE PROCEDURE [dbo].[xyz_Update]
-- Add the parameters for the stored procedure here
@xyzID integer,
@xyzName nvarchar(200),
@xyzPage nvarchar(500),
@xyzPageTitle nvarchar(500),
@xyzMetaDescription nvarchar(1000),
@xyzMetaKeywords nvarchar(1000)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE xyzSET
xyzName = @xyzName,
xyzPage = @xyzPage,
xyzPageTitle = @xyzPageTitle,
xyzMetaDescription = @xyzMetaDescription,
xyzMetaKeywords = @xyzMetaKeywords
WHERE xyzID = @xyzID
END
GO
Stored Procedure Guidelines
proc_[maintable][function(optional)]_insert - Insert
proc_[maintable][function(optional)]_select - Select
proc_[maintable][function(optional)]_delete - Delete
proc_[maintable][function(optional)]_update - Update
Select Example:
-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Joe Bailey
-- Create date: 10/09/2007
-- Description: Gathers all values from the xyz database
-- =============================================
CREATE PROCEDURE [dbo].[xyz_Select]
-- Add the parameters for the stored procedure here
@xyzID int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT xyzName,xyzPage, xyzPageTitle, xyzMetaDescription, xyzMetaKeywords
FROM XYZ
WHERE xyzID=@xyzID
END
GO
Monday, October 8, 2007
HTML showing up in my data grid
To fix, I added
HtmlEncode="false"
To the boundfield, this fixed everything.
Standard steps for creating an administrative form
Grid View
- Add SQL Datasource client
- Add Grid
- Update the properties of the grid (Skin)
- Set DataSource, set yes to refresh
- Add command field (Select)
- Add Select ImageURL
- Move the select image to the top
- Change Select button type to image
- Find key, set the property to invisible
- Add Delete
- change delete image
- change deleteimage button type to image
- Properties: Change the EmptyDataText to read "There are no records to display." This will display if no records exist.
- Look at all fields. For any fields that contain html tags coming from the database, put
HtmlEncode="false" into the boundfield tag.
Details View
- Add SQL Datasource
- Configure Data source
- Choose "Where"
- Choose unique ID
- Choose =
- Choose Control
- Select the correct control
- make sure to click advanced, this will allow us to create insert, delete, add statements automatically.
- Edit fields in Detail view
- Add Command field for Edit
- Edit - Set button type to button
- Edit - Change buttontext to Update
- Add comand field for Insert
- Insert - Change buttontype to button
- Insert - Change buttontext to Add
- Handle 0 rows - Add EmptyDataTemplate
Adding FckEditor so we can edit large areas of text with the editor
- Go to code view of aspx file
- In page tag at top of page, add the following parameters: ValidateRequest="false" StyleSheetTheme="xyz" Note: Stylesheet theme is optional
Copying and Reusing an existing admin form
- Copy and paste the existing form in Visual Studio
- Rename the new form
- Open up the .aspx file. Change the Inherits value to match the name of your page
- Open up the .aspx.vb file. Change the name of the class to match the name of your page.
- Open the .aspx file in design view
- Go to the initial datasource of the datagrid, click on it to configure the datasource
Friday, October 5, 2007
Working with GridView contol
GridView, asp:boundfield, insertvisible - when working with the control, set this to true or false to state whether or not this field shows up when the user is makeing an insert.
Had a challenge on what to name the uploaded files. Just settled on naming them with a randomly generated name. This doesn't help seo though.
Reminder: after all of this is implemented, because i had a datagrid talking to a dataview, i had to update the datagrid after the items were updated. So, i had to put in code... datagrid.databind() for the _itemupdated and _iteminserted, _itemdeleted.
Ajax, DetailsView, FileUpload, _ItemUploading and _ItemInserting -
Situation: I am allowing a client to upload a graphic. To make things convenient, I want them to see the graphic.
Challenge: The fileUpload does not fill in or show the client the file name. Plus, when they click on the update, i don't have a filename to reference, so it deletes the filename that was there before.
Solution:
When uploading a graphics file, i had to do a workaround.
I've added a couple of new lines in the update view:
- IMG - An image to show the graphic
- asp:label - I'm using this to display the file name. I'm also using this as a reference to the id of the record. This way, I can take this value and put it in place of the value for the fileupload filename.
In the code behind, I have code that handles it. Here is an example:
Dim fupTemp As FileUpload = CType(sender.findControl("fupx"), FileUpload)
If fupTemp.HasFile Then
Dim sPath = sImagePath & fupTemp.FileName
fupTemp.SaveAs(sPath)
e.NewValues("filename") = fupTemp.FileName
Else
Try
e.NewValues("filename") = CType(sender.findControl("imgFileName"), Label).Text
Catch ex As Exception
e.NewValues("filename") = "transparent.gif"
End Try
End If