0

Hi,

I am working with asp.net and in my web user control i have several buttons and textboxes.

FirstBtn cliked---->FirstTextBox ----->displays: "Hi"
secondBtn clicked--->SecondTextBox ------>displays:"Hello"

Now again if i click the firstbtn then the FirstTextBox would be empty.Can anyone tell me how can i sane the last entered value?


Regards,
Mishal

4
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by prashantchalise
0

Hi,
Did you mean to maintain the values even after post back by using ViewState.
If it is then try something like this,

1) Declare your properties

'Property Hi
		Public Property displayHi() As String
			Get
				Return Cstr(ViewState("displayHi"))
			End Get
			Set(ByVal value As String)
				ViewState("displayHi") = value
			End Set
		End Property

		'Property Hello
		Public Property displayHello() As String
			Get
				Return Cstr(ViewState("displayHello"))
			End Get
			Set(ByVal value As String)
				ViewState("displayHello") = value
			End Set
		End Property

2) Set in Page Load

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
			displayHello = "Hello"
			displayHi = "Hi"
End If
End Sub

3) Finally, append values in button event

'First Button for Hi
Protected Sub btnFirstBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFirstBtn.Click
'Some Display function
Display(displayHi)
End Sub

'2nd Button for Hello
Protected Sub btnSecondBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSecondBtn.Click
'Some Display function
Display(displayHello)
End Sub

That's all dude. :-)

Edited by prashantchalise: n/a

0

click TextBox, go to properties. Make the following changes:-

AutoPostBack=true
EnableViewState=true

Hope it helps.

0

u can't use viewstate in user control, when u want to move around your pages

Hi, I'm not sure but I don't think ViewState can't be used with User Control.

You can review it here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.