 |
| 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
|
|
|
|

July 23rd, 2004, 06:43 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2003
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 23rd, 2004, 07:27 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
I wonder if your issue is a non-unique ID when you access it. You should be able to, I would imagine.
Brian
|
|

July 23rd, 2004, 08:29 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

July 23rd, 2004, 08:35 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2003
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 ?
|
|

July 23rd, 2004, 08:47 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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?
|
|

July 23rd, 2004, 09:01 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2003
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 23rd, 2004, 11:30 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

July 23rd, 2004, 01:18 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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
|
|

July 23rd, 2004, 01:35 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

July 23rd, 2004, 06:10 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|
 |