如何通过html调用c-sharp函数

如何通过html调用c-sharp函数

问题描述:

int i;

       title = "";
       for (i = 0; i < ds.Tables[0].Rows.Count; i++)

       {

           title = title + "<div class='one' ><div class='Solar Mobile'><h1>" + (i + 1).ToString() + "." + ds.Tables[0].Rows[i]["product_name"].ToString() + " Just Rs." + ds.Tables[0].Rows[i]["price"].ToString() + "/-<asp:ImageButton ID='ImageButton1' runat='server' ImageUrl='~/images/cart.jpg' onclick='Addtocart' /></h1></div><div class='Solar-text' >" + ds.Tables[0].Rows[i]["description"].ToString() + "</div ><div class='img'><img  src='imggrab.aspx?ID=" + ds.Tables[0].Rows[i]["pk_product_id"].ToString() + "' /></div><div class='clr'></div></div>";
       }



是否正确...我正试图调用



is it correct ... i''m trying to call

Addtocart

函数,但是asp图像按钮不起作用...为什么这样...?
在此先感谢

function but the asp image button does not appers... why so...?
thanks in advance

将HTML注入页面是可以的,但是您不能将asp.net控件注入为内嵌html.

而是尝试将控件添加到父控件.
Injecting HTML to the page is alright, but you can''t inject an asp.net control as inline html.

Instead try to add controls to the parent control.


它不起作用.您可以使用Rosponse.Write方法呈现html,但不能呈现服务器控件(asp:ImageButton).我认为您正在尝试将商品添加到购物车中.请添加一个GridView控件并直接绑定表中的数据,然后尝试自定义网格.您可以在GridView模板列中完成所有这些样式操作.
It doesn''t work. you can render the html using Rosponse.Write method, but cannot render server controls (asp:ImageButton). I think here you are trying to add the item to a cart. Please add a GridView control and bind the data from table directly and try to customize the grid. You can do all these style things in GridView template columns.