Click here to Skip to main content
15,891,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a link buttons on one page.. and again each link button event. i want to put a code

C#
while (dr.Read())
{
  // i am putting the code in different linkbutton events i.e linkbutton1,linkbutton 2
   if(proid == String.Empty)
   {
      proid =  dr["ProductID"].ToString(); 
   }
   else
   {
      proid += "," + dr["ProductID"].ToString();
   }
Response.Redirect("ProductCatalog.aspx?ID="+proid);
//here i want to call a fuction which i have programmed on productcatalog.aspx page..

}


on productcatalog.aspx page

i have different functions

C#
public void less()
{
/*  block of code i use for loading data in grid view */
"Select * from Products where ProductID in ('" + Request.QueryString["ID"].ToString().Substring(1) +"') AND UnitCost <5000;
}



C#
public void more()
{
/*  block of code  i use for loading data in grid view */
"Select * from Products where ProductID in ('" + Request.QueryString["ID"].ToString().Substring(1) +"') AND UnitCost between 5000 and 10000";


how can i call the different the desired method from different linkbuttons on main page
Posted

Move the code from the page into a general DLL file - add a class called GeneralUtilities in your App_Code folder, and put the method in there as a static method. You can then access it from both pages.


"???"


Add a class to app_code.
Call it "GeneralUtilities.cs"
Include your method in this class as a static method:
C#
using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

public static class GeneralUtilities
    {
    public static MyReturnValue Less(MyParameterType myParam)
        {
        ...
        }
    }
You can then access it in both pages.
 
Share this answer
 
v2
Comments
codegeekalpha 30-Dec-11 3:37am    
???
OriginalGriff 30-Dec-11 3:56am    
Answer updated.
In QueryString you can pass like Response.Redirect("ProductCatalog.aspx?ID="+proid + "&less=true");

On target page Load Event

If(Request.QueryString["less"] !=null)
{
if(Convert.ToBoolean(Request.QueryString["less"]))
{
less();
}
else
{
more();
}
}


Hope this will help :)

Thanks
Vinod
 
Share this answer
 
Comments
codegeekalpha 30-Dec-11 5:13am    
why you pas request.querystring["less"] it should b request.querystring["id"]

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