Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to pass ClientID in OnClientClick
Message
 
À
14/03/2008 12:03:14
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
OS:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
01301882
Message ID:
01302237
Vues:
34
This message has been marked as a message which has helped to the initial question of the thread.
>>Either:
>>
>><asp:Table id="tblProInfo" runat="server"></asp:Table>
>>
>>
>>Or
>>
>>If it's a "normal" HTML table you need the 'runat' tag.
>>
>><table id="tblProInfo" runat="server"><table>
>>
>>
>>
>>>I'm using AJAX if it has anything to do with this.
>>
>>No, that shouldn't make any difference.
>
>It is a server side control, as I recall (not working today).
>
>In HTML it is something like content_tblProInfo... I'll give more details on Monday or, if you want, I can send you the whole ASPX page.
>
>I have this whole page send to Martin, so I have it now in my gmail.
>
>I've checked it and it's
>
>
><table cellpadding="6" id="tblProInfo" runat="server" visible="false">
>
><tr>
I'm not sure what's really being rendered into your HTML instead of the client ID, but at any rate (from reading your other messages), I'm not sure this is the best way to go about this. The object model available on the server side is not the same model available on the client side. So you really don't have access to the rows (and data in the rows) in the same manner. You can do it through Javascript and the DOM (Document Object Model), but honestly that's probably more than you want to get into right now.

Instead, I'd suggest hooking into the data binding events available and injecting the script you want into each row. Here's a sample to at least point you in the right direction:

- Create a new WebForm.
- Paste this code between the namespace { CODE GOES HERE } braces.
public partial class TableRowTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ArrayList list = new ArrayList() { "One", "Two", "Three" };

            this.tblTest.DataSource = list;
            this.tblTest.DataBind();
        }
    
        protected void tblTest_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.DataItem != null)
            {
                HyperLink link = e.Item.FindControl("lnkClick") as HyperLink;

                if (link != null)
                {                    
                    link.Attributes["href"] = "#";
                    link.Attributes["onclick"] = "return confirm('Navigate to " + e.Item.DataItem.ToString() + "');";                      
                }
            }
            
        }
    }
In the ASPX page, paste this code after the DOCTYPE section:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DataGrid runat="server" ID="tblTest" onitemdatabound="tblTest_ItemDataBound">            
            <Columns>
                <asp:TemplateColumn HeaderText="Test">                
                    <ItemTemplate>
                        <asp:HyperLink ID="lnkClick" runat="server" Text="<%# Container.DataItem %>"></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateColumn>
            </Columns>            
        </asp:DataGrid>
    </div>
    </form>
</body>
</html>
Run the page. It writes the onclick method for each row as it's bound to the data. Your databinding code will look different since you're probably binding to a DataTable and probably has more than one column (you would usually use the DataBinder.Eval(Container.DataItem, "Column") syntax). I didn't modify the URL it links to, just set it to #, but you can easily do that here - for example, you can have it link to a page and pass in a record value in the querystring.

(please take this as it's intended, just as friendly advice)

Do yourself a favor and pick up a book on ASP.NET if you haven't already - from your questions, you're missing a bit of the fundamentals on how things get hooked together. The nice thing about ASP.NET is that it hides a bunch of complexity from newer developers. The bad thing about ASP.NET is that it hides a bunch of complexity from newer developers, which can lead to an incorrect mental model about what's really happening.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform