code块在此背景下asp.net控件支持 [英] code blocks are not supported in this context in asp.net control
问题描述
我制作一个HTML表。我想隐藏的表行。我把属性 RUNAT =服务器
和 ID
的特定行,但是行有客户端code它类似于以下code。
<若%((strFlag ==D)||(strApprvdFlag ==Y)){%GT;
呼叫此行之后,我得到这个错误。
code块在此背景下asp.net控件支持。
块引用>下面是我的样本code:
<表>
< TR合并单元格=4ID =trMedicalscriptrunat =服务器>
< TD风格=WIDTH:×45像素; HEIGHT:12px的align =left级=LabelTaxTextWIDTH =45>< B> G&安培; NBSP;
< / B>
< / TD>
< TD风格=WIDTH:182px; HEIGHT:12px的阶级=LabelTaxTextalign =leftWIDTH =182
COLSPAN =2>医疗
< / TD>
< TD风格=WIDTH:81px; HEIGHT:12px的ALIGN =右级=LabelTaxTextWIDTH =81>
< ASP:文本框的onchange =onChangeFlag(),intOnly(本);的onkeyup =intOnly(本);安其preSS =返回CheckNumericWithOutDecimals(事件)
ID =TxtMedical的tabIndex =24=服务器WIDTH =96PXMAXLENGTH =12的风格=Z-INDEX:0>< / ASP:文本>
< / TD>
<%IF((strFlag ==D)||(strApprvdFlag ==Y)){%GT;
< TD类=LabelTaxText的风格=WIDTH:107px; HEIGHT:12px的ALIGN =右WIDTH =107>
< ASP:文本框的onchange =onChangeFlag(),intOnly(本);的onkeyup =intOnly(本);安其preSS =返回CheckNumericWithOutDecimals(事件)ID =TxtMedicalProof的tabIndex =24的onblur =charAlert(TxtMedical,TxtMedicalProof)=服务器MAXLENGTH =12WIDTH =96PX>
< / ASP:文本>
< / TD>
<%}%GT;
如果%(strApprvdFlag ==Y){%GT;<
< TD类=LabelTaxText的风格=WIDTH:68px; HEIGHT:24px的ALIGN =右WIDTH =68>
< ASP:文本框的id =TxtMedicalApproved的tabIndex =24=服务器MAXLENGTH =12WIDTH =96PX>< / ASP:文本>
< / TD>
< TD类=LabelTaxText的风格=WIDTH:43px>&安培; NBSP;
< ASP:标签ID =lblMedicalRemarks=服务器>< / ASP:标签>
< / TD>
<%}%GT;
< / TR>
< /表>
解决方案当您添加
RUNAT =服务器
来HTML控件更改渲染和code块不支持内。因此,如果有属性,你需要改变你可能需要,而不是做这个(样式类?):< TR ID ='myrow'RUNAT ='服务器'>
&所述; TD>
您code在这里
< / TD>
< / TR>做这样的事情:
< TR ID ='myrow'<%= GetRowProperties()%GT;>
&所述; TD>
您code在这里
< / TD>
< / TR>注意:
RUNAT =服务器
从TR
删除。然后在你的codebehind你可以做这样的事情:保护串GetRowProperties()
{
回归类='MyClass的'; //这样的事情
}I'm creating one html table. I want to hide the table row. I'm putting the attributes
runat=server
andid
for the particular row, but the row has client side code in it similar to the following code.<% if ((strFlag=="d") || (strApprvdFlag=="y")) {%>
After call this line, I got this error.
Code blocks are not supported in this context in asp.net control.
Below is my sample code:
<table> <tr colspan="4" ID="trMedical" scriptrunat="server"> <td style="WIDTH: 45px;HEIGHT: 12px" align="left" class="LabelTaxText" width="45"><b>G </b> </td> <td style="WIDTH: 182px;HEIGHT: 12px" class="LabelTaxText" align="left" width="182" colSpan="2">Medical </td> <td style="WIDTH: 81px; HEIGHT: 12px" align="right" class="LabelTaxText" width="81"> <asp:textbox onchange="onChangeFlag(),intOnly(this);" onkeyup="intOnly(this);" onkeypress="return CheckNumericWithOutDecimals(event)" id="TxtMedical" tabIndex="24" runat="server" Width="96px" MaxLength="12" style="Z-INDEX: 0"></asp:textbox> </td> <% if ((strFlag=="d") || (strApprvdFlag=="y")) {%> <td class="LabelTaxText" style="WIDTH: 107px; HEIGHT: 12px" align="right" width="107"> <asp:textbox onchange="onChangeFlag(),intOnly(this);" onkeyup="intOnly(this);" onkeypress="return CheckNumericWithOutDecimals(event)" id="TxtMedicalProof" tabIndex="24" onblur="charAlert(TxtMedical,TxtMedicalProof)" runat="server" MaxLength="12" Width="96px"> </asp:textbox> </td> <% } %> <% if (strApprvdFlag=="y") {%> <td class="LabelTaxText" style="WIDTH: 68px; HEIGHT: 24px" align="right" width="68"> <asp:textbox id="TxtMedicalApproved" tabIndex="24" runat="server" MaxLength="12" Width="96px"></asp:textbox> </td> <td class="LabelTaxText" style="WIDTH: 43px"> <asp:Label ID="lblMedicalRemarks" Runat="server"></asp:Label> </td> <% } %> </tr> </table>
解决方案When you add a
runat='server'
to an HTML control you change the rendering and code blocks aren't supported inside. So if there are properties you need to change (style? class?) you probably have to instead of doing this:<tr id='myrow' runat='server'> <td> your code here </td> </tr>
Do something like this:
<tr id='myrow' <%= GetRowProperties() %>> <td> your code here </td> </tr>
Note:
runat='server'
removed fromtr
. Then in your codebehind you can do something like this:protected string GetRowProperties() { return "class='myclass'"; // something like this }
这篇关于code块在此背景下asp.net控件支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!