Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: Hyperlink copy question

Reply
Thread Tools

Re: Hyperlink copy question

 
 
Brian Williams
Guest
Posts: n/a
 
      01-17-2007
When you do me.myotherLink = klink they both point to the same object in
memory essentially they are the same object.
What I would do is create a clone method adding all the properties and
attributes.

I don't know VB.Net so my example will be in C#.

HyperLink hlnk = this.gvSSShot.SelectedRow.FindControl("hlnk_BPChar t");
HyperLink hl = Clone(hlnk);
hl.ID = "NewControlID";
PlaceHolder1.Controls.Add(hl);

private static HyperLink Clone(HyperLink ctrl)
{
HyperLink hl = new HyperLink();
hl.Text = ctrl.Text;
hl.ImageUrl = ctrl.ImageUrl;
hl.NavigateUrl = ctrl.NavigateUrl;

foreach (string attribute in ctrl.Attributes.Keys)
{
hl.Attributes[attribute] = ctrl.Attributes[attribute];
}
return hl;
}

I hope this helps, maybe someone will have a better solution.

Regards,
Brian K. Williams

"Yankee Imperialist Dog" <(E-Mail Removed)>
wrote in message news:(E-Mail Removed)...
> why does this not work: I'm trying to resign the values from one Hyperlink
> to
> another hyperlink
> Dim hlnk As HyperLink =
> Me.gvSSShot.SelectedRow.FindControl("hlnk_BPChart" )
> ' then just give it everything from the found link
> me.myotherLink = hlnk
>
> It seems to me this should work and negate the need to assign text,
> NavagateURL, target, ....
>
> Anyone know why?
> Thanks
> --
> Share The Knowledge. I need all the help I can get and so do you!



 
Reply With Quote
 
 
 
 
Brian Williams
Guest
Posts: n/a
 
      01-17-2007
Objects are by value when passing them without specifying, you would need to
specify (ref) otherwise.

When you do me.myotherLink = hlnk both refer to the same object they are
still however independent objects themselves. Changing the value of the
first will not change the value of second even though their values are still
references to the same object, changes made to the object through the first
object will be visible through the second object.

I hope I didnt' make this more confusing...

Regards,
Brian


"Yankee Imperialist Dog" <(E-Mail Removed)>
wrote in message news:(E-Mail Removed)...
> Thanks for responsing,
> That is exactly what i have done except not with a loop (yet). I'm
> starting
> create a "bag" of functions (or Subs) for situations like this.
> 1. I thouht that objects were by value not by reference in dot.net?
> 2. in the loop would the id be overwritten as it is an attribute?
>
> Still new to this so hope my question makes sense....
> --
> Share The Knowledge. I need all the help I can get and so do you!
>
>
> "Brian Williams" wrote:
>
>> When you do me.myotherLink = klink they both point to the same object in
>> memory essentially they are the same object.
>> What I would do is create a clone method adding all the properties and
>> attributes.
>>
>> I don't know VB.Net so my example will be in C#.
>>
>> HyperLink hlnk = this.gvSSShot.SelectedRow.FindControl("hlnk_BPChar t");
>> HyperLink hl = Clone(hlnk);
>> hl.ID = "NewControlID";
>> PlaceHolder1.Controls.Add(hl);
>>
>> private static HyperLink Clone(HyperLink ctrl)
>> {
>> HyperLink hl = new HyperLink();
>> hl.Text = ctrl.Text;
>> hl.ImageUrl = ctrl.ImageUrl;
>> hl.NavigateUrl = ctrl.NavigateUrl;
>>
>> foreach (string attribute in ctrl.Attributes.Keys)
>> {
>> hl.Attributes[attribute] = ctrl.Attributes[attribute];
>> }
>> return hl;
>> }
>>
>> I hope this helps, maybe someone will have a better solution.
>>
>> Regards,
>> Brian K. Williams
>>
>> "Yankee Imperialist Dog" <(E-Mail Removed)>
>> wrote in message
>> news:(E-Mail Removed)...
>> > why does this not work: I'm trying to resign the values from one
>> > Hyperlink
>> > to
>> > another hyperlink
>> > Dim hlnk As HyperLink =
>> > Me.gvSSShot.SelectedRow.FindControl("hlnk_BPChart" )
>> > ' then just give it everything from the found link
>> > me.myotherLink = hlnk
>> >
>> > It seems to me this should work and negate the need to assign text,
>> > NavagateURL, target, ....
>> >
>> > Anyone know why?
>> > Thanks
>> > --
>> > Share The Knowledge. I need all the help I can get and so do you!

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a hyperlink column to asp.net datagrid - where only one value is a hyperlink davetichenor ASP .Net 1 10-30-2006 02:57 PM
How to add a hyperlink column to asp.net datagrid - where only one value is a hyperlink Dave ASP .Net Datagrid Control 0 10-21-2006 07:48 PM
what is Deep Copy, shallow copy and bitwises copy.? saxenavaibhav17@gmail.com C++ 26 09-01-2006 09:37 PM
is dict.copy() a deep copy or a shallow copy Alex Python 2 09-05-2005 07:01 AM
Dynamically Hyperlink and Event Handler for the Hyperlink ? Ken ASP .Net Datagrid Control 1 08-15-2003 11:38 PM



Advertisments