How can I change the NavigateUrl inside the user control ?

J

jeanluc.praz

I created a user control containing containing a few hyperlinks.
How can I change the NavigateUrl inside the user control ?

So far I did the following:

1) In the custom control

Code:
Public Property SetURL()
Get
SetURL= sModificarURL
End Get
Set(ByVal Value)
sModificarURL = Value

End Set
End Property

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
Me.hlnkModificar.NavigateUrl = sModificarURL
End Sub

2) In the page containing the control:
Code:
Dim cc As New myCustomControl
cc.SetURL= "Cv_1.aspx?x=" & Request("x")

My problem is that at PreRender the value I passed down to the property
doesn't exist any more.

Any other way of achieving this ?
Jean-Luc


www.corobori.com
 
G

Guest

First of all, it's better to directly assign to and get data from NavigateUrl
rather than via PreRender event:

Public Property SetURL() As String
Get
Return Me.hlnkModificar.NavigateUrl
End Get
Set(ByVal Value)
Me.hlnkModificar.NavigateUrl = Value
End Set
End Property

Seconly, you should get reference of usercontrol rather than create a new
usercontrol instance.

Dim cc As myCustomControl = CType(Me.FindControl(myCustomControl_ID),
myCustomControl)
cc.SetURL= "Cv_1.aspx?x=" & Request("x")


HTH

Elton Wang
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top