Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 6th, 2009, 05:27 PM
Authorized User
 
Join Date: Jun 2006
Location: , , India.
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to gagansharma7
Lightbulb user control javascript not working in footer row of a gridview

Hi there,

I successfully tested a user control for multi-select dropdownlist in a c# webform. The user control has some javascript functions to make it work. But when I use the same user-control in the footer row of a gridview, it doesnt work. The gridview is inside a <div>, <updatepanel>,<table> and is in the contentpage that uses a master page.

The error I am getting is: 'object required'.

register directive used in my webform is:

<%@RegisterTagPrefix="uc1"TagName="mddl"Src="../Controls/mddl.ascx" %>

gridview uses this:

<FooterTemplate>
<ucmddl:mddl id="ListMulti1"runat="server"></ucmddl:mddl>
</FooterTemplate>

using this line in the codebehind to detect and populate the user control:

ucpage.mddl m1 = (MultiDropdownSample.mddl)gridview1.FooterRow.FindControl("ListMulti1");

m1.List.Items.Add(new System.Web.UI.WebControls.ListItem("val1", "1"));
m1.List.Items.Add(new System.Web.UI.WebControls.ListItem("val2", "2"));

Any thoughts towards solution are really welcome.

Thanks
gs
  #2 (permalink)  
Old May 7th, 2009, 03:11 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

You probably need to show us the JavaScript to see what's wrong.

Once thing to be aware of is that ASP.NET can change client side IDs.

E.g., a Button like this:
Code:
 <asp:Button ID="Button1" runat="server" Text="Button" />
ends up like this in the browser:
Code:
<input type="submit" name="Button1" value="Button" id="Button1" />
However, the same button inside a "naming container control" (e.g. a GridView, a User Control, a Content control) can end up like this:
Code:
<input type="submit" name="ctl00$cpMainContent$Button1" value="Button" 
          id="ctl00_cpMainContent_Button1" />
If you assume there's a client element called Button1, your JavaScript will break. Look into ClientID to see how you can get the final ID of the control in the client.

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!
  #3 (permalink)  
Old May 7th, 2009, 03:31 PM
Authorized User
 
Join Date: Jun 2006
Location: , , India.
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to gagansharma7
Default

Hi Imar,

Thanks for your reply.

The js I am using is:

<scripttype="text/javascript"language="javascript">
function SelectedIndexChanged(ctlId)
{

var control = document.getElementById(ctlId+'ctl00_ContentPlaceHolder1_gvThreshold_ctl04_ListM ulti1_DDList');
var strSelText='';
for(var i = 0; i < control.length; i ++)
{
if(control.options[i].selected)
{
strSelText +=control.options[i].text +
',';
}
}
if (strSelText.length>0)
strSelText=strSelText.substring(0,strSelText.lengt h-1);
var ddLabel = document.getElementById(ctlId+"ctl00_ContentPlaceHolder1_gvThreshold_ctl04_ListM ulti1_DDLabel");
ddLabel.innerHTML = strSelText;
ddLabel.innerText = strSelText;
ddLabel.title = strSelText;
}
function OpenListBox(ctlId)
{
var lstBox = document.getElementById(ctlId+"ctl00_ContentPlaceHolder1_gvThreshold_ctl04_ListM ulti1_DDList");
if (lstBox.style.visibility == "visible")

{ CloseListBox(ctlId) ; }
else
{
lstBox.style.visibility =
"visible";
lstBox.style.height=
"100px";
}
}
function CloseListBox(ctlId)
{
var panel = document.getElementById(ctlId+"ctl00_ContentPlaceHolder1_gvThreshold_ctl04_ListM ulti1_Panel2");
var tabl = document.getElementById(ctlId+"ctl00_ContentPlaceHolder1_gvThreshold_ctl04_ListM ulti1_Table2");
var lstBox = document.getElementById(ctlId+"ctl00_ContentPlaceHolder1_gvThreshold_ctl04_ListM ulti1_DDList");
lstBox.style.visibility =
"hidden";
lstBox.style.height=
"0px";
panel.style.height=tabl.style.height;
}
</script>

The codebehind in the usercontrol to call it are:

publicvoid PageInit()
{
string ctlID= this.UniqueID + "_";

DDList.Attributes.Add(
"onchange", "SelectedIndexChanged('" + ctlID + "');");
DDList.Attributes.Add(
"onmouseout", "CloseListBox('" + ctlID + "');");
DDLabel.Attributes.Add(
"onclick", "OpenListBox('" + ctlID + "');");
colDDImage.Attributes.Add(
"onclick", "OpenListBox('" + ctlID + "');");
}


Thanks
gs
  #4 (permalink)  
Old May 7th, 2009, 03:38 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

When you post code here, can you please use the Clear Formatting button on the toolbar and wrap the code in code tags?

Also, this is a bit too much code for me to digest, especically without the possibility to see it running and without the relation to the final HTML in the browser. Also, "it doesn't work" is a bit too vague a discription to work with.

Try narrowing down the problem to a simple reproducible situation and please describe the problem in more detail.

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!
  #5 (permalink)  
Old May 7th, 2009, 04:21 PM
Authorized User
 
Join Date: Jun 2006
Location: , , India.
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to gagansharma7
Default

Hi Imar,

Sorry about not following the formatting and tags in my last posts, will take care of that from now. I am trying to use a multi-select dropdownlist in the footer row of gridview to add a new record to the database table. I saw an example of multi-select dropdownlist here:
http://www.codeproject.com/KB/user-c...pdownList.aspx

made it work on my localhost and tried to use this usercontrol in my main page. When I click on the dropdownlist on my page, it gives javascript error :

some line no. and 'object required'

Is it bit clear now?
  #6 (permalink)  
Old May 7th, 2009, 04:33 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

Yes, but my ability to help you hasn't improved.... ;-)

Without running code, I can't reproduce the problem and thus I can't suggest a fix. You need to use a debugger (VS 2008 has on-board JavaScript debugging; alternatively you can tools like FireBug or simply put a debugger statement in your code). Then you can find out's what's causing the null reference and work from there.

BTW: no need to be sorry about formatting your code. It's a bug in this forum that requires you to take these steps unfortunately.

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:
gagansharma7 (May 7th, 2009)
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in displaying null value to the control in the footer template of gridview jazzydonald ASP.NET 3.5 Basics 14 February 16th, 2009 08:33 AM
Totaling columns in a footer row of a GridView psimonson ASP.NET 2.0 Basics 1 May 5th, 2008 01:34 PM
How to update a selected row from gridview control ryan.webb ASP.NET 2.0 Professional 1 December 28th, 2007 04:21 AM
Access User Control gridview gergi67 C# 2 November 9th, 2007 10:09 AM
User Control in a GridView Colonel Angus ASP.NET 2.0 Basics 4 August 13th, 2007 10:28 AM



All times are GMT -4. The time now is 04:07 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.