handling user control event

G

Guest

Hi all,
I have an event in user control email to handling email change when user
want to change the input for email address. Here it is
In email.ascx.vb:
Protected Sub UpdateEmail(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TxtEmail.TextChanged
If Session("Email") <> Me.Email Then
Session("Email") = TxtEmail.Text 'or me.email
End If
End Sub
In email.ascx, I have
<asp:TextBox id="TxtEmail" OnTextChanged="UpdateEmail" runat="server"
</asp:TextBox>
My purpose is to update session variable if there is anything has been
changed for the email address.
But his event doesn't fire after I made the change in the text box until I
click the continue button on the page. The update session variable doesn't
work. I don't know why.

And I have to add the some code in the page containing the email user
control to make the update working. But it doesn't make any sense to me to
have event handler. here it is:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Session("Email") <> "" Then
If Email.Email <> Session("Email") Then
Session("Email") = Email.Email
Else
Email.Email = Session("Email")
End If

End If

End Sub
 
T

Terry Burns

1.) In order for you to do a postback when you exit the textbox, you need to
set the Autopostback property to True for that TextBox..

2.) <<<*** If you have already tested that Email.Email <> Session.("Email")
is False ( meaning they are the same ) then
why do you need to make the assignment. Or have I missed something ?
 
G

Guest

Terry,
thank you. I forgot that autopastback issue.
for Email.Email = Session("Email") <<< ****
is to make sure that when users navigate the pages, I want to make sure that
the value in the control wouldn't disappear, that's why, each time the page
is reloading and if the session variable is there already and not changed,
reload that value to control again. I think I probably didn't design the
program in a right way.
Do you have better idea besides Steven mentioned that I can use .net 2.0 to
solve this problem?

--
Betty


Terry Burns said:
1.) In order for you to do a postback when you exit the textbox, you need to
set the Autopostback property to True for that TextBox..

2.) <<<*** If you have already tested that Email.Email <> Session.("Email")
is False ( meaning they are the same ) then
why do you need to make the assignment. Or have I missed something ?
 
S

Steven Cheng[MSFT]

Hi Betty,

After you apply the "AutoPostBack" =true to the Textbox, each time
TextBox's Text is change at client, the page will be posted back, and you
can update the session in the TextBox's TextChanged event handler. There is
not need to add the update code in Page_Load again. If you want to keep
the TextBox's Text synchronous with the Session's value, just add the code
in (Not IsPostBack) because during post back, the TextBox's Text should be
the latest value (unless the same user open this page again and update this
value :))

====================
Private Sub Page_Load

If Not Page.IsPostBack Then

Email.Email = Session("xxx")
End If

End Sub
===================

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top