开发者

In ASP.net ".aspx" pages placed in subfolder can not access when in click on that specific page in menu

i am using jquery menu on master page. menu containt bind at runtime depend upon user right. in my project ".aspx" pages placed in root folder as well as subfolder ..when i click on page name on menu it redirect me to that specific page which is located in root part of my project. but i can't redirect to pages in subfolder..

target page name is defined in database. on clicking it pick up target url from datatbse and redirect to page.

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using AjaxPro;

public partial class Reports_fleet : System.Web.UI.MasterPage
{
Jetfleet_Framework.clsDataAcess objData = new Jetfleet_Framework.clsDataAcess();
DataSet dsMenu = new DataSet();
HttpBrowserCapabilities objbrowser;
protected void Page_Load(object sender, EventArgs e)
{

    objbrowser = Request.Browser;
    if (objbrowser.Browser == "AppleMAC-Safari")
    {
        loctbl.Style.Add("margin-top", "30px");
        loctbl.Style.Add("margin-left", "-30px");
        sumnu.Style.Add("margin-top", "2px");
    }
    if (objbrowser.Browser == "Firefox")
    {
        loctbl.Style.Add("margin-top", "30px");
        loctbl.Style.Add("margin-left", "-50px");
        sumnu.Style.Add("margin-top", "2px");
    }
    lbl.Text = Session["ServiceLocName"].ToString();
    hdnRelease.Value = Session["Release"].ToString();
    hdnCloseWindow.Value = Session["userId"].ToString();
    Utility.RegisterTypeForAjax(typeof(Reports_fleet));
    Response.Buffer = true;
    Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
    Response.Expires = -1500;
    Response.Cache.SetNoStore();
    Response.CacheControl = "no-cache";
    if (Session["userId"] == null)
    {
        Response.Redirect("LogIn.aspx");
    }

    //name.InnerHtml = Session["userFullName"].ToString();
    BuildNavigationMenu();
    name.InnerHtml = Session["userFullName"].ToString();

    if (!this.IsPostBack)
    {
        if (Session["Release"] == "True")
        {
            string spRelease = "usp_ins_upd_task_assign;3";
            Object[] paramRelease = new Object[1];
            paramRelease[0] = (Object)Session["userId"].ToString();

            objData.ExecuteNonQuery(spRelease, paramRelease);
        }
        else
        {
            Session["Release"] = "True";
        }

    }
}

private void BuildNavigationMenu()
{

    //Creates html UL element for menu.
    string uname = "", pass = "", location = "";
    Session["bchk"] = "True";

    int userId = System.Int32.Parse(Session["userId"].ToString());
    int roleId = System.Int32.Parse(Session["userRole"].ToString());
    try
    {
        if (Session["navigation_menu_dataset"] != null)
        {
            dsMenu = (DataSet)Session["navigation_menu_dataset"];

        }
        else
        {
            dsMenu = GetNavigationMenu(userId, roleId);
            Session["navigation_menu_dataset"] = dsMenu;

        }
        uname = Session["userName"].ToString();
        pass = Session["password"].ToString();
        location = Session["loction"].ToString();
        Session["username"] = uname;
        Session["password"] = pass;
        Session["Location"] = location;

        int mnuCount, totalMenus;
        totalMenus = System.Int32.Parse(dsMenu.Tables[1].Rows[0]["total_menus"].ToString());
        HtmlGenericControl divMenu = new HtmlGenericControl("div");
        divMenu.Attributes["id"] = "menu";
        HtmlGenericControl ulMenu = new HtmlGenericControl("ul");
        ulMenu.Attributes["class"] = "menu";

        for (mnuCount = 1; mnuCount <= totalMenus; mnuCount++)
        {
            HtmlGenericControl liMain = new HtmlGenericControl("li");
            if (mnuCount == totalMenus)
            {
                liMain.Attributes["class"] = "last";
            }
            else
            {
                liMain.Attributes["class"] = "parent";
            }
            HtmlGenericControl aMain = new HtmlGenericControl("a");
            aMain.Attributes["href"] = "#";
            HtmlGenericControl spMenu = new HtmlGenericControl("span");
            DataRow[] drMenu = null;

            drMenu = dsMenu.Tables[0].Select("parent_menu_id = " + mnuCount);

            if (drMenu.Length != 0)
            {
                spMenu.InnerHtml = drMenu[0]["parent_menu_name"].ToString();//Masters
                aMain.Controls.Add(spMenu);
                liMain.Controls.Add(aMain);
                HtmlGenericControl divMenu1 = new HtmlGenericControl("div");
                HtmlGenericControl ulMenu1 = new HtmlGenericControl("ul");
                int subMenuStepTo = 0;
                for (int rowcnt = 0; rowcnt < drMenu.Length; rowcnt++)
                {
                    if (drMenu[rowcnt]["is_folder"].ToString().ToLower() == "false")
                    {
                        //If no submenus are there.
                        HtmlGenericControl liMain1 = new HtmlGenericControl("li");//Booking Upload                                                        
                        HtmlGenericControl aMain1 = new HtmlGenericControl("a");
                        aMain1.Attributes["href"] = drMenu[rowcnt]["target_url"].ToString();
                        HtmlGenericControl spMenu1 = new HtmlGenericControl("span");
                        spMenu1.InnerHtml = "&nbsp;&nbsp;" + drMenu[rowcnt]["display_text"].ToString();
                        aMain1.Controls.Add(spMenu1);
                        liMain1.Controls.Add(aMain1);
                        ulMenu1.Controls.Add(liMain1);
                    }
                    if (drMenu[rowcnt]["is_folder"].ToString().ToLower() == "true")
                    {
                        //submenus are there 
                        DataRow[] drSubMenu;
                        HtmlGenericControl liMain1 = new HtmlGenericControl("li");//Customer
                        liMain1.Attributes["class"] = "parent";
                        HtmlGenericControl aMain1 = new HtmlGenericControl("a");
    开发者_运维百科                    aMain1.Attributes["href"] = "#";
                        HtmlGenericControl spMenu1 = new HtmlGenericControl("span");
                        subMenuStepTo = rowcnt;
                        spMenu1.InnerHtml = "&nbsp;&nbsp;" + drMenu[subMenuStepTo]["display_name"].ToString();   //subMenuStepTo                         
                        aMain1.Controls.Add(spMenu1);
                        liMain1.Controls.Add(aMain1);
                        drSubMenu = dsMenu.Tables[0].Select("display_name = '" + drMenu[subMenuStepTo]["display_name"].ToString() + "' AND parent_menu_id = " + mnuCount);//subMenuStepTo
                        HtmlGenericControl divMenu2 = new HtmlGenericControl("div");
                        HtmlGenericControl ulMenu2 = new HtmlGenericControl("ul");
                        for (int rowcnt1 = 0; rowcnt1 < drSubMenu.Length; rowcnt1++)
                        {
                            if (mnuCount == 3)
                            {
                                AppRelativeTemplateSourceDirectory = "~/Reports";
                            }
                            HtmlGenericControl liMain2 = new HtmlGenericControl("li");//Corporate                                
                            HtmlGenericControl aMain2 = new HtmlGenericControl("a");
                            aMain2.Attributes["href"] = drSubMenu[rowcnt1]["target_url"].ToString();
                            HtmlGenericControl spMenu2 = new HtmlGenericControl("span");
                            spMenu2.InnerHtml = "&nbsp;&nbsp;" + drSubMenu[rowcnt1]["display_text"].ToString();
                            aMain2.Controls.Add(spMenu2);
                            liMain2.Controls.Add(aMain2);
                            ulMenu2.Controls.Add(liMain2);
                        }
                        subMenuStepTo = subMenuStepTo + (drSubMenu.Length - 1);
                        divMenu2.Controls.Add(ulMenu2);
                        liMain1.Controls.Add(divMenu2);
                        ulMenu1.Controls.Add(liMain1);
                    }
                    if (drMenu[rowcnt]["is_folder"].ToString().ToLower() != "false")
                    {
                        rowcnt = subMenuStepTo;
                    }
                }
                divMenu1.Controls.Add(ulMenu1);
                liMain.Controls.Add(divMenu1);

            }
            ulMenu.Controls.Add(liMain);
        }
        divMenu.Controls.Add(ulMenu);
        mnuContainer.Controls.Add(divMenu);


    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
    finally
    {
        dsMenu.Dispose();
    }
}

private DataSet GetNavigationMenu(int userId, int roleId)
{
    //Gets menu items based on user id.
    try
    {
        string spMenu = "usp_get_navigation_menu;2";
        Object[] paramsMenu = new object[2];
        paramsMenu[0] = (Object)userId;
        paramsMenu[1] = (Object)roleId;
        objData.FillDataset(spMenu, dsMenu, null, paramsMenu);
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
    finally
    {
        objData.Dispose();

    }
    return dsMenu;
}

[AjaxPro.AjaxMethod]
public void CloseWindow(int userid, string release)
{
    if (release == "False")
    {
        string spRelease = "usp_ins_upd_task_assign;3";
        Object[] paramRelease = new Object[1];
        paramRelease[0] = (Object)userid;

        objData.ExecuteNonQuery(spRelease, paramRelease);
    }
}

}

this is my code to bind menu at runtime ..i can't access subfolder pages ..i tried to define subfolder path in database ..it works at first time but when i click on other menu page which is in root then in address bar ".aspx" page name attach with subfolder name ...so page could not found

please help me .........


use "< base href='http://localhost/testapp/' />" in master page, it will help you..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜