•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 374,167 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,305 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1414 | Replies: 8 | Solved
![]() |
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hey,
I have a this readblog.cs file in projects App_Code folder, and at main folder I have Blog.aspx -> Blog.aspx.cs file.
And I have a Table control in Blog.aspx file, called Bloglist, and I am trying to modify it from App_Code/readblog.cs class file and I dont know how to use Using statements or something like that to get reference so I could use Bloglist at App_Code folder? . here's a snippet from both of files->
----------------------------
Down under App_Code/readblog.cs
----------------------------
and somewhere down here is that this.Bloglist item, and it doesnt find it (of course, cause theres not a reference to the Blog.aspx.cs file, and I dont know how to do it? I have tryed namespaces and etc, maeby im just confused cause its in the App_Code folder
----------------------------
Down under blog.aspx.cs
----------------------------
THX! <- Noob!
I have a this readblog.cs file in projects App_Code folder, and at main folder I have Blog.aspx -> Blog.aspx.cs file.
And I have a Table control in Blog.aspx file, called Bloglist, and I am trying to modify it from App_Code/readblog.cs class file and I dont know how to use Using statements or something like that to get reference so I could use Bloglist at App_Code folder? . here's a snippet from both of files->
----------------------------
Down under App_Code/readblog.cs
----------------------------
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.IO; /// <summary> /// Summary description for readblog /// </summary> /// public class readblog
----------------------------
Down under blog.aspx.cs
----------------------------
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class Blog : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
}
else
{
readblog rb = new readblog("blogs.xml");
}
}
}THX! <- Noob!
Last edited by peter_budo : Feb 4th, 2008 at 12:21 pm. Reason: Please use code tags even for code snippets
•
•
Join Date: Feb 2008
Location: Atlanta
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 1
When using a website project, you don't need to worry about namespaces. Anything in App_Code is automatically available in the pages in the rest of the site (for better or worse).
The code you posted should work (assuming readblog has a constructor that accepts a string parameter). Are you getting a compilation error?
The code you posted should work (assuming readblog has a constructor that accepts a string parameter). Are you getting a compilation error?
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
When using a website project, you don't need to worry about namespaces. Anything in App_Code is automatically available in the pages in the rest of the site (for better or worse).
The code you posted should work (assuming readblog has a constructor that accepts a string parameter). Are you getting a compilation error?
Yeah it works that way, no problem in there, but other way around.
I have this code in App_Code/readblog.cs file
void RebuildBlogPage(DataSet ds)
{
//string prevUser = ""; //Etsitään edellinen user
foreach (DataRow dr in ds.Tables[0].Rows)
{
//Lisää topic
TableRow tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].CssClass = "h3";
tr.Cells[0].Text = dr[0].ToString();
this.BlogTable.Rows.Add(tr);
//Lisää date
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].CssClass = "h5";
tr.Cells[0].Text = Convert.ToString(dr[1].ToString()) + " by " +
dr[3].ToString();
this.BlogTable.Rows.Add(tr);
//Lisää BLog
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].Width = 200;
tr.Cells[0].CssClass = "textblog";
tr.Cells[0].Text = dr[2].ToString();
this.BlogTable.Rows.Add(tr);
//lisätään separator
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].ColumnSpan = 2;
this.BlogTable.Rows.Add(tr);
}Error ->
'readblog' does not contain a definition for 'BlogTable' and no extension method 'BlogTable' accepting a first argument of type 'readblog' could be found (are you missing a using directive or an assembly reference?)
And that BlogTable is at ~/Blog.aspx file?
•
•
Join Date: Feb 2008
Location: Atlanta
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 1
I'm assuming that's some code that's been moved from an ASPX page's code behind into its own class? It sounds like BlogTable was a control on that page.
If so, what you probably need to do is have RebuildBlogPage return a Table. Something like:
Then, in your ASPX page, you would add the return value of that method to the controls collection of your page, placeholder, panel, or whatever you're using for layout.
If so, what you probably need to do is have RebuildBlogPage return a Table. Something like:
Table RebuildBlogPage(DataSet ds)
{
//string prevUser = ""; //Etsitään edellinen user
Table BlogTable = new Table();
foreach (DataRow dr in ds.Tables[0].Rows)
{
//Lisää topic
TableRow tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].CssClass = "h3";
tr.Cells[0].Text = dr[0].ToString();
BlogTable.Rows.Add(tr);
//Lisää date
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].CssClass = "h5";
tr.Cells[0].Text = Convert.ToString(dr[1].ToString()) + " by " +
dr[3].ToString();
BlogTable.Rows.Add(tr);
//Lisää BLog
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].Width = 200;
tr.Cells[0].CssClass = "textblog";
tr.Cells[0].Text = dr[2].ToString();
BlogTable.Rows.Add(tr);
//lisätään separator
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].ColumnSpan = 2;
BlogTable.Rows.Add(tr);
}
return BlogTable;
}Then, in your ASPX page, you would add the return value of that method to the controls collection of your page, placeholder, panel, or whatever you're using for layout.
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Now we are getting to point. But my knowledge is not enough yet, ill past both codes here
Blog.aspx.cs
and App_Code/readblog.cs
Now it's mixed with that return table. Everything else is original, i tried somethings. Now I have to return that table over to Blog.cs somehow....? Thx allready, it would be nice if i could figure it out on my own, but just cant
Blog.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class Blog : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
}
else
{
readblog rb = new readblog("blogs.xml");
}
}
protected void WriteBlog1_Click(object sender, EventArgs e)
{
this.Response.Redirect("WriteBlog.aspx");
}
}and App_Code/readblog.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public class readblog
{
public readblog()
{
//
// TODO: Add constructor logic here
//
}
public readblog(string xmlfilename)
{
DataSet ds = ReadBlogIntoTable(xmlfilename);
if ((bool)HttpContext.Current.Session["Changed"])
{
AppendBlogs(ds, xmlfilename);
WriteXmlBlog(ds, xmlfilename);
HttpContext.Current.Session["Changed"] = false;
}
RebuildBlogPage(ds);
}
private DataSet ReadBlogIntoTable(string xmlfilename)
{
DataSet ds = new DataSet();
string filename = HttpContext.Current.Server.MapPath(".\\App_Data\\") + xmlfilename;
if (File.Exists(filename))
{
ds.ReadXml(filename); //Jos on niin luetaan tiedosto datasettiin ja palautetaan se
}
else
{
DataTable dt = new DataTable("Contents");
ds.Tables.Add(dt);
dt.Columns.Add("Topic", Type.GetType("System.String"));
dt.Columns.Add("Time", Type.GetType("System.DateTime"));
dt.Columns.Add("Content", Type.GetType("System.String"));
dt.Columns.Add("Writer", Type.GetType("System.String"));
}
return ds;
}
void AppendBlogs(DataSet ds, string xmlfilename)
{
DataRow dr = ds.Tables["Contents"].NewRow();
dr[0] = HttpContext.Current.Session["Topic"];
dr[1] = DateTime.Now;
dr[2] = HttpContext.Current.Session["Content"];
dr[3] = HttpContext.Current.Session["Writer"];
ds.Tables["Contents"].Rows.Add(dr);
WriteXmlBlog(ds, xmlfilename);
}
private void WriteXmlBlog(DataSet ds, string xmlfilename)
{
string filename = HttpContext.Current.Server.MapPath(".\\App_Data\\") + xmlfilename;
ds.WriteXml(filename);
}
Table RebuildBlogPage(DataSet ds)
{
Table BTable = new Table();
foreach (DataRow dr in ds.Tables[0].Rows)
{
TableRow tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].CssClass = "h3";
tr.Cells[0].Text = dr[0].ToString();
BTable.Rows.Add(tr);
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].CssClass = "h5";
tr.Cells[0].Text = Convert.ToString(dr[1].ToString()) + " by " +
dr[3].ToString();
BTable.Rows.Add(tr);
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].Width = 200;
tr.Cells[0].CssClass = "textblog";
tr.Cells[0].Text = dr[2].ToString();
BTable.Rows.Add(tr);
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].ColumnSpan = 2;
BTable.Rows.Add(tr);
}
return BTable;
}
}Now it's mixed with that return table. Everything else is original, i tried somethings. Now I have to return that table over to Blog.cs somehow....? Thx allready, it would be nice if i could figure it out on my own, but just cant
•
•
Join Date: Feb 2008
Location: Atlanta
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 1
Okay, with that in mind, things are going to be a little different.
Doing something like this for your readblog class would be a step in the right direction:
Then, in Blog.aspx.cs, you could add that table to the page like this:
Before going too far, it might not hurt for you to take a look at some tutorials on object oriented design and programming. That's what's at the heart of this. Getting off to the right start with it will make things go much more smoothly.
Doing something like this for your readblog class would be a step in the right direction:
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
public class readblog
{
private DataSet _blog;
public readblog(string xmlfilename)
{
_blog = ReadBlogIntoTable(xmlfilename);
if ((bool)HttpContext.Current.Session["Changed"])
{
AppendBlogs(xmlfilename);
WriteXmlBlog(xmlfilename);
HttpContext.Current.Session["Changed"] = false;
}
}
private DataSet ReadBlogIntoTable(string xmlfilename)
{
DataSet ds = new DataSet();
string filename = HttpContext.Current.Server.MapPath(".\\App_Data\\") + xmlfilename;
if (File.Exists(filename))
{
ds.ReadXml(filename); //Jos on niin luetaan tiedosto datasettiin ja palautetaan se
}
else
{
DataTable dt = new DataTable("Contents");
dt.Columns.Add("Topic", Type.GetType("System.String"));
dt.Columns.Add("Time", Type.GetType("System.DateTime"));
dt.Columns.Add("Content", Type.GetType("System.String"));
dt.Columns.Add("Writer", Type.GetType("System.String"));
ds.Tables.Add(dt);
}
return ds;
}
void AppendBlogs(string xmlfilename)
{
DataRow dr = _blog.Tables["Contents"].NewRow();
dr[0] = HttpContext.Current.Session["Topic"];
dr[1] = DateTime.Now;
dr[2] = HttpContext.Current.Session["Content"];
dr[3] = HttpContext.Current.Session["Writer"];
_blog.Tables["Contents"].Rows.Add(dr);
WriteXmlBlog(xmlfilename);
}
private void WriteXmlBlog(string xmlfilename)
{
string filename = HttpContext.Current.Server.MapPath(".\\App_Data\\") + xmlfilename;
_blog.WriteXml(filename);
}
public Table RebuildBlogPage()
{
Table BTable = new Table();
foreach (DataRow dr in _blog.Tables[0].Rows)
{
TableRow tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].CssClass = "h3";
tr.Cells[0].Text = dr[0].ToString();
BTable.Rows.Add(tr);
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].CssClass = "h5";
tr.Cells[0].Text = Convert.ToString(dr[1].ToString()) + " by " +
dr[3].ToString();
BTable.Rows.Add(tr);
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].Width = 200;
tr.Cells[0].CssClass = "textblog";
tr.Cells[0].Text = dr[2].ToString();
BTable.Rows.Add(tr);
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].ColumnSpan = 2;
BTable.Rows.Add(tr);
}
return BTable;
}
}Then, in Blog.aspx.cs, you could add that table to the page like this:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class Blog : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
}
else
{
readblog rb = new readblog("blogs.xml");
Page.Controls.Add(rb.RebuildBlogTable());
}
}
protected void WriteBlog1_Click(object sender, EventArgs e)
{
this.Response.Redirect("WriteBlog.aspx");
}
}Before going too far, it might not hurt for you to take a look at some tutorials on object oriented design and programming. That's what's at the heart of this. Getting off to the right start with it will make things go much more smoothly.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
- ASP.NET wizard control (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Watermarking images and AJAX,FLASH
- Next Thread: permission denied error



Linear Mode