保留在页面刷新文本框值

保留在页面刷新文本框值

本文介绍了保留在页面刷新文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件UC1一个文本框。我已经嵌入这个UC1在Default.aspx的网页叫。我的问题是运行应用程序并输入在文本框中的一些数据后,刷新页面时,我想表明我在文本框中输入和不明确的文本框的值。我想就如何才达到这个code的帮助。在此先感谢您的帮助。

I have a textbox in a user control uc1. I have embedded this uc1 in a page called default.aspx. My issue is after running the application and entering some data in the textbox, when refresh the page i would like to show the values that i have entered in the textbox and not clear the textbox. I would like help with code on how to achive this. Thanks in advance for your help.

推荐答案

我能够刷新页面,而不在文本框中清除值。我做到了,如下:
我创建了如下UC1.vb公共财产:
公共财产textbox_value()作为字符串

I was able to refresh the page without clearing the value in textbox. I did it as below:I created a public property in the UC1.vb as below:Public Property textbox_value() As String

    Get
        If Session("textbox1") IsNot Nothing Then
            Return Session("textbox1").ToString()
        Else
            Return ""
        End If
    End Get
    Set(value As String)
        Session("textbox1") = value
    End Set
End Property

和用户控件的Page_Load事件我增加了code如下:
        如果随后的IsPostBack
            textbox_value = textbox1.Text
        elseif的不是那么的IsPostBack第一次页面加载或刷新页面时,
            textbox1.Text = textbox_value
         结束如果

And in the page_load event of the user control i added the code below: If IsPostBack Then textbox_value= textbox1.Text ElseIf Not IsPostBack Then ' First time the page is loaded or when the page is refreshed textbox1.Text = textbox_value End If

希望它帮助。

这篇关于保留在页面刷新文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:48