Can someone explain this? I appreciate some help. Thank You.

S

Shapper

Hello,

I have a third party control in my page. I need to set the properties of
Labels and Images in this control when:
1. User enters the Page.
2. A button is clicked which changes culture (Change Properties)

Usually I would do it this way:

Sub Page_Load(...)
Set_Properties()
End Sub

Sub myMenu_MenuItemSelected(...) Handles myMenu.ItemSelected
Set_Properties()
End Sub

Sub Set_Properties() is:
Dim img As System.Web.UI.WebControls.Image =
myControl.FindControl("_ctl0").FindControl("imgLogo")
img.AlternateText = "New Text"
...
End Sub

Well, it doesn't work. I have this information:
"The control loads data and build object model in OnLoad event handler,
which occurs exactly after Page_Load event. The control objects can't be
accessed before or in Page_Load function.
This can be solved either using Page_Prerender function or any element
event handler for example Button_Click, etc., which occurs after
Page_Load event."

Well, with this info I made it work:

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
Dim img As System.Web.UI.WebControls.Image =
myControl.FindControl("_ctl0").FindControl("imgLogo")
img.AlternateText = "New Text"
...
End Sub

Sub myMenu_MenuItemSelected(.) Handles myMenu.ItemSelected
Dim img As System.Web.UI.WebControls.Image =
myControl.FindControl("_ctl0").FindControl("imgLogo")
img.AlternateText = "New Text"
...
End Sub

Well, even if it works I am duplicating my code which makes no sense to
me in terms of optimization.
Note: The duplicated code will be much longer that the one I show.

Can someone help me with this?

Am I following the wrong idea?

Thank You Very Much,
Miguel
 
W

willow

you try it:
Sub Page_Load(...)
If IsPostBack = False Then
Set_Properties()
End If
End Sub

Sub myMenu_MenuItemSelected(...) Handles myMenu.ItemSelected
Set_Properties()
End Sub
 
S

Shapper

I tried. It doesn't work.

you try it:
Sub Page_Load(...)
If IsPostBack = False Then
Set_Properties()
End If
End Sub

Sub myMenu_MenuItemSelected(...) Handles myMenu.ItemSelected
Set_Properties()
End Sub
 
W

willow

hi,Miguel
I think your first way is right;The control has existed in your page when
anybody access your page.
So.I think,problem is existed in otherwise.I read your code,i found only
one:
Dim img As System.Web.UI.WebControls.Image =
myControl.FindControl("_ctl0").FindControl("imgLogo")

may be it is wrong that parameter of method FindControl ,it is your
control's name.you should find control's name in your page source.
By the way,you should debug your code,may be you will find the true.

Best wishes
Willow Yang
 

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,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top