问题描述
好吧,我有一个软件(创作工具),它有一些功能,我可以通过它在我的C#应用程序中从中获取值。所以我试图获取TestName的值。在它之后我想在标签中显示所获取的值,比如说Label1。我运行代码,但它没有显示获取的值测试1,而只是显示Label1。因此,当我在Visual Studio 2010中使用F10调试代码时进行测试时,我看到在第一个循环中它获取了正确的值Test 1,而在Label中它也显示了正确的值Test 1。但后来不知道为什么在完成后,它再次进入第一行代码并再次执行整个循环。那时它显示空值,因此在运行时,它不会显示我想要的值,只显示Label1。我在.aspx.cs的Page_Load中编写代码,我的标签位于同一页面的.aspx中。救命。代码在这里。
代码就在这里。
test.aspx.cs
Well, I have one software(Authoring tool), it has some functionality by which I can fetch values from it in my C# application. So I am trying to fetch a value for TestName. After it I want to display that fetched value in a label, say Label1. I run the code but it is not showing the fetched value "Test 1", instead it just show me "Label1". So for testing when I debug the code using F10 in Visual studio 2010, I saw that in first loop it fetches the correct value that is "Test 1" and in Label also it shows correct value, "Test 1". But then don't know why after completing, it again goes to the first line of code and again whole loop executes. At that time it shows null values and thus at run, it doesnt show me desired value just showing "Label1". I am writing the code in Page_Load of .aspx.cs and my label is in .aspx of the same page. Help. Code is here.
Code is here.
test.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Collections;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ //get the parameters posted from the test
if (Page.IsPostBack)
{ }
else
{
string testname = Request.Form["TestName"];
Label1.Text = testname;
}
}
}
test.aspx:
test.aspx :
<%@ Page Language="C#" debug="true" AutoEventWireup="true" CodeFile="test.aspx.cs"
Inherits="test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<%--<script type="text/javascript" language="Javascript">
function setValues()
{
//first check if you get TestName value byusing alert
alert(document.getElementById("TestName").value);
document.getElementById("Label1").innerHTML =
document.getElementById("TestName").value;
//give return false to avoid postback
return false;
}
</script>--%>
<form id="form1" runat="server">
<div>
</div>
<p>
<asp:Label ID="Label1" runat="server" Text="Label" Font-Size="Larger"></asp:Label>
</p>
</form>
</body>
</html>
推荐答案
You must be setting that label some where else false
。这就是它没有显示的原因。
. That is why its not showing.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
protected void Page_Load(object sender, EventArgs e)
{
if(!Ispostback)
{
//your code;
}
}
这篇关于标签不在asp.net,visual studio 2010中显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!