CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

MS SQL 2008 on ASP.NET Hosting



Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 2/27/2008 5:00:13 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 0 Views: 87 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
1 Items, 1 Pages 1 |< << Go >> >|
parrotrebozo
Asp.Net User
C# LinkButton with MasterPage2/27/2008 5:00:13 AM

0/0

Hi. I am trying to use a dynamically-generated LinkButton control to asynchronously populate a submenu.

For example, choosing one of these LinkButton controls (created in code-behind)
        Hardware (id=A1)   ||   Software (id=A2)   ||   Books (id=A3)    ||    etc.
would present a separate menu of
            Software:Games   ||   Software:Finance   ||    etc.

The code works fine if I use it on a stand-alone .aspx page; however, once I attach the page to a MasterPage the link no longer works the way I expect.

Here is what I see as the issue: when the button is on the stand-alone page the ID I assign it remains as I expect ('A2'); when the page has a MasterPage, the ID I assign is appended to the end of the .NET-generated ID, 'ctl00$ContentPlaceHolder1$A2'. Consequently, I can no longer access the value using Request["__EVENTTARGET"].

How can I get around this so that I can access this ID from the code-behind while still using the MasterPage?

Thank you for your time.

=========================================================
.cs file...
protected void Page_Load(object sender, EventArgs e)
{
    this.loadmenu1();
}
public void loadmenu1()
{
    LinkButton newcontrol;
    string displayname = "";
    string displayid = "";
    string[] menu1names = new string[] { "MENU1", "MENU2", "MENU3" };
    for (int i = 0; i < menu1names.Length; i++)
    {
        displayname = menu1names[i];
        displayid = (
string)i.ToString();
        newcontrol =
new LinkButton();
        newcontrol.Attributes.Add(
"runat", "server");
        newcontrol.ID = displayid;
        newcontrol.Text = displayname +
" || ";
        divmenu1.Controls.Add(newcontrol);
    }
    if (menu1names.Length > 0)
    {
        //string selectedmenuA = Request["__EVENTARGUMENT"];
        string selectedmenuB = Request["__EVENTTARGET"];
        this.loadmenu2(selectedmenuB);
    }
}
public void loadmenu2(string menu1id)
{
    switch (menu1id)
    {
        case "0":
            divmenu2.InnerHtml =
"ONE";
            break;
        case "1":
            divmenu2.InnerHtml =
"TWO";
            break;
        case "2":
            divmenu2.InnerHtml =
"THREE";
            break;
        default:
            divmenu2.InnerHtml =
"";
            break;
    }
}

=========================================================
Does NOT work:
.master file...
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="debug.master.cs" Inherits="mercury.masterpages.debug" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml" >
    <
head id="Head1" runat="server">
        <title>Untitled Page</title>
    </
head>
    <
body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true" />
            <div>
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" />
            </div>
        </form>
    </
body>
</
html>

.aspx file (with MasterPage...
<%@ Page Language="C#" MasterPageFile="~/masterpages/debug.master" AutoEventWireup="true" CodeBehind="asynclinkbuttontest.aspx.cs" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <div ID="divmenu1" runat="server" />
                <hr />
                <div ID="divmenu2" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</asp:Content>

=========================================================
DOES
work:
.aspx file (stand-alone)...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="asynclinkbuttontest.aspx.cs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml" >
    <
head runat="server">
    <title>Untitled Page</title>
    </
head>
    <
body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <div>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <div ID="divmenu1" runat="server" />
                        <hr />
                        <div ID="divmenu2" runat="server" />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </form>
</
body>
</
html>


- Scott
1 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Professional ASP.NET 3.5: In C# and VB Authors: Bill Evjen, Scott Hanselman, Devin Rader, Pages: 1673, Published: 2008
Professional ASP.NET 2.0 Authors: Bill Evjen, Scott Hanselman, Farhan Muhammad, Srinivasa Sivakumar, Devin Rader, Pages: 1253, Published: 2005
ASP.NET 2.0: A Developer's Notebook Authors: Wei Meng Lee, Pages: 326, Published: 2005
C# for Programmers: Updated for C# 2.0 Authors: Paul J. Deitel, Pages: 1317, Published: 2005
ASP.NET 2.0 Everyday Apps For Dummies Authors: Doug Lowe, Pages: 504, Published: 2006
Visual C# 2005: How to Program Authors: Harvey M. Deitel, Paul J. Deitel, Pages: 1591, Published: 2006
ASP.NET 2.0 MVP Hacks and Tips Authors: David Yack, Joe Mayo, Scott Hanselman, Fredrik Normén, Dan Wahlin, J. Ambrose Little, Jonathan Goodyear, Pages: 400, Published: 2006
Professional VB 2005 Authors: Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Rama Ramachandran, Kent Sharkey, Bill Sheldon, Pages: 1066, Published: 2006
Beginning ASP.NET 2.0 Authors: Chris Hart, John Kauffman, Chris Ullman, David Sussman, Pages: 759, Published: 2005
ASP.NET 2.0 Black Book: black book Authors: Dreamtech Software, Dreamtech Software, Charul Shukla, Anil Kumar Barnwal, Dreamtech Software India, Pages: 1167, Published: 2006

Web:
how to get the text of link button in master page to a content ... i have a master page in which i am having 10 link buttons. and i am loading the Text of the link button from ... <%@ Page Language="C#" ...
Visual Studio .NET link button in master page Oct 7, 2008 ... link button in master page - C_A P 07-Oct-08 07:10 7:10:35 AM ... solutiion - C- Sharp Guru 07-Oct-08 07:50 7:50:38 AM ...
LinkButton on a Master page : c#, asp.net, ie 7 Apr 28, 2008 ... Hello, I am writing a C# asp.net application. I am using a master page with 3 LinkButtons, each should point to a different page.
ASP.NET link button in master page link button in master page - Adarsh Parmar 07-Oct-08 07:10 7:10:35 AM ... solutiion - C-Sharp Guru 07-Oct-08 07:50 7:50:38 AM ...
Chris Love's Official ASP.NET Blog : Handling Master Page Click ... So the problem I had to solve was how to handle a LinkButon Click event from within the content page for a LinkButton on the Master Page. ...
find control in user control in master page - bytes And a master page. In fisrst web user control there is a datalist. In datalist ItemCreated event, I try to find a linkbutton control which ...
C#.NET Localization with MasterPage | Mike Add the Click Event to your MasterPage.master.cs /* * You could change this Event as you like. * I used a LinkButton for the example * because it is really ...
.BenRush - Handling events from MasterPage controls in the ... This let's us interact with the LinkButton on the master page strongly (as opposed to using the .... (http://ple--blog.nl.eu.org/chase-c... [Pingback] ...
CodeProject: Developing an ASP.NET page with MasterPage and ... The next step is the master page: <%@ Master Language="C#" AutoEventWireup="true " ... the CommandArgument attribute of the LinkButton is used. ...
Need help dynamically changing CssClass on master page controlls ... Jul 29, 2008 ... Line 22: LinkButton btWeb = MasterPage.FindControl("linkWeb"); Source File: c:\ Inetpub\wwwroot\pete\Admin\Home.aspx.cs Line: 20 ...




Search This Site:










how do i disable treenodes

treeview and xmldatasource vs sitemapdatasource

reorder treeview items

the file web.sitemap required by xmlsitemapprovider does not exist.

problem dynamically set a variable for a menu item pointing to external pages

remove top entry in treeview

form wizard, embeaded if statements options

multiple themes in the website

site design choices

help in callback

referencing a master page subroutine?

changing the navigateurl of a bound menuitem

sitemap and menu: how to create dynamic url?

must treenode values be unique?

passing values from content page to user control on master page

database sitemapprovider with enablelocalization, best practice?

a page can have only one server-side form tag

menu with levelmenuitemstyles

nested master page and intellisense problem

menu control

masterpage and redirect

strange css output with <asp:menu>

dispalying images

background image on a masterpage

trouble applying skinid to an <asp:tablerow> tag

how can i see all of the menu root and child items when the page loads?

horizontal navbar (liek the blue one above) with drop downs?

control.resolveclienturl isn't designed correctly?

master page controls trigger invalid postback errors on contentpages

menu scrolling?

  Privacy | Contact Us
All Times Are GMT