0
foreach (DataRow dr in dt.Rows)
{
    html += "<tr class=\"GreyBorder\" id='tblFilesGrid_" + dr["Id"].ToString() + "' 
                pkid=\"" + dr["id"].ToString() + "\"  class=\"DataRow\">";
                html += "<td class=\"GreyBorder\" style=\"text-align:center !important;\">" + Count + 
                "</td>";

    html += "<td  align=\"center\" >" + dr["Name"] + "</td> ";

    html += "<td class=\"GreyBorder\" align='center'><img id='view' title='view' 
                onclick=showDocument('" + dr["id"] + "');  src='../../Images/folder.gif'> &nbsp&nbsp 
                <img title='remove' onclick='return DeleteRow(this)'  src='../../images/delete.png'> 
                </td>";

    html += "</tr>";
    Count++;
}

This is my dynamic grid which has an onclick function showDocument. I need to code this function in my code behind. For this I have added runat server attribute in my div tag in aspx page. How would I modify this line of code now to access my function in code behind??

html += "<td class=\"GreyBorder\" align='center'><img id='view' title='view' 
            onclick=showDocument('" + dr["id"] + "');  src='../../Images/folder.gif'> &nbsp&nbsp 
            <img title='remove' onclick='return DeleteRow(this)'  src='../../images/delete.png'> 
            </td>";

I added runat server attribute in my aspx but after adding runat server, my grid is not showing.

 <div id="divFilesGrid"  runat="server" > </div>
Unknown
  • 145
  • 2
  • 11

1 Answers1

1

You are mixing apples and oranges. what you wrote is dynamic html ("on the fly") runat="server" is for well defined Microsoft server side components (like <asp:Label> or <asp:DropDownList> or whatever). These two don't mix.

LongChalk
  • 783
  • 8
  • 13
  • Just like when I write this I can access my id in code behind. In the same way I want to access my function showDocument in code behind. how can I do so? – Unknown Feb 12 '20 at 09:49
  • I was told to add runat server attribute in my grid above – Unknown Feb 12 '20 at 09:49
  • Ok, then please ask the one who told you. BTW, if you do find a hack to mix "high level server side components" with "low level html rendered html" please share with us, as I for one would really like to learn that trick. – LongChalk Feb 12 '20 at 10:01
  • I added runat server attribute to my div tag in aspx. This way can i access my function in code behind? – Unknown Feb 12 '20 at 10:27
  • what would i have to change in my grid above? just change onclick to onserverclick? – Unknown Feb 12 '20 at 10:28
  • @LongChalk https://stackoverflow.com/questions/248437/asp-net-parsing-raw-html-into-controls – Hans Kesting Feb 12 '20 at 10:35