0

currenly I worked on a project with heavy javascript, do all the logic at client side, that mean manipulate form field values using javascipt, but when I post back to server I cant get the value on server side. example below:

Aspx

 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
 <asp:Button ID="Button1" runat="server" Text="Button" />

 <script type="text/javascript">
      $("#<%= Label1.ClientId %>").html("200");
   </script>

code behind

  Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Response.Write(Label1.Text)
   End Sub

I have manipulate the values using javascript, but when click the button post back, I still get "Label". I not sure whether is the viewstate issue, I have try to turn off the viewstate of the control but the result is still same.

4

1 回答 1

1

如果情况是针对单个标签,则可以快速解决,然后可以将该值保留在隐藏字段中并发布。然后它将在服务器中可用。如前所述,如果代码可以将操作值保留在许多标签中,并且为所有这些标签保留隐藏字段将很繁重。可以有一个 jquery ajax 调用来发布数据,而不是作为建议发布整个页面。

<input id="Hidden1" type="hidden" value ="manipulated value" />
于 2013-07-16T12:07:50.687 回答