Hey guys,
Herein lies personal code snippets and work-arounds to some tricky asp.net situations.
Please note that I am not some super-awesome coder, and that I will make a few mistakes. I am open to suggestive, and some constructive criticism.
Also, please make requests on what you need done, and I will try make a plan to get there!
I will keep this as updated as possible.
Herein lies personal code snippets and work-arounds to some tricky asp.net situations.
Please note that I am not some super-awesome coder, and that I will make a few mistakes. I am open to suggestive, and some constructive criticism.
Also, please make requests on what you need done, and I will try make a plan to get there!
I will keep this as updated as possible.
CSS : Embedded Fonts
Code:
@font-face {
font-family: 'Summerti'; /* we can name this whatever we want */
src: url(Summerti.eot); /* IE will download this anyway */
src: local('Summertime'), /* It'll ignore this.. */
url(Fonts/Summerti.tff) format('truetype');
}
h1, h2, h3 {
margin: 0;
font-weight: normal
color: #1E3F7F;
font-family: Summerti;
}
@font-face will only work in CSS3
[font-family] Will give the class a header, to call whenever you want.
[src:url] This is for Internet Explorer users. You need to give the relative (or direct) URL to the font.
Font MUST be in oet format. Unfortunatly, IE users will have this font downloaded to their PC for it to be used.
This might override any previous font with that name.
[src:local] IE will ignore this. Give the full NAME (NOT File name) of the font)
URL to the font, and [format] of w...om/downloads/connector/net/5.1.html#downloads
--> Change it to the latest version, and get the MSI installer. Then, copy the required .dll's from the install directory to your project folder. Reference those files.
I put the Connect & Disconnect in different classes, so you only need to call the class eg. ConnectToDatabase();, instead of re-writing.
web.config: ".Net Framework Data Provider. It may not be installed." FIX
Code:
<system.data>
<DbProviderFactories>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.3.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
On my system, I never needed this (And it caused an error) when running it from VS2010. This fix is only for site hosts.
web.config: Just add this
Code:
<system.web>
<customErrors mode="Off"/>
<httpRuntime requestValidationMode="2.0" />
<pages validateRequest="false" />
</system.web
I'm writing this tutorial at 10:03am.. Ill remember why you need this later.
mix : Adding a new Content page, linking to a Master
This is a very arb way of doing it. Will be happy for recommendations on easier ways
Create 2 .txt files
Page.txt
HTML:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Body" Runat="Server">
</asp:Content>
CodeBehind.txt
HTML:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Code:
private void CreatePage()
{
string pageName = txtPageName.Text.Replace("'", "'");
string m = Server.MapPath("../");
string fileLoc = m + pageName + ".aspx";
string filecLoc = m + pageName + ".aspx.cs";
FileStream fs = new FileStream(fileLoc, FileMode.Create);
BufferedStream bs = new BufferedStream(fs);
fs.Close();
FileStream fs1 = new FileStream(filecLoc, FileMode.Create);
BufferedStream bs1 = new BufferedStream(fs1);
fs1.Close();
//Get data for page
//Get data for Page
StreamReader pageRead = new StreamReader(m + "Page.txt");
string page = pageRead.ReadToEnd();
pageRead.Close();
page = page.Replace("Default2.aspx.cs", pageName+".aspx.cs");
//Populate Page
StreamWriter sw = new StreamWriter(fileLoc);
sw.Write(@page);
sw.Close();
//Get data for Code Behind
StreamReader codeRead = new StreamReader(m + "CodeBehind.txt");
string code = codeRead.ReadToEnd();
codeRead.Close();
//Populate Code Behind
StreamWriter swcb = new StreamWriter(filecLoc);
swcb.Write(@code);
swcb.Close();
}
Code:
protected void btnAdd_Click(object sender, EventArgs e)
{
//Create Page method needs to be called here for some reason.
CreatePage();
//Make sure that you have a connection ready to insert Data
ConnectToDatabase();
//This makes sure that you are able to use ', and replaces .aspx with nothing.
string pageName = txtPageName.Text.Replace("'", "'");
pageName = pageName.Replace(".aspx", "");
string title = txtTitle.Text.Replace("'", "'");
string data = txtData.Text.Replace("'", "'");
try
{
//This will make sure the page is added to the database, to be referenced
MySqlCommand cmd = sqlConn.CreateCommand();
cmd.CommandText = @"INSERT INTO pages (heading, data, name) VALUES ('"+@pageName+".aspx','"+@data+"','"+@title+"')";
cmd.ExecuteNonQuery();
DisconnectDatabase();
//Refresh the page
Response.Redirect(Request.Url.AbsoluteUri);
}
catch (MySqlException em)
{
txtData.Text = em.ToString();
}
}
Explanation:
After many diverse ways, the best way I could make a new file, was to manually create a file called [whatever].aspx and [whatever].aspx.cs.
Then, I would copy code out of the 2 text files, and insert it into the 2 newly created files, changing the linked name.
After that, all I needed to do was make sure that the page was referenced in the data base, and voila! Done
Last edited: