Onserverclick和onclick不起作用 [英] Onserverclick and onclick not work

查看:134
本文介绍了Onserverclick和onclick不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我在html列表(表)中加载数据后的代码中:ASP

From my code behind im load data in html list (table): ASP

<table id="tblClientes" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Nombre</th>
            <th>Razón Social</th>
            <th>Teléfono</th>
            <th>Email</th>
            <th></th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <asp:Literal runat="server" ID="tableData"></asp:Literal>
    </tbody>

和.CS(隐藏代码)

tableData.Text += "<tr>";
                tableData.Text += "<td>" + cliente.Nombre + "</td>";
                tableData.Text += "<td>" + cliente.RazonSocial + "</td>";
                tableData.Text += "<td>" + cliente.Telefono + "</td>";
                tableData.Text += "<td>" + cliente.Email + "</td>";
                tableData.Text += "<td><a href='#' runat='server' onserverclick='btnCargarDatosCliente_Click' data-toggle='modal' data-target='#ventanaEmergente' id='btnCargarDatosCliente_" + cliente.Id.ToString() + "'>Editar</a></td>";
                tableData.Text += "<td><input type='button' data-toggle='modal' data-target='#ventanaAdvertencia' id='btnEliminarCliente_" + cliente.Id.ToString() + " value='Borrar' runat='server'/>Elimiar</td>";
                tableData.Text += "</tr>";

onserverclick ='btnCargarDatosCliente_Click'不调用该事件.我确实尝试过onclick但还是一样.

The onserverclick='btnCargarDatosCliente_Click' not call the event. i did try with onclick but same.

有人知道我做错了吗?

推荐答案

它不能那样工作.如果将控件放在带有runat ="server"的aspx表单上,则该控件将在服务器上处理,并且输出html将使用适当的javascript函数(如果指定了事件,例如OnClick)返回给客户端,该函数将表单回传给客户端.如果像您一样生成字符串并将其分配给文字,则它已经按服务器原样呈现,因为已经进行了服务器端处理,因此runat ="server"在那里没有任何意义-它只是一个字符串.

It does not work that way. If you place control on the aspx form with runat="server" that control is processed on the server and output html is returned to the client with proper javascript function (if you specify event like for example OnClick) that posts the form back. If you generate string like you do and assign it to literal it is render 'as it is' as server-side processing already has taken place so runat="server" has no meaning there - it is just a string.

要实现所需的功能,我建议将Repeater控件与LinkBut​​ton控件一起使用.网上有很多示例/教程.

To achieve what you want I suggest using Repeater control with LinkButton control. There is a lot of examples/tutorial on the web how to do it.

这篇关于Onserverclick和onclick不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆