Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 23rd, 2010, 03:15 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

If possible, try recreating the problem without a database. E.g. use a standard for loop instead of database records.

Does the CSS matter? If so, include it; otherwise you can leave it out. This is about functionality, right?

Try to post the absolute minimum code required to make it easy to work with the code. That probably means you should create a new site / page from scratch to avoid the clutter in your pages and master page.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Gayathri79 (March 23rd, 2010)
 
Old March 23rd, 2010, 04:45 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default

I have removed some menus, CSS and search box etc from the Master Page. so it jus has header and login.
i have added a new Default.aspx page from this Master page.
-I also removed the database records. I created everything new.

So i am posting Masterpage.master, default.aspx, default.aspx.cs.
I tried to execute this, and i am getting the same error with Button control.

Masterpage.master
-----------------

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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></title>

</head>
<body>
<form id="form1" runat="server">
<div id="header"
style="background-color:#66CDAA;height:247px; width:899px; margin-top:0px; margin-left:200px">
<img src="ImageFls/img7.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:LoginVie w ID="LoginView1" runat="server">
<AnonymousTemplate>
<span class="style11"><span class="style13">Please Sign Up to Register.</span>

</AnonymousTemplate>
<LoggedInTemplate>
<span class="style11"><span class="style13">Welcome&nbsp;</span><asp:LoginName
ID="LoginName1" runat="server" CssClass="style13" /></span>
<span class="style13">&nbsp;&nbsp;&nbsp;</span><span class="style11"><span class="style13">[&nbsp;</span><asp:LoginStatus
ID="LoginStatus1" runat="server" CssClass="style13" /><span class="style13">
&nbsp;]</span>&nbsp;</span>

</LoggedInTemplate>
</asp:LoginView>

<asp:Login ID="Login1" runat="server"

style="z-index: 1; left: 635px; top: -44px; position: relative; height: 153px; width: 262px">
</asp:Login>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;

<div style="background-color:#C9EEE1;height:714px; width:901px; margin-top:200px;margin-left:580px;
position:absolute; left: -372px; top: 52px;" class="style1" id="maincontent">


<asp:ContentPlaceHolder id="MainContentholder" runat="server">
<br />
<br />
</asp:ContentPlaceHolder>
</div>

</form>
</body>
</html>

----------------------------


Default.aspx
------------

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>



<asp:Content ID="Content2" ContentPlaceHolderID="MainContentholder" Runat="Server">

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<div>
<asp:Table ID="Table1" runat="server" Height="66px" Width="418px">
</asp:Table>

</div>

</asp:Content>

----------------------------------

Default.aspx.cs
---------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Common;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Drawing;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


for (int i = 0; i <= 10; i++)
{
TableRow firstrow = new TableRow();
TableCell firstcell = new TableCell();

Button but1 = new Button();
but1.ID = "Button " + i.ToString();
but1.Text = but1.ID;
firstcell.Controls.Add(but1);
firstrow.Cells.Add(firstcell);

Panel pan10 = new Panel();
pan10.Height = Unit.Pixel(100);
pan10.Width = Unit.Pixel(100);
pan10.BackColor = Color.Chocolate;
pan10.ID = "panel" + i.ToString();
Label lab = new Label();
lab.ID = "label" + i.ToString();
lab.Text = "This Panel contains Button Client Id: " + but1.ClientID;
pan10.Controls.Add(lab);
//Form.Controls.Add(pan10);

AjaxControlToolkit.HoverMenuExtender hov = new AjaxControlToolkit.HoverMenuExtender();
hov.TargetControlID = but1.ClientID;
hov.PopupControlID = pan10.ClientID;
Form.Controls.Add(hov); /* If i comment this line, this is working without hover control */
Table1.Rows.Add(firstrow);
}
}
}

Last edited by Gayathri79; March 23rd, 2010 at 04:51 PM..
 
Old March 24th, 2010, 05:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Gayathri79,

I found out what the problem is. You were close, but you need to make four changes to make this work.

First, you need to use UniqueID (used for postback scenarios) instead of ClientID (for client script):

Code:
 
hov.TargetControlID = but1.UniqueID;
Secondly, the ID of the button is not valid as it contains a space. Change this:

Code:
 
but1.ID = "Button " + i.ToString();
to this:
Code:
but1.ID = "Button" + i.ToString();
Next, you need to enable the line that adds the Panel to the Form or there won't be a panel to show by the hover extender.

Code:
 
Form.Controls.Add(pan10);
Finally, the order of your code is important. Consider your current code:

Code:
 
hov.TargetControlID = but1.ClientID;
hov.PopupControlID = pan10.ClientID;
Form.Controls.Add(hov);
Table1.Rows.Add(firstrow);
The first line assigns the ClientID (which should be UniqueID) of the button to the TargetControlID. However, at this stage, the button doesn't know it's inside a table that's inside a Master Page. So, at this stage, it simply returns Button0 for the first button. However, once all controls are added to the form (by adding firstrow to the table), the control hierarchy is known and the UniqueID of the button is changed from Button0 to ctl00$MainContentholder$Button0 which is the ID that the hover panel needs.

So, simply assigning the UniqueID of the button to the extender *after* all controls are added to the form should do the trick:

Code:
 
AjaxControlToolkit.HoverMenuExtender hov = new AjaxControlToolkit.HoverMenuExtender();
hov.PopupControlID = pan10.ClientID;
Form.Controls.Add(hov);
Table1.Rows.Add(firstrow);
hov.TargetControlID = but1.UniqueID;
This way, TargetControlID gets assigned the full unique ID of the button control.

For your reference, here's the complete working code:

Code:
 
protected void Page_Load(object sender, EventArgs e)
{
 for (int i = 0; i <= 10; i++)
 {
  TableRow firstrow = new TableRow();
  TableCell firstcell = new TableCell();
  Button but1 = new Button();
  but1.ID = "Button" + i.ToString();
  but1.Text = but1.ID;
  firstcell.Controls.Add(but1);
  firstrow.Cells.Add(firstcell);
  Panel pan10 = new Panel();
  pan10.Height = Unit.Pixel(100);
  pan10.Width = Unit.Pixel(100);
  pan10.BackColor = Color.Chocolate;
  pan10.ID = "panel" + i.ToString();
  Label lab = new Label();
  lab.ID = "label" + i.ToString();
  lab.Text = "This Panel contains Button Client Id: " + but1.ClientID;
  pan10.Controls.Add(lab);
  Form.Controls.Add(pan10);
  AjaxControlToolkit.HoverMenuExtender hov = new AjaxControlToolkit.HoverMenuExtender();
  hov.PopupControlID = pan10.ClientID;
  Form.Controls.Add(hov);
  Table1.Rows.Add(firstrow);
  hov.TargetControlID = but1.UniqueID;
 }
}
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Gayathri79 (March 24th, 2010)
 
Old March 24th, 2010, 02:58 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thank you so much for your time. It worked. But there is one small problem.

When i enable the Panel control 'pan10' , every time the page loads, the 'pan10' appears on the form for a second and disappears again. i tried to make it hidden using '.popupMenu' inthe Cssclass:

.popupMenu
{
height:400px;
width:400px;
visibility: hidden;
}
And added in the load event as:

pan1.CssClass = "popupMenu";

Now Panel is not appearing on the Form, but appears like a thin horizontal line when i hover on the burron control.

Last edited by Gayathri79; March 24th, 2010 at 04:18 PM..
 
Old March 24th, 2010, 07:01 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can't you put all the panels inside a div that is initially hidden using CSS and then show it using some onload code (using jQuery for example)?

BTW: it's better to post a new message instead of editing an existing one. I follow these forums over e-mail and you initially said: "it works, thanks", so I almost missed this update...

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Gayathri79 (March 24th, 2010)
 
Old March 24th, 2010, 07:26 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default

sorry abt that.
 
Old March 25th, 2010, 03:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

No need to be sorry; just a tip to help your posts get more attention.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem regarding Login controls bond007 ASP.NET 2.0 Basics 1 April 16th, 2009 01:14 AM
Problem with Try it Out List Controls phage BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 September 15th, 2008 02:15 PM
Problem with user controls jamara ASP.NET 2.0 Basics 7 November 17th, 2006 05:34 PM
problem in user controls nishantmp1 ASP.NET 1.0 and 1.1 Basics 1 September 27th, 2006 09:43 AM
problem in using Image controls harini19 VB How-To 1 March 5th, 2004 02:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.