English 中文(简体)
页: 1 使用java制成可装值,但无
原标题:asp.net: Use javascript set lable value but it doesn t save
  • 时间:2012-01-12 07:54:02
  •  标签:
  • asp.net

这是我的法典:

<form id="form1" runat="server">
<div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <input type="button" onclick="ontextchange();" />

    <asp:Button ID="Button1" runat="server"
        Text="Button" onclick="Button1_Click" />
</div>


function ontextchange() {

         document.getElementById("Label1").innerText="New";

    }

问题在于:我可以通过javascript改变可装值,但在我点击Button1时,可装值成为第一个“Label”。 当我点点击 as牛顿时,我怎么能拿到新的价值呢?

最佳回答

你可能试图利用一个隐蔽的领域,但你需要保持客户方文字和服务器方活动手的同步。

<asp:Hidden ID="Hidden1" runat="server" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

Java:

function ontextchange() {
  // Set the label for the visual result
  document.getElementById("Label1").innerText="New";
  // Set the hidden input for the server
  document.getElementById("Hidden1").value="New";
}

服务器边可以读到隐藏的投入并更新标签(保持同步):

protected void Button1_Click(object sender, EventArgs e)
{
  // Set the label text to the value from the hidden input
  string value = Hidden1.Value;
  Label1.Text = value;
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签