简体   繁体   English

服务器标签格式不正确-使用JQuery使用服务器控件创建表

[英]Server tag not well formed - Create table with server control using JQuery

I am trying to create a table that has some dynamic data and some server controls. 我想创建一个table ,有一些动态的数据和一些服务器控件。 I need server controls so that they will be accessed in code behind. 我需要服务器控件,以便可以在后面的代码中对其进行访问。 I am creating table in JQuery . 我在JQuery创建table My code is as below. 我的代码如下。

function createLeaveDetails(formattedArray) {
                    var leaveTable = "<table class='table table-striped table-hover table-bordered' style='width: 435px'>";
                    leaveTable += "<tr> <th>Date</th> <th>Full Day</th> <th>Half Day</th> </tr>";
                    for (i = 0; i < formattedArray.length; i++) {
                        leaveTable += "<tr> <td>" + formattedArray[i] + "</td> <td><asp:RadioButton ID='radHalf" + i + " runat='server' GroupName='grp" + i + "' /></td>";
                        leaveTable += "<td><asp:RadioButton ID='radFull" + i + " runat='server' GroupName='grp" + i + "' /></td> </tr>";
                    }
                    leaveTable = +"</table>"

                    $("#tblLeaveDetails").append();
                }

but at run-time its giving The server tag is not well formed. 但是在运行时,它的给定The server tag is not well formed. error on line 在线错误

leaveTable += "<tr> <td>" + formattedArray[i] + "</td> <td><asp:RadioButton ID='radHalf" + i + " runat='server' GroupName='grp" + i + "' /></td>";

First of all, you cannot create "server" controls from client side (ie JavaScript / Jquery). 首先,您无法从客户端(即JavaScript / Jquery)创建“服务器”控件。 As the Browser does not understand the server tag. 由于浏览器无法理解服务器标签。 The Asp View engine render that server control to the HTML control accordingly. Asp View引擎将相应的服务器控件呈现为HTML控件。 So all you can do is you create basic HTML elements from the client side scripting. 因此,您所能做的就是从客户端脚本创建基本的HTML元素。 Create 创造

<input type='radio'></input>

instead of 代替

<asp:RadioButton />

As you need the value at the server you can create an Hidden Field and put the selected value of the input radio in that hidden field from JavaScript / Jquery. 当您在服务器上需要该值时,可以创建一个“隐藏字段”,然后将输入单选的选定值放在JavaScript / Jquery的该隐藏字段中。 as follows 如下

$('#yourRadiobuttonlist').change(function(){
    yourHiddenField.value = $('#yourRadiobuttonlist :selected').val();
});

And at server side you can access the Hidden Field value for the desired selected value of the radio button. 在服务器端,您可以访问“隐藏字段”值以获得单选按钮的所需选定值。

Hope it helps.... 希望能帮助到你....

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM