- C# code
protected void Page_Load(object sender, EventArgs e) { string a = CreateBarCode("4242", 50, 3, true); Response.Write(a); } public string CreateBarCode(string text, int height, int width, bool showText) { string strTemp = text.ToLower(); //替换各个字符 strTemp = strTemp.Replace("0", "_|_|__||_||_|"); strTemp = strTemp.Replace("1", "_||_|__|_|_||"); strTemp = strTemp.Replace("_", "<span style='height:" + height + ";width:" + width + ";background:#FFFFFF;'></span>"); strTemp = strTemp.Replace("|", "<span style='height:" + height + ";width:" + width + ";background:#000000;'></span>"); if (showText) { return strTemp + "<br/>" + text; } else { return strTemp; } }
- C# code
Literal1.Text = CreateBarCode("leaves", 50, 3, true); Response.Write(Literal1.Text);
我在Literal1试了,但是它在网页显示了两个两个条形码
------解决方案--------------------------------------------------------
去掉Response.Write(Literal1.Text);
------解决方案--------------------------------------------------------
Literal1.Text = CreateBarCode("leaves", 50, 3, true);
Response.Write(Literal1.Text);
在这里你一个给Literal1赋值了,页面显示了Literal1的值
下面由重新把Literal1的值给写出来,那么页面肯定是会有2个Literal1的值
去掉Response.Write(Literal1.Text),保留给Literal1赋值
------解决方案--------------------------------------------------------
Response.Write(Literal1.Text);
这个代码去掉试试
------解决方案--------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Literal1.Text = CreateBarCode("4242", 50, 3, true);
}
}