简体   繁体   English

内联代码不适用于asp:Button

[英]inline code doesn't work on a asp:Button

Could someone tell me why this is happening and how to fix it if possible? 有人可以告诉我为什么会这样,如果可能的话如何解决?

I have a button in a aspx file like: 我在aspx文件中有一个按钮,例如:

<% foreach blah %.

orderID = GenerateCorrectOrderID();

    <input id="btnOrder"  type="button" style="background-color: #000040; color: #FFFFFF; font-weight: normal" value="Order" onclick="javascript:OpenOrderService('<%=orderID%>','A');" />


<% end foreach blah %>

The orderID is being placed correctly in the html as expected. 如预期的那样,将orderID正确放置在html中。 I would like to replace the input button with a asp.button like this: 我想用asp.button替换输入按钮,如下所示:

                    <asp:Button ID="btnOrder"  style="background-color: #000040; color: #FFFFFF; font-weight: normal" Text="Order"    OnClick="UpdateOrderGrid" runat="server" CausesValidation="False" Visible="False"  onclientclick="javascript:OpenOrderService('<%=#orderID%>','A');"  />

The <%=#orderID%> is not being properly placed in the html file. <%=#orderID%>未正确放置在html文件中。 In fact it looks just like this: <%=#orderID%> How can I force it to inline properly? 实际上,它看起来像这样:<%=#orderID%>如何强制其正确内联?

Any idea on how I can get this to work? 关于如何使它起作用的任何想法? I really want to use a Asp.Button because I have a trigger in a update panel that it is attached to. 我真的想使用Asp.Button,因为我在连接到的更新面板中有一个触发器。

If it were me, I would use a repeater and databind the onclientclick instead of putting the code in your aspx/ascx file. 如果是我,我将使用中继器并将数据绑定到onclientclick上,而不是将代码放入您的aspx / ascx文件中。

If you MUST do it this way, it appears you've mixed databinding syntax with inline evaluation syntax. 如果必须这样做,则似乎您已将数据绑定语法与内联评估语法混合在一起。

What I think you want is 我想你想要的是

... onclinentclick="javascript:OpenOrderService('<%= orderId %>','A');" />

Well after trying several different ways like with java script classes and what not....I decided to use a input button which I could use some inline code to define it's id. 在尝试了几种类似Java脚本类的方法之后,我决定使用一个输入按钮,可以使用一些内联代码来定义它的ID。 I then put a asp.button inside a invisible div and then when the input button was pushed I would call the click event of the asp.button which in turn would cause the trigger of the update panel to fire off. 然后,我将一个asp.button放在一个不可见的div中,然后当按下输入按钮时,我将调用asp.button的click事件,这又将触发更新面板的触发。

I know this is a very ugly way to do it but I spent way too much time looking for a more elegant way to accomplish this. 我知道这是一个非常丑陋的方法,但是我花了太多时间寻找一种更优雅的方法来完成此任务。

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

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