[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

OnClick

Posted on 2006-03-26
14
Medium Priority
?
1,824 Views
Last Modified: 2012-06-27
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="&lt;b&gt;Team 1&lt;/b&gt;" ItemStyle-Width="140px">
<ItemTemplate>
<Table id="ColA"  width="180pt" style="cursor: hand; cursor: pointer;">
  <tr>
    <td onclick="ColA_Click"  onmouseover="bgColor='#FFE682'"  onmouseout="bgColor='Silver'" 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>
0
Comment
Question by:Mafalda
  • 7
  • 3
  • 2
  • +1
14 Comments
 
LVL 14

Expert Comment

by:existenz2
ID: 16296178
Use a <asp:Table> instead of a normal table and <asp:tablecolumn> instead of <td> etc... and add a runat="server" too it.

Here's a nice tutorial on using tables in asp.net: http://www.c-sharpcorner.com/asp/Controls/TableControlPSD.asp
0
 
LVL 6

Author Comment

by:Mafalda
ID: 16296480
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='#FFE682'"  onmouseout="bgColor='Silver'"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Author Comment

by:Mafalda
ID: 16296642
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="&lt;b&gt;Team 1&lt;/b&gt;" 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>
0
 
LVL 12

Expert Comment

by:bsdotnet
ID: 16297086
(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>
0
 
LVL 12

Accepted Solution

by:
bsdotnet earned 1200 total points
ID: 16297211
You can change to this,

<asp:TemplateField >
<ItemTemplate>
<Table id="ColA"  width="180pt" style="cursor: hand; cursor: pointer;">
  <tr>
    <td onclick="ColA_Click('<%# Container.DataItem("col1") %>','<%# Container.DataItem("col2") %>')"  onmouseover="bgColor='#FFE682'"  onmouseout="bgColor='Silver'" bgcolor='Silver' >
    <table border="0" class="item">
      <tr>
        <td width="120pt" class="label" align="left">
          <%# Container.DataItem("col1") %>
        </td>
        <td width="60pt" class="odd" align="right">
          <%# Container.DataItem("col2") %>
        </td>
      </tr>
    </table>
    </td>
  </tr>
</Table>
</ItemTemplate>
</asp:TemplateField>

and then use the javascript to pass selected items to same page or different page:
    <script language=javascript>
        function ColA_Click(A,B) {
            document.location.href='gridview3.aspx?col1=' + A + '&col2=' + B;                
        }
    </script>
0
 
LVL 6

Author Comment

by:Mafalda
ID: 16298697
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
0
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16299963
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.
0
 
LVL 6

Author Comment

by:Mafalda
ID: 16305882
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
0
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16309622
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.
0
 
LVL 6

Author Comment

by:Mafalda
ID: 16411258
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(Container.DataItem('OddsB')))

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='Games2.aspx?A=' + A + '& B=' + B;
}
</script>

Then I changed the code as follows


<ItemTemplate>
  <Table id="ColB" onclick="ColB_Click2('<%#Container.DataItem('TeamB')%>','<%#Container.DataItem('OddsB')%>')" width="180pt" style="cursor: hand; cursor: pointer;">
    <tr>
      <td  onmouseover="bgColor='#FFE682'"  onmouseout="bgColor='Silver'" 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(<%#Container.DataItem('TeamB')%>,<%#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)
0
 
LVL 6

Author Comment

by:Mafalda
ID: 16411266
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')"

0
 
LVL 15

Assisted Solution

by:GavinMannion
GavinMannion earned 800 total points
ID: 16415136
Try

onclick="ColB_Click2('" + <%#Container.DataItem('TeamB')%>+ "','" +<%#Container.DataItem('OddsB')%> + "')"

0
 
LVL 6

Author Comment

by:Mafalda
ID: 16416232
Well the following seems to be the right sysmtax to do it

<Table id="ColB" onclick="ColB_Click2('<%#Container.DataItem("ID")%>','<%#Container.DataItem("TeamB")%>','<%#Container.DataItem("OddsB")%>')" width="180pt" style="cursor: hand; cursor: pointer;">

Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month20 days, 7 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question