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(object sender, EventArgs e)
{
string category;
// This will look for value of "ddlCategory" in the current
request stream
category = HttpContext.Current.Request.Form["ddlCategory"];
index = getIndexZeroItem();
if (!category.Equals(getIndexZeroItem()))
{
HttpContext.Current.Response.Redirect("./sculpture2.aspx?catID="
+ category);
}
}
public static string getIndexZeroItem()
{
// 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*******@gmail.com>
???????:11*********************@u72g2000cwu.google groups.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 OnSelectedIndexChanged 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 OnSelectedIndexChanged 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]