+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / user.aspx/javascript

user.aspx/javascript

5 posts, 0 answered
  1. tim
    tim avatar
    27 posts
    Registered:
    12 Oct 2010
    04 Nov 2010
    Link to this post
    hi

    i wanted to add some javascript to the user.aspx page where I need to reference a particular textbox, normally I would do this

    document.getElementById('<%=UserCompany.ClientID %>').value

    however this fails complaining that UserCompany doesnt exist. I could write something in javascript to loop through everything and search ofr what I want but that seems a touch messy, is there a way when the page renders I can find that control ?

    thanks
    tim
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Nov 2010
    Link to this post
    Hi tim,

    You can use UserCompany.ClientID if UserCompany is in the current context. It is the same as $find.
    You can take a look at jQuery traversing

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. tim
    tim avatar
    27 posts
    Registered:
    12 Oct 2010
    04 Nov 2010
    Link to this post
    hi
    sorry, i wasnt very clear with the problem there, i get a compilation error 

    Compiler Error Message: CS0103: The name 'UserCompany' does not exist in the current context

    so I guess they're not in the current context, so where are they ? oh my days.... they're in the page, rendered and doing what they should but I just cant get to them, do I need to find within another control (the manageProfile panel )?

    tia
    tim
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Nov 2010
    Link to this post
    Hi tim,

    Most probably you use nested controls and the UserCompany is part of the controls collection of a control that is on the first level.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. tim
    tim avatar
    27 posts
    Registered:
    12 Oct 2010
    04 Nov 2010
    Link to this post
    hi ivan

    thanks for getting back so quickly, I've sorted fit out now, using the same routine as i do in the code behind but in actual page and then spit out my javascript var.  code below just in case anyone else wants/needs it

    //get our usercompany id
    <%
    Telerik.Security.WebControls.ManageUsers.EditContainer editContainer = manageUsers.GetCurrentContainer() as Telerik.Security.WebControls.ManageUsers.EditContainer;
    if (editContainer != null)
    {
        ManageProfile p = editContainer.FindControl("manageProfile") as ManageProfile;
        var container = (((System.Web.UI.WebControls.CompositeControl)(p)).Controls[0]);
        if (container is ManageProfile.EditContainer)
        {
            var editCont = container;
            foreach (Control co in editCont.Controls)
            {
                if (co is TextBox)
                {
                    if (co.ID == "UserCompany")
                    {
                        Response.Write("var UserCompanyId= '" + co.ClientID + "';);
                    }
                }
            }
        }
    }
    %>
    hth

    tim
Register for webinar
5 posts, 0 answered