调用所需的函数(方法从一页到另一页) [英] calling the desired function(Method from one page to another)

查看:85
本文介绍了调用所需的函数(方法从一页到另一页)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一页上有一个链接按钮..以及每个链接按钮事件.我想输入一个代码

i have a link buttons on one page.. and again each link button event. i want to put a code

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..

}



在productcatalog.aspx页面上

我有不同的功能



on productcatalog.aspx page

i have different functions

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;
}







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

推荐答案

将页面中的代码移动到通用DLL文件中-在以下位置添加一个名为GeneralUtilities的类您的App_Code文件夹,然后将该方法作为静态方法放在其中.然后,您可以从两个页面访问它.


"???"


将一个类添加到app_code.
称之为"GeneralUtilities.cs"
将您的方法作为静态方法包括在此类中:
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:
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.


在QueryString中,您可以像Response.Redirect("ProductCatalog.aspx?ID =" + proid +& less = true);

在目标页面上加载事件

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();
}
}



希望这会有所帮助:)

谢谢
Vinod



Hope this will help :)

Thanks
Vinod


这篇关于调用所需的函数(方法从一页到另一页)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆