C# - Referencing One Aspx.cs Class In Another Aspx.cs Class?
Aug 29, 2010Does anyone know how to reuse the code from one aspx.cs class in another aspx page?
View 5 RepliesDoes anyone know how to reuse the code from one aspx.cs class in another aspx page?
View 5 RepliesGetting error when referencing a public method of Class1.cs (not in App_Code) in Default.aspx.cs.
View 5 RepliesIs there any way to list all the class in my ASP.Net application(Including class in App_Code and Partial Class(aspx pages and asmx user controls)
View 3 RepliesI have a 'classic' ASP.NET app (.NET 3.5) with a pretty standard runat="server" style form with server-side controls and an 'Execute' asp:button. In the code-behind, the executeButton_click handler processes some of the other controls, runs a report, and drops the result into an asp:label. So the effect of pressing the Execute button is that the entire page reloads with the report inserted into the label.
I need to change this so that when the Execute button is pressed, the report pops up in a new window with a different layout (ie without the controls and form). If I was doing this in an MVC framework I would just change the view template in the 'execute' action, so the analogue for ASP.NET would be change the code in front, ie the .aspx file that gets used, from the code-behind class.
Is this possible? I know the link between the .aspx and the .aspx.cs isn't extremely tight as it is possible to reuse a code-behind class in multiple .aspx files. So can I set the .aspx file to render from the code-behind?
i want to know, can one aspx page have two or more code behind page?
like if i have page collge.aspx, by default it will inherit college.aspx.cs, i want to know can't it inherit more then one aspx.cs. If not then why?
I am trying to do something such as:
<%= Class1.GetName %>
in my ASPX page, but my class1.vb can't work like this, I have to declare it first in the aspx page, how can I make my Class1.vb file be shared among the whole website?
I need to pass a string from my .aspx page to my .VB class.
i need to capture (device_category; accept_headers : user_agent) and pass the values to my class, i tryed to captur the values on the clas itself but i got an error(valuse are not member of this class..)
How can i have a string accessable to my class?
I have added a static string variable inside a web page with it's class named VersionBase. The class is public, the variable is public, why can't I simply do VersionBase.MyString from anywhere inside the project like I can do with any other class?
View 13 RepliesI'm just starting out learning ASP.NET. From what I understand, ASP.NET differs from old school ASP in that the logic code for a page exists in as separate file rather then being embedded in the ASP page. So when a user requests a page like ShoppingCart.aspx the server reads the directive at the top ...
<%@ Page Title="" Language="C#" MasterPageFile="~/Styles/Site.Master" AutoEventWireup="true"
CodeBehind="MyShoppingCart.aspx.cs" Inherits="TailspinSpyWorks.MyShoppingCart" %>
This tells the server what file and what class in the file is associated with the page. The code behind class also has member variables that correspond to each control on the page, and provide a way for code in the code behind file to manipulate the controls.
First, do I understand this correctly?
Second, could a site be setup with two separate ASPX pages with identically named controls, which both had a directive pointing to the same file and class? Would you even want to do this? Both pages could have the same functionality but a different layout. I was thinking this could be a way to create separate "desktop" and "mobile" versions of a page with out duplicating content in the code behind files.
I guess ultimately what I'm wondering, is if there a way to define an abstract page? Say create an abstract page definition that says a page must have controls "cart_list", "total_lbl", but then be able to have multiple pages that inherit from this abstract page?
I am on .aspx page and i want to take the width and height of a control from a static class
where i have defined them as constans.
Is there any way to access that class directly from the aspx page?
I know that i can make a method like:
width="<%= getWidthSize() %>"
and inside the aspx.cs to define this method to take the size from that static class.
But i am asking if this could be directly managed from the web aspx page...?
I have a 2D array of doubles in my Default class on my Default.aspx.cs page, like so:
protected Double[,] time;
By the time the page loads, I have populated this array from a database. Now, I want to reference this array in another file (Diff.aspx.cs) to avoid visiting the database again. Also, the data is used in a read-only fashion.
If I'm writing in-line code on a .aspx page is it possible to override the onLoad of the class that the .aspx is directly inheriting from? Right now if I do the override the base.onLoad inline on the .aspx page it is overriding the "Page" object's onLoad event not the class the .aspx is inheriting from.
View 1 Repliesi have a hidden textbox in my aspx page. The aspx page also has a masterpage in the <% @Page> directive.
<input type="hidden" runat="server" name="txtType" id="txtType" />
actually in aspx.cs i am getting txtType.ClientID="ctl00_MainHeaderContent_txtType"
I have a webpart in a webpart zone in this aspx page. In the webpart CreateChildcontrols() I need to access this hiddenTextbox value. I am able to access it as
string TxtValue = this.Page.Request.Form["ctl00_MainHeaderContent_txtType"];
But instead of hardcoding I want to access as a control in the page or form. How can I do that I want to do as looping through the controls in the page but Page.Controls.Count gives 1 and that is MasterPage. How can I get the entire controls in the page and loop through and find the hidden textbox. I also tried as string TxtValue = this.Page.Request.Form["<%=txtType.ClientID%>"] in CreateChildControls() of the webp[art. But could not access hidden textbox like this.
Given an instance of a control SomeControl that is in a some file (could be a usercontrol/ascx, or an aspx) how can I get a reference to the class to which it belongs?
In a usercontrol, SomeControl.NamingContainer seems to be reliable.
In a page that inherits from a MasterPage, this will return a reference to the ContentPlaceHolder, not the actual class that defines the aspx. What I would want in that case is SomeControl.Page
Parent will return the parent control in the heirarchy so isn't much use.
Is there any method for getting this directly regardless of what kind of thing it is?
I have a webpage with a textbox, panel and a DropDownExtender, may plan is to dynamically add labels to the panel on load.
and my plan is to do the dynamic adding of labels in a Class.
so my problem is how can i pass a group Label Controls from a Class to the ASPX page Panel.
I have an c# Class Library where I need some dynamic template based text. Instead of inventing my own template parser I thought I could create an aspx file in my project that is executed at runtime and, instead of viewing the output in a browser, I want a StreamReader or string object that holds the result.
View 3 RepliesIs there a way to call a public function from a class?
[code]....
Is that possible? The reason why am doing this is because I need to parse that variable into a an JQuery function so I wanted JQuery to read that field. Can I Assign that value in base class or I have to do it within default.aspx pageload method?
View 1 RepliesIs it possible to set the Inherits attribute of an ASPX Page directive to a class in an arbitrary assembly?
I need to modify an ASP.NET (1.1) application for which the source code was lost. In a new assembly (foo2.dll) I've created a replacement code-behind class that derives from the original class in the site's code-behind assembly (foo.dll). It seems easy enough to set the Inherits attribute of the Page directive to the new class name, but when I do that the web server gives me Could not load type 'Foo2.checkout2'. I am referencing the new assembly in the <assemblies> section of Web.config.
I don't see anything in the documentation to indicate that this scenario is unsupported, but I'm not certain that it is, either.
Original
<%@ Page Inherits="Foo.checkout" language="c#" Codebehind="checkout.aspx.cs" AutoEventWireup="false" %>
New
<%@ Page Inherits="Foo2.checkout2" CodeFile="checkout2.aspx.cs" CodeFileBaseClass="Foo.checkout" language="c#" Codebehind="checkout.aspx.cs" AutoEventWireup="false" %>
I have a referencing problem in my project. I have an ASP.NET application where pages are in multiple subfolders. All pages user controls are working fine.
I just want to reference a page class that is not in the root folder (in subfolder from the root folder) in my usercontrol code-behind file like this
if (Page is ar_default){ //}Where ar_default is my page class name as it is in folder name "ar"The user control is also in the same subfolder as the page being accessed.Wnen I use the same method with pages in the root folder, there is no problem at all and it is working although I notice that the classes still not appearing in the coding drop down menu but if I typed the name correctly it work.like so:if (Page is _default){ //}When using the same code with classes in subfolders it is giving this error:The type or namespace name 'ar_default' could not be found (are you missing a using directive or an assembly reference?)I'm not using any namespaces also.
I have created a class within the App_Code called shared_methods.vb where I use methods that are frequently used within several pages.
I have a hyperlink control within the masterpage that i want to change the NavigateUrl depedning on what page. Just for better coding i would like to define the variable holding the hyperlink with my shared_method.vb.
I have:
Dim hl_back As HyperLink = CType(Master.FindControl("hl_master_back"), HyperLink)
This works within a page but not within shared_methods.
I have a series of dynamic controls that I'm adding to a page. These are listboxes.
I am adding a handler dynamically e.g. AddHandler listboxname.SelectedIndexChanged, AddressOf listboxSelectedChanged
However, this subroutine looks as follows:
Public Shared Sub listboxSelectedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
I have written a custom membership provider for my MVC 2 app, and it all works fine. I wanted to force people to log in as soon as they went to the site, so set the authorization section of the web config to deny annonymous users. As expected, when you try and access the site, it re-routes you straight to the LogOn.aspx page. The problem I'm having is that when it initially jumps to the LogOn page, it cannot find any of the files referenced in the html header section.
The strange thing is I set a path to a css file as follows:
../../Content/site.css
yet in the page it shows up as
../Content/site.css
I even wrote a html helper that uses Url.Content on the paths passed in, but this still does not solve the problem. If I go to the LogOn page after the application has initially loaded, it references all the files correctly.
Basically I need multiple code-behind files each containing different functions for a page. Different classes do not do this because they are not connected to the page so their methods require parameters I want direct control of the page without the need for parameters.
I can only seem to crete one code-behind file and I need many. I've tried putting the aspx page in the App_Code folder but this causes an error.
i have created basic .aspx files .one is login.aspx and registration.aspx...Now in my solution explorer i also added class file i.e StudentInfo.cs and wrote some properties in it...now my question is
1. i want to connect Studentinfo.cs class to my login.aspx.cs...So that i can call the methods in Studentinfo.cs..how to do it?