Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LinkButtons inside Datagrid

Status
Not open for further replies.

FederalProgrammer

Programmer
Jul 2, 2003
318
CA
For some reason I cannot get the Command Event Handler to handle the click on my linkbuttons that are placed inside a datagrid of mine;
I get an "Internet Explorer Script Error" which says on line1 char1 of my Container Form an object is expected. Please read on for a better description of what I have:

frm: contains a place holder for a user control
MyUC: a user control containing a DataGrid w/ link buttons inside it
linkButtons: whose texts are bounded to items from DB

code for frm:
Code:
private sub Page_Load(...)
      dim uc as MyUc = me.LoadControl(PathToMyUc)
      me.PlaceHolder1.Controls.Add(ucContests)
End Sub

code for MyUc.ascx.vb:
Code:
private Sub Page_Load(...)
    if (not me.IsPostBack)
    dim dt as dataTable = SomeGlobalFunction.GetSomDataTable()
     me.DataGrid1.DataSource = dt
     me.DataGrid1.DataBind()
     end if
End Sub

Sub HandleDataGridCommand(o as object, e as DataGridCommandEventArgs)
   'Some Code goes in here
End Sub

Code in MyUc.ascx:
Code:
<%@ Control Language="vb" AutoEventWireup="False" CodeBehinde = "MyUc.ascx.vb" inherits="MySite.MyUc" TargetSchema="[URL unfurl="true"]http://schemas.microsoft.com/intellisense/ie5"[/URL] %>
<html>
<body>
      <form ID="MyForm" runat="Server">
            <asp:DataGrid id="DataGrid1" runat="Server" OnItemCommand="HandleDataGridCommand" AutoGeneratedColumns="False">
                <columns>
                     <asp:buttonColumn DataTextField="title" HeaderText="Some Header"></asp:ButtonColumn>                
                </columns>
            </asp:DataGrid>
      </Form>
</body>
</html>

When I run this, I get an "Internet Explorer Scrip Error" which says on line 95 char 29 of frm.ascx a ";" is expected!! (this is kinda wierd 'cause in my internet settings, I have disabled "script debugging" and "Display a message for each script error)
This is what I have on my line 95: <TD>
Does it get any weirder or what!!!!!!!!!!!!! Any ideas???




---------------
 
When you say you have <TD> on line 95, how exactly do you determine this?

The best way to locate the error is to say yes when IE asks you if you would like to debug, then choose to debug script (the default). VS.net should then highlight the exact location of the problem. Start from IE in a completely separate window - don't rely on VS.net's built in browser.

Mark [openup]
 
hay thanx for the reply;
To answer your question:
Code:
When you say you have <TD> on line 95, how exactly do you determine this?
"Internet Explorer Script Error" displays the error indicating Line#, Char# and the file in which the error has occured. So I opened the file and that's what I have in there: <TD> The freakier part is that line has only 10 char not 28! 11th char is a carrage return

I also tried openning a new browser as you said (after building the code of course); But I don't get an option to debugg the script... do you mind telling me how this is done please?

FYI: I removed the following from frm
me.PlaceHolder1.Controls.Add(ucContests)
and no script error... when I put this line back on again the script error comes back up! Weirdness :)




---------------
 
when I replace
Code:
<columns>
    <asp:buttonColumn DataTextField="title">
    </asp:ButtonColumn>                
</columns>

by
Code:
<columns>
    <asp:HyperLinkColumn DataTextField="title">
    </asp:HyperLinkColumn>                 
</columns>

The script error doesn't show up.... By the way, for targetSchema, ie 5 is the highest I can select?! is there a way to force an IE6 setting?




---------------
 
I CANNOT BELIEVE NO ONE HERE COULD POINT THIS OUT!!!!!!
Here's the sol'n for the next poor sole w/ the same problem:

Easy Sol'n:
Remove the <Form></Form> tags from the User Control page (in MyUc.ascx). When you add the user control to your container form, make sure the userControl is within <form></form tags:

So, you should have this in your container form:
Code:
<form> 
<uc1:MyUc id="someUcID" runat="server"></uc1:MyUc> 
</form>

and this in your user control .ascx file:
Code:
<%@ Control Language="vb" AutoEventWireup="False" CodeBehinde = "MyUc.ascx.vb" inherits="MySite.MyUc"%>
<asp:DataGrid id="DataGrid1" runat="Server">
    <columns>
        your code in here
    </columns>
</asp:DataGrid>
<asp:datagrid> ... </asp:datagrid>




---------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top