Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
R

Rico MNC

@Rico MNC
About
Posts
4
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How to access a ListBox within a custom control with Javascript in the aspx page.
    R Rico MNC

    Turns out my previous solution was a trip down an evil rabbit hole due to reusing a global variable from my JavaScript in my code behind (doh). Here is the corrected solution, which is a bit uglier: First, in the custom control I made a public property for the listbox ClientID within the control I wished to access in my Javascript:

    public partial class Controls_Locations : System.Web.UI.UserControl
    {
    public ListBox Locations
    {
    get {return lbControlVehicles.ClientID; }

    }

    Then in my page code behind I provided a public property for this listbox ClientID string:

    private Controls_Locations userLocations;

    public string UserVehiclesListBox
    {
    get { return userLocations.Locations; }

    }

    In my Page_Load I initialize userLocations:

    protected void Page_Load(object sender, EventArgs e)
    {
    if (Page.IsPostBack == false)
    {
    userLocations = this._Locations1;// _Locations1 is the custom control in my aspx file which contains the listbox I want to access

    In my aspx file using Javascript:

    <uc1:RastracUserVehicle_Locations ID="RastracUserVehicle_Locations1" runat="server" />

    <script type="text/javascript" language="javascript">

    var myLocationList;

    function getLocationListBox()
    {
    myLocationList = $get("<%=UserVehiclesListBox%>");

    //myLocationList is now the listbox contained within the custom control

    }

    I used a "global" Javascript variable so that I only need to get the list once. I have not yet discovered whether accessing the list will cause a post back to the server everytime.

    ASP.NET javascript design sysadmin tools tutorial

  • Accessing custom control using javascript on the client page.
    R Rico MNC

    When I try this:

    var foo = $find<"%=_Locations1.ClientID%>");

    The dynamic page during debug shows:

    var foo = $find"ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolderMain__Locations1");

    and foo is null after stepping through it.

    ASP.NET csharp javascript html help tutorial

  • Accessing custom control using javascript on the client page.
    R Rico MNC

    Yes I am aware of the name mangling, and have tried all my usual solutions. I will post more details and examples later. Thanks for trying to help.

    ASP.NET csharp javascript html help tutorial

  • Accessing custom control using javascript on the client page.
    R Rico MNC

    I have been tasked with replacing some DOM and javascript with an ASP custom control. The aspx page is using master pages. What I need to do is access the custom control with javascript in the aspx page. The control and its C# code behind are working, but I need to access a listbox contained within the control. I seem to be unable to access the control at all. For example, in the aspx page I have the custom control like this:

    ;

    In another page using an AJAX slider control, I have been able to access it like this:

    var sliderUpdater = $find("SliderBehavior");

    ... then I am able to get and set properties for the slider. However, trying similar approaches with our custom control all results in returning null from the $find. Note: our control does not currently have any extenders or BehaviorID. I will post more code details if necessary. Any ideas, help, or links would be appreciated. Thank you.

    ASP.NET csharp javascript html help tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups