I am learning C# and asp.net and am trying to create a new utility
class.
The default code you get from vwd express is:
/// <summary>
/// Summary description for ddlCode
/// </summary>
public class someClass
{
public someClass()
{
//
// TODO: Add constructor logic here
//
}
}
If I have a method, for example txtBoxSubmit, that assigns a variable
(string txtData) from txtBox.text, where do I put that code in the
above scaffold? Can it have an empty constructor?
Thanks! 5 3322
You may have a constructor which accepts a string as parameter to make it
reusable on other places (compatible for exposing read-only property of the
string so others can't change it once the object is created), or have a
empty constructor and a property that let you change that value. It's
basically a choice of designing how you want to make it work.
Empty constructor is legal of course, just meaning this class won't do any
custom initialization when it's created.
And I don't prefer to have control names explicitly coded into classes other
than the webform itself, to preserve reusability and code cleaness.
"Ranginald" <da*******@gmai l.com>
???????:11***** *************** **@i39g2000cwa. googlegroups.co m... I am learning C# and asp.net and am trying to create a new utility class.
The default code you get from vwd express is:
/// <summary> /// Summary description for ddlCode /// </summary> public class someClass { public someClass() { // // TODO: Add constructor logic here //
} }
If I have a method, for example txtBoxSubmit, that assigns a variable (string txtData) from txtBox.text, where do I put that code in the above scaffold? Can it have an empty constructor?
Thanks!
On that note, I was hoping you or someone could assist me with the
following small problem:
I have a .ascx user control that declares a dropdownlist, ddlCategory,
and populates it from a sqlserver database. That works fine.
I am trying to create a common class for a method, runCategory, that
executes at the OnSelectedIndex Changed of the above user control
dropdown list. If I put this runCategory() in the control's own
codebehind file, along with the instantiation code, all is well..
BUT.......I want to use this situation as to learn how to create a
simple asp.net C# class. l know that I could just put this
ddlCategory() method into the .ascx code file without any trouble and
it will work but that defeats the learning purpose for me here.
I am doing nothing in design view and I want to have it all in code.
So when I try to put the OnSelectedIndex Changed functionality into its
own class, I get a "the name 'ddlCategory; does not exist in the
current context". I also get a "the name 'response' does not exist in
the current context..."
Could someone please explain why this behavior is occuring and how to
fix it?
=============== =============
Here is the code (it's really simple):
/**** file = ddlCode.cs ********
/
/// <summary>
/// Summary description for ddlCode
/// </summary>
public class ddlCode
{
public ddlCode()
{
//
// TODO: Add constructor logic here
//
}
public void runCategory(obj ect sender, EventArgs e)
{
string category;
category = ddlCategory.Sel ectedValue;
int index;
index = ddlCategory.Sel ectedIndex;
if (index != 0)
{
Response.Redire ct("./sculpture2.aspx ?catID=" + category);
}
}
I am not declaring a new namespace in the .ascx.cs file (if that helps
at all).
Thanks,
David
I acutally get the same message in if I combine it all into one file
(the ddlCategory error).
The partial class is public, the page_load is public, and runcategory
is public.
Thanks.
So you want to create a generic static method for runCategory?
But unfortunately, static method (or external objects) don't have direct
access to the current webform, so some workarounds are needed.
Something like this (Disclaimer: I wrote this in .NET v1.1, although it
should work in v2.0 too):
public static void runCategory(obj ect sender, EventArgs e)
{
string category;
// This will look for value of "ddlCategor y" in the current
request stream
category = HttpContext.Cur rent.Request.Fo rm["ddlCategor y"];
index = getIndexZeroIte m();
if (!category.Equa ls(getIndexZero Item()))
{
HttpContext.Cur rent.Response.R edirect("./sculpture2.aspx ?catID="
+ category);
}
}
public static string getIndexZeroIte m()
{
// implements this yourself to retrieve the first item in
dropdownlist, you may
// cheat by pushing this value in Session when you create the
dropdownlist
}
"Ranginald" <da*******@gmai l.com>
???????:11***** *************** *@u72g2000cwu.g ooglegroups.com ... On that note, I was hoping you or someone could assist me with the following small problem:
I have a .ascx user control that declares a dropdownlist, ddlCategory, and populates it from a sqlserver database. That works fine.
I am trying to create a common class for a method, runCategory, that executes at the OnSelectedIndex Changed of the above user control dropdown list. If I put this runCategory() in the control's own codebehind file, along with the instantiation code, all is well..
BUT.......I want to use this situation as to learn how to create a simple asp.net C# class. l know that I could just put this ddlCategory() method into the .ascx code file without any trouble and it will work but that defeats the learning purpose for me here.
I am doing nothing in design view and I want to have it all in code.
So when I try to put the OnSelectedIndex Changed functionality into its own class, I get a "the name 'ddlCategory; does not exist in the current context". I also get a "the name 'response' does not exist in the current context..."
Could someone please explain why this behavior is occuring and how to fix it? [Code removed]
Opps... forgotten to remove the following line...
index = getIndexZeroIte m();
"Lau Lei Cheong" <le****@yehoo.c om.hk> ¼¶¼g©ó¶l¥ó·s»D: uj************* *@TK2MSFTNGP03. phx.gbl... So you want to create a generic static method for runCategory?
But unfortunately, static method (or external objects) don't have direct access to the current webform, so some workarounds are needed.
Something like this (Disclaimer: I wrote this in .NET v1.1, although it should work in v2.0 too):
public static void runCategory(obj ect sender, EventArgs e) { string category; // This will look for value of "ddlCategor y" in the current request stream category = HttpContext.Cur rent.Request.Fo rm["ddlCategor y"]; index = getIndexZeroIte m(); if (!category.Equa ls(getIndexZero Item())) {
HttpContext.Cur rent.Response.R edirect("./sculpture2.aspx ?catID=" + category); } }
public static string getIndexZeroIte m() { // implements this yourself to retrieve the first item in dropdownlist, you may // cheat by pushing this value in Session when you create the dropdownlist }
"Ranginald" <da*******@gmai l.com> ???????:11***** *************** *@u72g2000cwu.g ooglegroups.com ... On that note, I was hoping you or someone could assist me with the following small problem:
I have a .ascx user control that declares a dropdownlist, ddlCategory, and populates it from a sqlserver database. That works fine.
I am trying to create a common class for a method, runCategory, that executes at the OnSelectedIndex Changed of the above user control dropdown list. If I put this runCategory() in the control's own codebehind file, along with the instantiation code, all is well..
BUT.......I want to use this situation as to learn how to create a simple asp.net C# class. l know that I could just put this ddlCategory() method into the .ascx code file without any trouble and it will work but that defeats the learning purpose for me here.
I am doing nothing in design view and I want to have it all in code.
So when I try to put the OnSelectedIndex Changed functionality into its own class, I get a "the name 'ddlCategory; does not exist in the current context". I also get a "the name 'response' does not exist in the current context..."
Could someone please explain why this behavior is occuring and how to fix it? [Code removed]
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Lefevre |
last post by:
Hello
I recently had troubles with a class inheritance hierarchy.
I solved it, but it didn't satisfied me.
I found the solution using this forum :)
Actualy i found the following message (with no responces associated) :
|
by: Jun |
last post by:
I have following script
<script>
var Animal = function(name){
this.name = name;
}
Animal.prototype.eat = function (food)
{
|
by: Fabian Müller |
last post by:
Hi all,
my question is as follows:
If have a class X and a class Y derived from X.
Constructor of X is X(param1, param2) .
Constructor of Y is Y(param1, ..., param4) .
|
by: Nafai |
last post by:
Hello. I want to do something like this:
class A { // It's virtual
protected:
float* data;
int n;
public:
A(int a);
virtual float* createData();
//...
|
by: Matt |
last post by:
I try to compare the default constructor in Java and C++.
In C++, a default constructor has one of the two meansings
1) a constructor has ZERO parameter
Student()
{ //etc...
}
2) a constructor that all parameters have default values
| |
by: Martin Oddman |
last post by:
Hi,
I have a compiling problem. Please take a look at the code below.
I have an application that is built upon three tiers: one data tier
(Foo.DataManager), one business tier (Foo.Kernel) and one web
presentation tier (Foo.WebFiles). The data tier shall only be
accessible thru the business tier so I do NOT want a reference to
the data tier in the presentation tier.
In the business tier I have a class with the name CategoryItem that...
|
by: Player |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello all.
I am in the process of teaching myself C# and I think I am doing OK.
I have learnt how to how to call the right constructor of a class, if the
class has more than than one cosntructor, by making sure that each
constructor has a different signature. I have managed to learn that and get
|
by: Ben Blank |
last post by:
I'm writing a family of classes which all inherit most of their methods and
code (including constructors) from a single base class. When attempting to
instance one of the derived classes using parameters, I get CS1501 (no method
with X arguments). Here's a simplified example which mimics the
circumstances:
namespace InheritError {
// Random base class.
public class A {
protected int i;
|
by: Andrew J. Marshall |
last post by:
I want to create a class that must receive a parameter when instantiated.
In other words, I do not want it to have a "Public Sub New()".
1) Does VB.NET create a default public constructor if I do not declare one?
2) I've read that I can have a "Private Sub New()" which should take care of
my needs. Comments?
Thanks,
Andrew
|
by: JosephLee |
last post by:
In Inside C++ object Model, Lippman said there are four cases in which
compile will sythesize a default constructor to initialize the member
variables if the constructor is absent:
1. there is a virtual function;
2. virtual inheritance;
3.base class with explicit default constructor;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |