Click here to Skip to main content
15,883,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all ,

i want to have custom constructor for the aspx.cs page.


what my need is i want to pass almost 20 different criteria from search filter page to result page and i don't want to use session variable for each parameter and pass it to next form. can we have some method like windows application form where we create a constructor of a form and pass value by calling it's object and on that form we use those variables.


may be something like this....
C#
public partial class pagename: System.Web.UI.Page
    {
        public pagename(int a ,int b ,string c, string d, datetime f,int g)
        {
              //i get value from here and can use these variable on page load method. 
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }


now when i call this page using response.redirect how can i pass variable to this..or simply any other method to call this page and pass above values..???
Posted
Comments
Sergey Alexandrovich Kryukov 13-Mar-14 1:53am    
What does it mean, "aspx.cs class"? custom constructor? What do you think some constructors are custom and some are not? :-)
And so on...
—SA
ravikhoda 13-Mar-14 1:58am    
well what i want to say that can we do something like above ...please see my code sample...aspx.cs class means the code file of aspx page and custom constructor means that can we do such thing and pass our values from one page to other page...
Sergey Alexandrovich Kryukov 13-Mar-14 2:13am    
Pages are independent, run in different address spaces, so you can only pass anything serializeable...
—SA

1 solution

1.If you want to use Page.Response.Redirect() you could use query string to send data between pages.

2.But you could use Server.Transfer() and in this case you could use Context cache to transfer data between pages like in the next example:

C#
this.Context.Items.Add("stepID", this.Page.Request["stepID"]);
                this.Context.Items.Add("processName", this.Page.Request["processName"]);
                this.Context.Items.Add("taskListType", this.Page.Request["TaskListType"]);
                this.Context.Items.Add("taskID", this.Page.Request["taskID"]);
                this.Context.Items.Add("taskType", this.Page.Request["taskType"]);
//
                this.Server.Transfer(this.Page.Request["pageURL"].ToString());
 
Share this answer
 
Comments
ravikhoda 13-Mar-14 4:18am    
okay this looks good , i dont want to pass around 20 variables in querystring but i will try above method ..Thanks..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900