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

Recommended Answers

All 4 Replies

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. :-)

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

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

AutoPostBack=true
EnableViewState=true

Hope it helps.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.