Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 July 23rd, 2004, 06:43 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Whitstable, , United Kingdom.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid command buttons


Hi,

 I have a simple datagrid with bound datacolumns.

 I can add a button to fire off a server side event and all
 works fine.

  If I add a regular HTML button or label and specify an
  'OnClick' event (which calls a client side script) - nothing
  happens. Can i use HTML buttons/labels to generate onclick
  activity from within a databound asp:datagrid?

TIA.


 
Old July 23rd, 2004, 07:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I wonder if your issue is a non-unique ID when you access it. You should be able to, I would imagine.

Brian
 
Old July 23rd, 2004, 08:29 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Remember that the HTML button's or link's onClick event handler is client-side. If you want to have a datagrid's row contain a server side button or link, you need to use a ButtonColumn.
 
Old July 23rd, 2004, 08:35 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Whitstable, , United Kingdom.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I want to use a client-side HTML button in a bound
datagrid. I want the button's onclick to trigger a
client-side script.

I also have server-side buttons in the datagrid that work ok.

When I try and click on the HTML client-side buttons - nothing
happens.

I have set unique IDs on all buttons and still no results.

Can I mix server-side and client-side buttons in a bound
datagrid or should I use a table or repeater ?

 
Old July 23rd, 2004, 08:47 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Yes you can mix them. I'm not sure why you are having problems. Making this work shouldn't involve any .NET code, it's just plain HTML. Can you post the relavent markup and code-behind? How are you setting the onClick attribute of the HTML elements?
 
Old July 23rd, 2004, 09:01 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Whitstable, , United Kingdom.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hi,

 I have left out other bits of code for ease of reading.
 I have left out other columns that are just simple text fields.
 The script is contained in the header section.

 The first button - Id=btndetail works fine.

 When I click on label id = lab99 it wont fire off the script
 function.

 Please see HTML below.

<script>
  function DoMessage() {
    Alert("Hi ya!");
  }
</script>


<Columns>
  <asp:TemplateColumn HeaderText="Detail">
    <ItemTemplate>
    <asp:Button ID="btnDetail" width="50px" font-size="smaller"
         ForeColor="#0000ff" runat="server"
    Text="Detail" commandname="Detail">
        </asp:Button>
    </ItemTemplate>
  </asp:TemplateColumn>

  <asp:TemplateColumn HeaderText="Detail">
    <ItemTemplate>
    <Label id ="lab99" onclick="DoMessage();" >Memo</Label>
    </ItemTemplate>
  </asp:TemplateColumn>
</Columns>

Does any of this help?
TIA.

 
Old July 23rd, 2004, 11:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I think your issue is that the label can't generate an onclick event. In your case, this isn't an ASP.NET server control, it's a label for another field, which describes that field. For example:

<Label for="txtTextBox">Enter Text</Label>
<input type="text" id="txtTextBox" name="txtTextBox"></input>

Brian

Brian
 
Old July 23rd, 2004, 01:18 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

However, the "onClick" attribute is applicable to practically every HTML element. Confirm that the onclick attribute is or isn't being written out in the source HTML. Maybe the <label> element is one that doesn't support onClick. Looks like it does:

http://msdn.microsoft.com/workshop/a...ects/label.asp
 
Old July 23rd, 2004, 01:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Learn something new everytime...... Peter does the label ID have to be unique to not cause problems? Above the label with lab99 would be repeated many times?

Brian
 
Old July 23rd, 2004, 06:10 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Any HTML that is in a repeating template will repeat as is. If the template has a server control (anything with runat="server") the control will get a unique ID.




Similar Threads
Thread Thread Starter Forum Replies Last Post
datagrid command buttons CyberW ASP.NET 3.5 Basics 21 November 29th, 2008 04:02 PM
Using command buttons in Access kelljw Access VBA 10 July 5th, 2006 12:42 PM
Using command buttons in Access kelljw BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 July 4th, 2006 07:21 AM
Labels as command buttons RichMW Access VBA 0 February 18th, 2005 09:10 AM
Graphics For Command Buttons Teqlump Access 1 November 24th, 2004 11:02 AM





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