Mafalda
asked on
OnClick
Hi Experts,
I am trying to create a web page where users can select one of too teams and place a bet.
The following is an example of the first column in the table where I would like to click.
Currently when I click It fails and says ColA_Click is undefined.
Also I would like to pass Command Arguments to ColA_Click but I don't know how.
This is ColAClick in my code behind file
Public Sub ColA_Click(ByVal sender As Object, ByVal e As EventArgs)
lblInfo.Text = "INSIDE A"
End Sub
And this is the column example.
<asp:TemplateColumn HeaderText="<b>Team 1</b>" ItemStyle-Width="140px">
<ItemTemplate>
<Table id="ColA" width="180pt" style="cursor: hand; cursor: pointer;">
<tr>
<td onclick="ColA_Click" onmouseover="bgColor='#FFE 682'" onmouseout="bgColor='Silve r'" bgcolor='Silver' >
<table border="0" class="item">
<tr>
<td width="120pt" class="label" align="left">
<%# Container.DataItem("TeamA" ) %>
</td>
<td width="60pt" class="odd" align="right">
<%# Container.DataItem("OddsA" ) %>
</td>
</tr>
</table>
</td>
</tr>
</Table>
</ItemTemplate>
</asp:TemplateColumn>
I am trying to create a web page where users can select one of too teams and place a bet.
The following is an example of the first column in the table where I would like to click.
Currently when I click It fails and says ColA_Click is undefined.
Also I would like to pass Command Arguments to ColA_Click but I don't know how.
This is ColAClick in my code behind file
Public Sub ColA_Click(ByVal sender As Object, ByVal e As EventArgs)
lblInfo.Text = "INSIDE A"
End Sub
And this is the column example.
<asp:TemplateColumn HeaderText="<b>Team 1</b>" ItemStyle-Width="140px">
<ItemTemplate>
<Table id="ColA" width="180pt" style="cursor: hand; cursor: pointer;">
<tr>
<td onclick="ColA_Click" onmouseover="bgColor='#FFE
<table border="0" class="item">
<tr>
<td width="120pt" class="label" align="left">
<%# Container.DataItem("TeamA"
</td>
<td width="60pt" class="odd" align="right">
<%# Container.DataItem("OddsA"
</td>
</tr>
</table>
</td>
</tr>
</Table>
</ItemTemplate>
</asp:TemplateColumn>
ASKER
Well, it is ok to switch to asp:Table if I can acomplish at least the same I am accomplishing now.
At the moment I am using onclick, onmouseover and onmouseout in HTML table
Looking at the documentation I don't see a way to do that with asp:Table.
I am sure there is a way, I just can't find it ...
After switching to asp:Table the code includes
<asp:Table>, <asp:TableRow> and <asp:TableCell> instead of <table> <tr> and <td>
I lost all the "mouse movement " colors and pointer functionality and I still cant find a way to click ...
onclick="ColA_Click" onmouseover="bgColor='#FFE 682'" onmouseout="bgColor='Silve r'"
At the moment I am using onclick, onmouseover and onmouseout in HTML table
Looking at the documentation I don't see a way to do that with asp:Table.
I am sure there is a way, I just can't find it ...
After switching to asp:Table the code includes
<asp:Table>, <asp:TableRow> and <asp:TableCell> instead of <table> <tr> and <td>
I lost all the "mouse movement " colors and pointer functionality and I still cant find a way to click ...
onclick="ColA_Click" onmouseover="bgColor='#FFE
ASKER
Currently this is how it looks like.
I have the ColA_Click subroutine but it is not called.
In addition on VisualStudio I could see the bounded cells in design mode and now they dissapeared.
<asp:TemplateColumn HeaderText="<b>Team 1</b>" ItemStyle-Width="140px">
<ItemTemplate>
<asp:Table id="ColA" width="180pt" style="cursor: hand; cursor: pointer;" runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:Table id="item" BorderWidth="0">
<asp:TableRow>
<asp:TableCell Width="120pt" HorizontalAlign="Left">
<%# Container.DataItem("TeamA" ) %>
</asp:TableCell>
<asp:TableCell Width="60pt" HorizontalAlign="Right">
<%# Container.DataItem("OddsA" ) %>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
</asp:TemplateColumn>
I have the ColA_Click subroutine but it is not called.
In addition on VisualStudio I could see the bounded cells in design mode and now they dissapeared.
<asp:TemplateColumn HeaderText="<b>Team 1</b>" ItemStyle-Width="140px">
<ItemTemplate>
<asp:Table id="ColA" width="180pt" style="cursor: hand; cursor: pointer;" runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:Table id="item" BorderWidth="0">
<asp:TableRow>
<asp:TableCell Width="120pt" HorizontalAlign="Left">
<%# Container.DataItem("TeamA"
</asp:TableCell>
<asp:TableCell Width="60pt" HorizontalAlign="Right">
<%# Container.DataItem("OddsA"
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
</asp:TemplateColumn>
(i am referring to the code in your question), you need to put your event in javascript instead,
for example,
<script language=javascript>
function ColA_Click() {
alert("a");
}
</script>
for example,
<script language=javascript>
function ColA_Click() {
alert("a");
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
1) I saw javascripts implementations, I was sure MS will have a VB alternative way to do it.
I will try the javascript approach.
2) Is there a way to implement onmouseover, onmouseout and onclick using a <asp:Table> instead of a <table>
Thanks,
Maf
I will try the javascript approach.
2) Is there a way to implement onmouseover, onmouseout and onclick using a <asp:Table> instead of a <table>
Thanks,
Maf
Are you just trying to get your click event handled in the codebehind?
Then I would recommend changing the whole embedded table onclick idea and just set the labels to be link buttons. Then catch the onlick of the link button.
Then I would recommend changing the whole embedded table onclick idea and just set the labels to be link buttons. Then catch the onlick of the link button.
ASKER
I need the table cells to be clickable and formatable.
I shouldnt use buttons if possible.
Those are the requirements of the project.
I saw this done all over (javascript included inside) in web sites.
It seems absurd to use 3 languages to accomplish a misserable task ... presenting a table with clickable formattable cells.
Also maintaining such an application gets more complicated.
I would like to use VB.NET and HTML (avoid it as much as I can) only.
Maf
I shouldnt use buttons if possible.
Those are the requirements of the project.
I saw this done all over (javascript included inside) in web sites.
It seems absurd to use 3 languages to accomplish a misserable task ... presenting a table with clickable formattable cells.
Also maintaining such an application gets more complicated.
I would like to use VB.NET and HTML (avoid it as much as I can) only.
Maf
the onclick command on tables is for client side javascript.
To just get a table cell that can be clicked on... I think I would ue javascript.
Sorry I don't know of a nicer way around that.
To just get a table cell that can be clicked on... I think I would ue javascript.
Sorry I don't know of a nicer way around that.
ASKER
Sorry for the pause, but I needed to step out from the project for 2 weeks.
Im back now and I trirf to implement the javascript solution/workaround
I get the following message (debugging message):
error BC30201: Expression expected.
target.SetDataBoundString( 1, System.Convert.ToString(Co ntainer.Da taItem('Od dsB')))
The code change I made is as follows:
First I added the javascript function
<script language=javascript>
function ColB_Click2(A,B)
{
document.location.href='Ga mes2.aspx? A=' + A + '& B=' + B;
}
</script>
Then I changed the code as follows
<ItemTemplate>
<Table id="ColB" onclick="ColB_Click2('<%#C ontainer.D ataItem('T eamB')%>', '<%#Contai ner.DataIt em('OddsB' )%>')" width="180pt" style="cursor: hand; cursor: pointer;">
<tr>
<td onmouseover="bgColor='#FFE 682'" onmouseout="bgColor='Silve r'" bgcolor='Silver' >
<table border="0" class="item">
<tr>
<td width="120pt" class="label" align="left">
<%# Container.DataItem('TeamB' ) %>
</td>
<td width="60pt" class="odd" align="right">
<%# Container.DataItem('OddsB' ) %>
</td>
</tr>
</table>
</td>
</tr>
</Table>
</ItemTemplate>
Same error appears if i try to change it to
onclick="ColB_Click2(<%#Co ntainer.Da taItem('Te amB')%>,<% #Container .DataItem( 'OddsB')%> )"
omitting hte quotes
Using double quotes is a syntax error with a suggestion to change the quotes type (my guess from double to single)
Im back now and I trirf to implement the javascript solution/workaround
I get the following message (debugging message):
error BC30201: Expression expected.
target.SetDataBoundString(
The code change I made is as follows:
First I added the javascript function
<script language=javascript>
function ColB_Click2(A,B)
{
document.location.href='Ga
}
</script>
Then I changed the code as follows
<ItemTemplate>
<Table id="ColB" onclick="ColB_Click2('<%#C
<tr>
<td onmouseover="bgColor='#FFE
<table border="0" class="item">
<tr>
<td width="120pt" class="label" align="left">
<%# Container.DataItem('TeamB'
</td>
<td width="60pt" class="odd" align="right">
<%# Container.DataItem('OddsB'
</td>
</tr>
</table>
</td>
</tr>
</Table>
</ItemTemplate>
Same error appears if i try to change it to
onclick="ColB_Click2(<%#Co
omitting hte quotes
Using double quotes is a syntax error with a suggestion to change the quotes type (my guess from double to single)
ASKER
Ok a few more remarks/corrections
The code for the cells is
<td width="120pt" class="label" align="left">
<%# Container.DataItem("TeamB" ) %>
</td>
<td width="60pt" class="odd" align="right">
<%# Container.DataItem("OddsB" ) %>
using double quotes.
In addiiton and more important changing the code to pass strings work.
e.g.
onclick="ColB_Click2('A', 'B')"
The code for the cells is
<td width="120pt" class="label" align="left">
<%# Container.DataItem("TeamB"
</td>
<td width="60pt" class="odd" align="right">
<%# Container.DataItem("OddsB"
using double quotes.
In addiiton and more important changing the code to pass strings work.
e.g.
onclick="ColB_Click2('A', 'B')"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well the following seems to be the right sysmtax to do it
<Table id="ColB" onclick="ColB_Click2('<%#C ontainer.D ataItem("I D")%>','<% #Container .DataItem( "TeamB")%> ','<%#Cont ainer.Data Item("Odds B")%>')" width="180pt" style="cursor: hand; cursor: pointer;">
Thanks
<Table id="ColB" onclick="ColB_Click2('<%#C
Thanks
Here's a nice tutorial on using tables in asp.net: http://www.c-sharpcorner.com/asp/Controls/TableControlPSD.asp