Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

LoginView Linkbutton not being seen by document.getElementById() ... Linkbutton does not exist in the current context

Posted on 2007-11-20
11
Medium Priority
?
1,000 Views
Last Modified: 2013-12-17
Here is the error I recieve : The name 'LinkButton5' does not exist in the current context      
   
<script type="text/javascript" language="javascript">  
    function MouseOver1(e)
    {
switch (e);
case1:
document.getElementById('<%=LinkButton1ClientID%>').style.color = "Blue";
break;
case 2:
document.getElementById('<%=LinkButton2.ClientID%>').style.color = "Blue";
break;..........etc on the case and breaks and } below just didnt want to type them :)
document.getElementById('<%=LinkButton3.ClientID%>').style.color = "Blue";
document.getElementById('<%=LinkButton4.ClientID%>').style.color = "Blue";
document.getElementById('<%=LinkButton5.ClientID%>').style.color = "Blue"; which references a linkbutton as you can see but LinkButton5 id is within a loginview unlike 1 through 4 which are right in the aspx page not imbeded within a loginview:

<asp:LoginView ID="LoginView2" runat="server">
                            <LoggedInTemplate>
                                        <asp:LinkButton ID="LinkButton5" runat="server" ForeColor="WhiteSmoke" onmouseover="MouseOver1(5)" onmouseout="MouseOver2(5)">Blah</asp:LinkButton>

linkbuttons 1 through 4 that are in the main aspx program and not in a loginview change color when moused over without issues.... but since linkbutton5 is with that LoginView it is somehow out of context any info or code snipit that show how I can bring it back in context??

Appreciate the help.

             Thanks in advance!!
0
Comment
Question by:pugmi16
  • 6
  • 3
  • 2
11 Comments
 
LVL 3

Expert Comment

by:john_steed
ID: 20326095
Hi there,

Try using UniqueID instead of ClientID. ClientID might only return the name of the control itself, but once rendered it will get an id like parentcontrol_control.

Hope this helps
0
 
LVL 4

Expert Comment

by:kirankumar_goura
ID: 20326106
Change your JavaScript function MouseOver1 to ...
function MouseOver1(e)
{      
       document.getElementById("LinkButton"+e).style.color = "Blue";
}
and then remove "onmouseover" event from all of your <asp:LinkButton> controls and add
the following code Page_Load event ...
 LinkButton1.Attributes.Add("onmouseover", "MouseOver1(1)");
 LinkButton2.Attributes.Add("onmouseover", "MouseOver1(2)");
 LinkButton3.Attributes.Add("onmouseover", "MouseOver1(3)");
 LinkButton4.Attributes.Add("onmouseover", "MouseOver1(4)");
 LinkButton5.Attributes.Add("onmouseover", "MouseOver1(5)");

Let me know for further assistance.

- Kiran G
0
 

Author Comment

by:pugmi16
ID: 20329606
Kirankumar I added the following to the codebehind page:

    protected void Page_Load(object sender, EventArgs e)
    {
        LinkButton1.Attributes.Add("onmouseover", "MouseOver1(1)");
        LinkButton2.Attributes.Add("onmouseover", "MouseOver1(2)");
        LinkButton3.Attributes.Add("onmouseover", "MouseOver1(3)");
        LinkButton4.Attributes.Add("onmouseover", "MouseOver1(4)");
        LinkButton5.Attributes.Add("onmouseover", "MouseOver1(5)");
    }

But am getting the error: The name 'LinkButton1' does not exist in the current context
                                        The name 'LinkButton2' does not exist in the current context....etc  out to to 5

but on the page I do have the id LinkButton1, 2...etc not sure why the code behind page doesn't see it:

                            <div style="height: 40px; margin-top: 10px; margin-left: 4px;">
                                <asp:LinkButton ID="LinkButton1" runat="server" ForeColor="WhiteSmoke">Guild Charter</asp:LinkButton>
                            </div>
                            <div style="height: 40px; margin-left: 4px;">
                                <asp:LinkButton ID="LinkButton2" runat="server" ForeColor="WhiteSmoke">Guild  Rules</asp:LinkButton>
                            </div>
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:pugmi16
ID: 20329834
John I also did what yous said and used uniqueID ... I belive :) I went and compiled the project ran it and then looked at the html it contained a unique ID of (ctl00_LoginView2_LinkButton5) instead of LinkButton5. I then pasted it in:

      case 5:
        document.getElementById('<%=ctl00_LoginView2_LinkButton5.ClientID%>').style.color = "Blue";
        break;
      }

and I still get:
The name 'ctl00_LoginView2_LinkButton5' does not exist in the current context
0
 

Author Comment

by:pugmi16
ID: 20329842
I am upping this another 50 points as I appreciate you guys working with me on this current context still popping up as and issue.
0
 

Author Comment

by:pugmi16
ID: 20329858
John, Sorry I forgot to mention I changed it to uniqueid  also and it still came up with out of current context:

      case 5:
        document.getElementById('<%=ctl00_LoginView2_LinkButton5.UniqueID%>').style.color = "Blue";
        break;


The name 'ctl00_LoginView2_LinkButton5' does not exist in the current context
0
 
LVL 3

Expert Comment

by:john_steed
ID: 20330200
Hey,
Did you get an error in your original code using <%=LinkButton5.ClientID%> before ? Or did it just return a name that is not the clientname of your control ? (You can check by doing "view source" in internet explorer)
If it works but doesn't gave you the right clientname, try using  <%=LinkButton5.UniqueID%> in your original code.

Otherwise you might have to try something like LoginView2.FindControl("Linkbutton5").ClientID


0
 

Author Comment

by:pugmi16
ID: 20330490
Hey John

 I sure did... When I used <%=LinkButton5.ClientID%> it came back with LinkButton5' does not exist in the current context.

I just tried:
document.getElementById(LoginView2.FindControl("Linkbutton5").ClientID).style.color = "Blue";
and
document.getElementById(LoginView2.FindControl("Linkbutton5").UniqueID).style.color = "Blue";
and
document.getElementById('<%=LoginView2.FindControl("Linkbutton5").UniqueID%>').style.color = "Blue";

Did not Give any compile errors of being out of current context yaaaa but doesn't turn blue LOL ...

0
 
LVL 3

Accepted Solution

by:
john_steed earned 700 total points
ID: 20330539
can you tell me what this
document.getElementById('<%=LoginView2.FindControl("Linkbutton5").UniqueID%>').style.color = "Blue";
becomes (between <% and %>) when you run the page ? (you can see when doing "view source")

also look for the linkbutton5 element when viewing source and tell me what his id is

thanks
0
 
LVL 4

Assisted Solution

by:kirankumar_goura
kirankumar_goura earned 700 total points
ID: 20332684
But am getting the error: The name 'LinkButton1' does not exist in the current context
                                        The name 'LinkButton2' does not exist in the current context....etc  out to to 5

but on the page I do have the id LinkButton1, 2...etc not sure why the code behind page doesn't see it:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.>>>>>>>>>>>
When LoginView control being added onto a page and LoggedInTemplate is applied on the Control
instance, so at that time, we can only retrieve the reference of those controls like
        Control ctrl = FindControl("loginView");
        LinkButton Link5 = (LinkButton)ctrl.FindControl("Link5");
So first you have to determine whether the user has been
authenticated or not and then use the LoginView.FindControl( stringId)
together with the sub control's ID to retrieve the control reference.
0
 

Author Closing Comment

by:pugmi16
ID: 31410292
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question