简体   繁体   English

如何甚至在ASP中的表上添加onclick,以便您可以从c#后端执行某些操作

[英]how to add a onclick even on tables in ASP so that you can do something from the c# backend

i have this piece of code 我有这段代码

<asp:Table ID="Table1" runat="server">
    <asp:TableRow>
        <asp:TableCell>
         Cell text
        </asp:TableCell>
    </asp:TableRow>
</asp:Table>

what i want to do is to make this table clicable and to process somthing at the back for example 我想要做的就是使这张桌子变得可笑,并在背面处理诸如此类的东西

void Table1_Click(Object sender, EventArgs e)
{
    //do somthing
 }

Can you not add an onclick event to the table? 您不能将onclick事件添加到表中吗? Like this. 像这样。 It has been a while since I did webforms. 自从我制作网络表单以来已经有一段时间了。

<asp:Table id="Table1" runat="server" OnClick="Table1_Click">
    <asp:TableRow>
      <asp:TableCell>
         Cell text
      </asp:TableCell>
    </asp:TableRow>
</asp:Table>

Then use what you have for your backend. 然后将您的后端可用。

void Table1_Click(Object sender, EventArgs e)
{
    //do somthing
}

You can wrap the entire Table with a LinkButton. 您可以使用LinkBut​​ton包装整个表。

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="Button1_Click">

    <asp:Table ID="Table1" runat="server">
        <asp:TableRow>
            <asp:TableCell>
                 Cell text
            </asp:TableCell>
        </asp:TableRow>
    </asp:Table>

</asp:LinkButton>

I would suggest creating a JavaScript function and then making an Ajax call to a web method to call CS method. 我建议创建一个JavaScript函数,然后对Web方法进行Ajax调用以调用CS方法。

HTML: HTML:

<asp:Table ID="Table1" runat="server">
    <asp:TableRow >
        <asp:TableCell onclick="tablecell_click();">
            hello
        </asp:TableCell>
    </asp:TableRow>
</asp:Table>

Javascript: Javascript:

function tablecell_click() {
        //JQuery ajax call here
    }

`in Jquery: 在Jquery中:

$(document).ready(function(){ $(document).ready(function(){

$("#Table1").on('click',function(){ $(“#Table1”)。on('click',function(){

alert(); 警报(); }); }); });` });`

Create a button and use JQuery to click the button to do the PostBack. 创建一个按钮,然后使用JQuery单击该按钮以执行PostBack。 Call the JQuery using the onclick on the TableCell 使用TableCell的onclick调用JQuery

 <asp:Table ID="Table1" runat="server">
    <asp:TableRow>
        <asp:TableCell onclick="tablecell_click();">
            hello
        </asp:TableCell>
   </asp:TableRow>
</asp:Table>
<asp:Button runat="server" id="btnCellClick" OnClick="Table1_Click"/>

    <script>
        function tablecell_click() {
           $('#btnCellClick').click();
         }
   </script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何向未初始化的变量添加内容? c# - How do you add something to an uninitialized variable? c# c#如何检查不存在的东西 - c# How do you check for something that is not there 如何在 C# 中从 MS Access 访问表? - How do you access tables from MS Access in C#? 即使您的网站仍处于离线状态,您也可以与asp.net c#进行Paypal集成吗? - can you do paypal integration with asp.net c# even though your website is still offline? C#如何连续向Label Box添加值,以便生成的数字继续添加到它? - C# How do you continuously add values to a Label Box so that the number generated keeps on adding to it? C#:如何做到这一点,以便可以确定要在虚拟模式下将哪些项目专门绘制到列表视图中? - C#: How do you make it so that you can decide which items you want specifically draw into a listview in virtual mode? 如何将字符串转换为 long 以便它可以用于在 C# 中读取二进制字节? - How do you convert a string to a long so it can be used to read binary bytes in C#? 在ASP.net C#中,如何将参数从Javascript函数传递给onclick处理程序 - In ASP.net C# how do I pass an argument from a Javascript function to the onclick handler 如何将字符串转换为数字,以便可以在C#中向其添加另一个数字? - How do I convert a string to a number so I can add another number to it in C#? 如何在C#中使用DataGridView联接表? - How do you join tables using a DataGridView in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM