VB.NET - Error:Hyperlink1 is not declared - Asked By pradnya sahu on 23-Nov-11 01:14 AM

In my application in .aspx page i have drag-drop "Hyperlink" from ToolBox

On page load (in .aspx.vb) page i have written following code
HyperLink1.Visible = False

it's Workng but it giving an error in the Error list "HyperLink1 is not declared"

It's working still why it's giving error?????

Thanks
Jitendra Faye replied to pradnya sahu on 23-Nov-11 01:17 AM
Add runat="Server" Attribute to HyperLink.

<asp:HyperLink ID="HyperLink1" runat ="server" -----------></asp:HyperLink>



Like this-


Suchit shah replied to pradnya sahu on 23-Nov-11 01:18 AM

did you drag a HyperLink control onto your page from the toolbox? If so, ensure the name or ID is HyperLink1. Otherwise, I would guess that the hyperlink isn't actually on the page, since I didn't see any codebehind instantiation of it.

As a test, try putting this before the code giving you the trouble:

Dim HyperLink1 as new HyperLink()
Me.Page.Controls.Add(HyperLink1)

Web Star replied to pradnya sahu on 23-Nov-11 01:24 AM
No, if runat="server" are missing than he can't access that control in code behind for set visible property.
I think then declareation of hyperlink control are in Web Form Designer generated code, because you are use it by drag and drop.  And may be some other hyperlink on that page show error like not declared.
Reena Jain replied to pradnya sahu on 23-Nov-11 01:33 AM
Hi,

As you have told you drag a HyperLink control onto your page from the toolbox. If so, ensure the name or ID is HyperLink1.  Otherwise, I would guess that the hyperlink isn't actually on the page, since I didn't see any codebehind instantiation of it.

As a test, try putting this before the code giving you the trouble:

Dim HyperLink1 as new HyperLink()
Me.Page.Controls.Add(HyperLink1)

pradnya sahu replied to Suchit shah on 23-Nov-11 01:46 AM

Thanks.. Actually i have drag and drop HyperLink1 on 1 page and same i want in the 2nd page so..i have copied that Hyperlink1 and paste into 2nd page.

So what is the reason?? and i have already written runat ="Server"
Asked By pradnya sahu on 23-Nov-11 01:46 AM
Thanks.. Actually i have drag and drop HyperLink1 on 1 page and same i want in the 2nd page so..i have copied that Hyperlink1 and paste into 2nd page.

So what is the reason?? and i have already written runat ="Server"
pradnya sahu replied to Jitendra Faye on 23-Nov-11 01:47 AM
Thanks.. Actually i have drag and drop HyperLink1 on 1 page and same i want in the 2nd page so..i have copied that Hyperlink1 and paste into 2nd page.

So what is the reason?? and i have already written runat ="Server"
Jitendra Faye replied to pradnya sahu on 23-Nov-11 02:03 AM
Ok, after copying that HyperLink check it's name in page2,