简体   繁体   English

需要帮助从我的代码后面格式化html

[英]Need help formatting html from my code-behind

I have the following code snippet, but I'm banging my head up against the wall trying to get the errors out of it. 我有以下代码片段,但我将头撞墙,试图消除错误。

I'm getting the following design time compile errors: 我收到以下设计时编译错误:

; expected
The name button does not exist in the current context.

Those same two messages also repeat for the DisplayReceipt. 对于DisplayReceipt,这两个相同的消息也会重复。

Here is my code snippet being assigned in my code behind for html. 这是在我的html 代码后面分配的代码段。

Can somebody please help me out? 有人可以帮我吗?

Image_ID = "<input id='" + fuelticket.Image_ID + "' type="button" onclick='" + DisplayReceipt(fuelticket.Image_ID)"'>";

You just need to escape the quotes: 您只需要转义引号即可:

Image_ID = "<input id='" + fuelticket.Image_ID + "' type=\"button\" onclick='DisplayReceipt(" + fuelticket.Image_ID + ")'>";

Or use string.Format() to make things a bit cleaner: 或使用string.Format()使事情更string.Format()

Image_ID = string.Format("<input id='{0}' type=\"button\" onclick='DisplayReceipt({0})'>", fuelticket.Image_ID);

To make it work use the below code: 要使其工作,请使用以下代码:

Image_ID = String.Format("<input id=\"{0}\" type=\"button\" onclick=\"{1}\">", fuelticket.Image_ID, DisplayReceipt(fuelticket.Image_ID));

The above looks more clear and optionally you can also use @ for the string so you don't have to escape any special characters. 上面的内容看起来更加清晰,您还可以选择使用@作为字符串,这样就不必转义任何特殊字符。

Image_ID = String.Format(@"<input id="{0}" type="button" onclick="DisplayReceipt({0})">", fuelticket.Image_ID));

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

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