How To Create A PageBase Class
Sep 24, 2010
I am trying to create a pageBase class where I can dynamically pull data from the database and display it on a web page. Each page I specifically set an ID for the sql query which pulls back the information such as page title and page text.
my problem is that I can't seem to pass the information captured from the query to the page. I get problems such as can't convert string type to literal and I need to declare a new keyword to an object.
PageBase Class
Csharp Code:
[code]....
View 3 Replies
Similar Messages:
Sep 2, 2010
I've inherited (no pun intended) an old ASP.NET 1.1 project that is now .NET 3.5. It is designed with base class that inherits from PageBase. All of the subsequent aspx pages inherit from this custom pagebase. It currently works by generating a bunch of html text in LiteralControls for the headers and navigation bars and dropping it into an HtmlGenericControl (in this case called 'page'), which is then displayed on the page by using this.Controls.Add(page); This actually works, except for the following output:
<span>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
...
</html>
</span>
Those span's aren't supposed to be there obviously, but they come from the HtmlGenericControl, which defaults to a tagName of span. This is causing some strange behavior in IE regarding centering controls on the page.
Basically I know I should be using masterpages for this type of thing, but I don't have time to switch this all over, and I'm not an ASP.NET expert yet to where I know exactly how to solve this problem. Is there another way of sending literal text directly to the HTML output without wrapping it in a control? Obviously I need the DocType to be the first thing on the page; nothing wrapping it.
View 2 Replies
May 26, 2010
I am tring to access a custom property on my Master page in a custom PageBase that resides in the App_Code folder. I can get this to work no problem in a web app but im having trouble doing it in the website project.
PageBase:
public abstract class PageBase : ClientSidePageBase
{
public WebMessage Message
{
get
[code]...
The above sample is what is in my web application and works fine but if i try and put this in the App_Code it doesnt pick up the MasterPage class so I cant access the property.
View 1 Replies
Feb 16, 2010
I have a class that derives from System.Web.UI.Page and have set my pages to derive from this custom page class instead of Page. At runtime, the controls are never initialized and throw a NullReferenceException. I've changed some class names and namespaces in the pasted code to protect the innocent. The only thing that I currently override in my PageBase is OnPreLoad and I do call the base.OnPreLoad. I'll eventually add more functionality to this PageBase but for now all that it has is this:
[Code]....
I've tried putting this into a class library (with System.Web referenced) and I've also tried moving the class into the web application and had the same results either way. As another strange twist, I have another class with derives from PageBase called IndexPageBase and it doesn't have this problem:
[Code]....
[Code]....
[Code]....
View 7 Replies
May 19, 2010
Should we create a class for every form we create,that will us to do the validations etc etc?
View 1 Replies
Jul 23, 2010
All I want to do is learn how to create a class procedure. And then. How to call it. As an example, A + B = C is the procedure. I would create a class. Right? Then do I name the procedure and put it in the class? Or create a new class for each procedure? Then I would want to, on a local level, substitue values for A & B to return C. So, if the public procedure exists, how to I call it? I know that this is really simple stuff, but I need examples to be simple.
View 1 Replies
Apr 4, 2011
A instance of a class is created in the partial class of an aspx page.Under page_load or button click method I'm trying to set the value to the class. but when each postback takes place new instance is created and I'm losing the previous value.
public partial class DatabaseSelection : System.Web.UI.Page
{
DBProperties dbpro;
Metadata obmeta;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dbpro = new DBProperties();
}
View 4 Replies
Jan 26, 2011
My ultimate goal is to create a UserControl in a class in my App_Code folder and render the html from that into a string.
The rending of HTML can be done using this example I believe:
How do I get the HTML output of a UserControl in .NET (C#)?
My Question:
I created my user control
public partial class Controls_MyUserControl : System.Web.UI.UserControl
I've registered it in my web.config
<add tagPrefix="UC" src="~/Controls/MyUserControl.ascx" tagName="MyUserControl" />
I can reference this on a page just fine
<UC:MyUserControl ID="MyUserControl1" runat="server" />
Yet when I try to create an object of this control type in a class (in my app_code folder) it doesn't allow me.
Controls_MyUserControl dummy = new Controls_MyUserControl();
The potentially strange thing is when I put this code into a code behind of a page, it works.
what I need to do to have the usercontrol to be able to be created in my class in the app_code folder?
My guess is, is that I need to reference the control in a "using" statement at the top, but I'm not sure what that'd be.
It's not in a namespace to my knowledge (at least there's no namespace, in the code behind of the actually user controls). Though I'm not sure if it inherits one from the System.Web.UI.UserControl.
View 1 Replies
Sep 18, 2010
I am using vs 2010, mvc, linq to sqlMy Model is .dbmliletbl_teacher,tbl_class,tbl_subject etc are involvedI write code in my controller for table join.
[Code]....
View 5 Replies
Jan 23, 2010
i have tables like Lookup and lookupvalues in the lookup table like and lookup values like
LookupId LookupName | lookupValueId lookupId Name
1 Country | 1 1 Usa (country)
2 State | 2 2 All(state)
3 Relation | 3 2 Colarado (state)
4 3 agenttoClient(relation)
now i want create enum class form databse
my req is
enum lookup{
Country,state,Relation(these should be come from Databse when ever application intialised)
}
now i able acces lookupvalues
lookup.country.1=>USa
lookup.State.1=>All
lookup.State.2=>Colorado
lookup.Relation.1=>Agent to client
View 1 Replies
Apr 10, 2010
i have a table ("WebSettings") that have some information about Website like what is the name of website which theme use and so on i want to creat a class to return the website settings can you give me some information obot what is the best way in this case to get the informations and how can i creat this class?
View 1 Replies
Feb 24, 2010
I am using Visual Studio 2008 with .Net 2.0
I am maintaining and old application in ASP.Net and it has one CustomGridView control with 4000 lines of code. I see that in that file only, when I try to modify any code the IDE does not respond quickly as it does for other files. I thought of creating partial classes for the same but it seems that VS is not reconginzing the new partial class. I am trying to use the variables from the old partial class and it is not able to reconize any variable or method.
View 5 Replies
Feb 26, 2011
May i know how to create Component class in asp.net.i was used the following code in VB.net but inASP.net there is no Componentclass file in
Add->Newitem
(how to create textbox with only your can enter numbers only)
My code to create text that only accept Number and also some color change.................
Public Class ZillisisNumberTextBox
Inherits TextBox
Private Sub ZillisisNumberTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Enter
Try
Me.BackColor = Color.LemonChiffon
Me.Font = New System.Drawing.Font("Verdana", 8.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ZillisisNumberTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Try
If Not IsNumeric(e.KeyChar) And e.KeyChar <> System.Convert.ToChar(Keys.Back) And e.KeyChar <> System.Convert.ToChar(Keys.Delete) Then
e.Handled = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ZillisisNumberTextBox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave
Try
Me.BackColor = Color.White
Me.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
View 11 Replies
May 24, 2010
i want create a class Library work with SQL Linq ,when i create a LINQ Data Class it automatic create some connectionString and use the database namemy question is can i change some settings that, use this class Library in difrent website with difrent connectionStrings?
View 6 Replies
May 21, 2010
I wanna do smth like this:
[Code]....
Does anyone have a recommendation how this is archievable? I am trying to pass in the Type to the method and then create an instace of it and then access the properties in it.
View 8 Replies
Mar 20, 2010
I have a bit of code I am reusing on a lot of my pages so decided to put this code into a Class and placed this class inside the App_Code directory. However when ever I try and create an instance of tis class so that I can use it's Methods etc I can't seem to get it to work, but if I create the class in the web root for the project it all wrks as expected.
View 12 Replies
May 21, 2010
I was wondering is it possible to create a css class at runtime?
I am unable to use the traditional method of doing so as one of the attributes need to be loaded at runtime.
As I am using the Coolite Toolkit, whenever i need to use a custom image onto one of the controls, the custom image path needs to be loaded in via a stylesheet class.
View 2 Replies
Apr 16, 2010
I am trying to create instance of class by using reflection in ASP.net web site. Class ClassName is defined and located in App_code folder. Following line returns null, what could be wrong.
Type type = Type.GetType("NameSpace.ClassName", false, true);
View 5 Replies
Aug 4, 2010
I have a search page that is used in multiple places with multiple 'themes' throughout my site. I have a few divs that can have their background color changed based on a radio button selection (whether they are enabled or not). I can do this just fine by changing the css class of the div on the fly with javascript.
However, these themes could potentially change, and the background color is grabbed from a database when the page is created. Right now I do this in the C# codebehind:
string bgStyle = "background-color:" +theme.searchTextHeaderColor +";";
OwnerSearchHeader.Attributes.Add("style", bgStyle);
In the Javascript I need to change this color to make it look disabled, and when the user clicks back to this div I need to re-enable it by changing it back to its original color. But since I only knew this color in the code-behind, I don't know what it was in the Javascript.
So my thought was to create a css class in the resulting HTML page when the page is loaded with the background color I need. Then I could simply switch from the divEnabled and divDisabled class in the javascript. But I'm not exactly sure how to do that.
View 2 Replies
May 13, 2010
I'm web dev newbie. I'm trying to create a log file as a separate class that will catch every exception , the thing is I don't much about files, where it is created, the path should be given or not, where is the ideal place to create it
View 3 Replies
Dec 17, 2010
I am trying to create a repository class for each table. For example I have TableA, TableB and TableC. TableB and TableC has Foreign key to TableA. I created an interface for TableA, TableB and TableC with SaveData() and ListData(). I have MVC form which inserts the data into these tables. When implementing these interface methods do I have to create a seperate class for each interface? Please let me if I am doing right.
[code]....
View 2 Replies
Mar 31, 2010
I am trying to compile the following code and i am getting the error:
Cannot create instance of abstract class .
m_objExcel = new Excel.Application();
m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
m_objBook = (Excel._Workbook)(m_objBooks.Add(m_objOpt));
m_objSheets = (Excel.Sheets)m_objBook.Worksheets;
m_objSheet = (Excel._Worksheet)(m_objSheets.get_Item(1));
// Create an array for the headers and add it to cells A1:C1.
object[] objHeaders = {"Order ID", "Amount", "Tax"};
m_objRange = m_objSheet.get_Range("A1", "C1");
m_objRange.Value = objHeaders;
m_objFont = m_objRange.Font;
m_objFont.Bold=true;
// Create an array with 3 columns and 100 rows and add it to
// the worksheet starting at cell A2.
object[,] objData = new Object[100,3];
Random rdm = new Random((int)DateTime.Now.Ticks);
double nOrderAmt, nTax;
for(int r=0;r<100;r++)
{
objData[r,0] = "ORD" + r.ToString("0000");
nOrderAmt = rdm.Next(1000);
objData[r,1] = nOrderAmt.ToString("c");
nTax = nOrderAmt*0.07;
objData[r,2] = nTax.ToString("c");
}
m_objRange = m_objSheet.get_Range("A2", m_objOpt);
m_objRange = m_objRange.get_Resize(100,3);
m_objRange.Value = objData;
// Save the Workbook and quit Excel.
m_objBook.SaveAs(m_strSampleFolder + "Book2.xls", m_objOpt, m_objOpt,
m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange,
m_objOpt, m_objOpt, m_objOpt, m_objOpt);
m_objBook.Close(false, m_objOpt, m_objOpt);
m_objExcel.Quit();
View 2 Replies
Jun 30, 2010
how can i learn propert to create page form in asp.net
class MyClass
{
public int id { get; set;}
public string Name { get; set;}
public string Name { get; set;}
}
ForExample : (To generate programmatically Asp.net forms)
void SetRecursiveTextBoxAndLabels()
{
Label lbl;
MyClass eng = new MyClass();
Type typ = eng.GetType();
PropertyInfo[] properties = typ.GetProperties();
for( int i =0; i<properties.Length; i++)..........
But it is not run correctly:( loading is too slow... By the way i didn't create classıs in real time . i ama using linqtoSql . You can talk about solution wthi the base of linqtosql...
View 1 Replies
Jan 25, 2010
I've been tasked with creating a class that will handle errors in my Web application. I'm told the goal is to have a separate .cs file that can be called to handle any errors that come along. I have no idea where to begin, and I've googled but I don't think I'm googling the right thing because I'm not really finding anything.
View 9 Replies
Apr 22, 2010
We all know that, we cannot create the object of Abstract class.
But why it is so?
I mean, can anyone explain it with real time example?
View 8 Replies