开发者

View state after postback VB?

开发者 https://www.devze.com 2023-02-24 10:22 出处:网络
I have a label\'s value that is posted back from a previous page and I want to use this label to do a simple calculation in the current pa开发者_高级运维ge, but when I do the calculation the page (ref

I have a label's value that is posted back from a previous page and I want to use this label to do a simple calculation in the current pa开发者_高级运维ge, but when I do the calculation the page (refreshed) the value of this label and automatically deleted the value (Since there would be no value in postback when it refreshed).

Here is the code behind file:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles   Me.Load
    Label2.Text = Request.Form("Hidden1")
End Sub

and here where I want to use the label

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Stotal As String
    Stotal = Val(Label2.Text) * 10
    Label3.Text = Stotal
End Sub

How can I save the value in the page via view state or any other method? Thanks in advance


Unless you've disabled ViewState on your page, the problem isn't that your label's ViewState isn't being saved, it's that you're overwriting it in your Page_Load method on the postback since the form variable Hidden1 is no longer being posted to your page from the previous page. Try:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles   Me.Load
    If Not IsPostBack
        Label2.Text = Request.Form("Hidden1")
    End If
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消