.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Access UserControl Control from a JavaScript Function

Posted By:      Posted Date: September 06, 2010    Points: 0   Category :ASP.Net
I have a requirement to launch a Modal Javascript dialog box from within my usercontrol,I have done this by <code> function browseControlAction(ProjID,ControlID) { strPrompt = 'Select a Previous control action..'; strOptions = 'dialogWidth:25;dialogHeight:30;status:no;resizable:yes'; selectedAction = window.showModalDialog('browseControlActions.aspx?ProjID=' + ProjID + '&Control=' + ControlID, strPrompt, strOptions); var sControl = ' + ControlID + '; if (selectedAction != null) { alert(ControlID.toString()); alert(selectedAction); var sTest = ControlID + '_txtControlAction'; alert(sTest); var sTest2 = 'txtSummary'; alert(sTest2); document.getElementById('txtCurrentControls').innerText=selectedAction;   //this works as this a control on the page itself document.getElementById(sTest2).innerText=selectedAction;      //Ditto document.getElementById(sTest).innerText=selectedAction;    //This Fails as this is the control in the USercontrol I am trying to Access //__doPostBack(','); }</code>can anybody tell me why I can't access the Textbox control on the USercontrol?

View Complete Post

More Related Resource Links

Acessing controls in usercontrol in javascript function where user control hosted in webpart



1how to acess controls in usercontrol  in javascript function where user control hosted in webpart


2)How to retieve values from javscript code to server side

details as follows

StringBuilder controlString = new StringBuilder();
            controlString.Append("<p>" + CurrentPage.ToString() + "of " + TotalPages.ToString() + " </p>");
            for (int intIndex = 1; intIndex <= TotalPages; intIndex++)
                controlString.Append("<li><a hre

Access control within a usercontrol from Javascript


I have a javascript embedded in my extended gridview control that reference the grid control. Example:

var DataGridObj = document.getElementById(GridView1);


where GridView1 is a variable and my calling program passes the grid name. This is ok if I place my extended gridview on aspx page and run. But, how if, I have gridview in a user control and that user control is being used in aspx?

My ASPX -> My User Control -> Extended GridView.

When I check the html code, my gridview has an ID of "UserControlID_ExtendedGridViewID". Example:

In Default.aspx

<uc1:MyGrid ID="MyGrid1" runat="server" />

In UserControl (MyGrid.ascx)

<cc1:ExtendedGridView ID="GridView1" runat="server" DataSourceID="XmlDataSource1" </cc1:GridView>

and, finally in ExtendedGridView.cs

function CreateGridHeader(DataDiv, GridView1, HeaderDiv) 
    var DataGridObj = document.getElementById(GridView1);
//other part of code

HTML code:

<table cellspacing="0" rules="all" border="0" id="MyGrid1_GridView1&q

Content page control passes as argument to javascript function


Here is the content page:


<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="JavaDynamicCopyValue.aspx.cs" Inherits="JavaDynamicCopyValue" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
 <script type="text/javascript" >
 function copyValue(input, output )
   ouput.value = input.value;
   return true;
 <asp:TextBox ID="txt1" runat="server" onchange="copyValue(this,document.getElementById('<%=txt2.ClientID%>'))"></asp:TextBox>
    <br />
    <br />
    <asp:TextBox ID="txt2" runat="server"></asp:TextBox>


I got a javascript run time error says output is undefined. if I view source of the page, the txt1 markup became:

<input name="ctl00$ContentPlaceHol

How to access ServerSide control Value in Javascript changed by Ajax

Hello,I have a Textbox whose value is been changed using ServerSide code (AJAX based - Partial postback) and now I want to access that changed value in JavaScript. Please suggest me that how can I access that value.document.getElementByID is displaying old value.Things work fine with full postback but are creating above issue with Partial Postback.Thanks, in Advance....

Accordion control access in Javascript using Content page

Hi, I struggled with some javascript issues, and discovered that the problem seemes to come from a failed ajax control access.Here's my problem:I have a master page and a content page.In my content page, I have an accordion with 2 panes.1rst pane: a textbox and a validation button;                     I want the button to fire javascript function without reloading page (using "return false;");In my master page, I put my ToolkitScriptManager.In my content page, I put my script containing the functions.The problem is that it seems like I can't access the accordion control in my js functions, whereas I can access my textbox value...Here is my source:<%@ Page Language="C#" MasterPageFile="~/Default.master" Title="CLEOR RH | Home" CodeFile="Default.aspx.cs" Inherits="Default_aspx" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> <asp:Content ID="Content1" ContentPlaceHolderID="Main" runat="server"> <script type="text/javascript"> var step1 = false; function pageLoad() { var accCtrl = $find('AccordionCtrl_AccordionExtender');

How to trigger a JavaScript function using "onmouseover" event on a SPMenuField control?



I could do something along these lines for TemplateField (with ItemTemplate having a HyperLink control):

private void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
     if (e.Row.RowType == DataControlRowType.DataRow)    
          ((HyperLink)e.Row.FindControl("lnk_id")).Attributes.Add("onmouseover", "someFunction();");    

For SPMenuField, which control should I set the "onmouseover" event to?



How do I write a string coming from a Javascript function in my Label control?


Hi all,

This is what I tried doing in my Javascript function (partially):

catch (err) {
              document.getElementById("lblError").innerHTML = err.description;

IE output of my lblError label component is a long id name like this:

<td>Last Error: <span id="ctl00_ctl00_ContentPlaceHolder_GlobalMasterPage_ContentPlaceHolder_DashboardMasterPage_lblError">No errors at this time.</span>

how do I look up for lblLabel in this case?

Thank you

Not able to access child controls in user control using javascript



I have a user control "SettingsControl" containing an ajax:CollapsiblePanelExtender which in turn has a GridView (gridView) and checkBoxes. On top of GridView we have two LinkButtons "Select All" and "Clear All". I have written to enable select all and clear all functionality. Select All should select all the rows in the grid by calling the following JavaScript written on the Client .aspx file.

function SelectAll(chk)
    //get reference of GridView control
    var grid = document.getElementById('<%= SettingsControl1.FindControl("gridView").ClientID %>');
    //variable to contain the cell of the grid
    var cell;

    if (grid.rows.length > 0)
        //loop starts from 1. rows[0] points to the header.
        for (i=1; i<grid.rows.length; i++)
            //get the reference of first column
            cell = grid.rows[i].cells[0];


How to access child(.ascx) page control from parent page(.aspx) javascript


I have functionality to select All check boxes on grid rows.

Child User control is having grid with checkbox to select all rows of grid. I want to select individual cell html from each row when I select all rows when checkbox 'select all' is clicked and place it into textbox which is in Parent page.

This textbox can only be in parent page.

So i need to call child(.ascx) page control from parent page(.aspx) using javascript as follows.

function CheckUncheckChildren(event)
        var childChkBoxes = document.getElementById('<%=gvUserDetails.ClientID %>').getElementsByTagName("input");
        var childChkBoxCount = childChkBoxes.length;
        var evtelem = (isIE())?event.srcElement:event.currentTarget;
        if(evtelem.checked == true)
            for(var i = 0; i<childChkBoxCount; i++)

Call javascript function on containing page from user control


I have a toolbar in a user control.  I would like to wire the toolbar's onclick event to a javascript function on the page that contains the user control.  What's the easiest way to do this?

Button control to stop Javascript Function on slideshow


Hi everyone-

I've got this slideshow I've pieced together that fades in and fades out.  However, when pushing the Stop Button (same as the Play button) to stop on a slide, the Javascript function continues and fades out so it stops on a blank .  How can I alter this javascript function to only fade in, stop on the slide and not fade out when the stop button is pushed?

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SlideShow7.aspx.vb" Inherits="SlideShow7" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <style type="text/css">
            margin: 50px 0px;
            padding: 0px;
            text-align: center;
            width: 475px;
            margin: 0px auto;
            text-align: center;
            padding: 20px;
            border: 1px dashed gray;
            background-color: Silver;

unable to access control inside webuser control



I have used calender web user control inside my project where i took textbox,button and calender.....but after dragging onto my aspx page....i am unable to access this textbox,calender and button on aspx page...Pls help me to find out the solution.

Access Control: Understanding Windows File And Registry Permissions


Understanding the ACLs that govern permissions and rights before an operation is allowed to proceed is critical to enhancing security.

John R. Michener

MSDN Magazine November 2008

Security Briefs: Access Control List Editing in .NET


Access control lists (ACLs) can be complex beasts, and user interfaces for editing them are incredibly tricky to implement properly. That's why I was really excited when Windows® 2000 shipped with a programmable ACL editor, shown in Figure 1.

Keith Brown

MSDN Magazine March 2005

Provisioning: Use Web Services Provisioning to Control Access, Usage, and Billing on Your Site


Building Web Services to provide enterprise-level solutions is only the first step. You need to take care of the infrastructure aspects of your solution as well, including provisioning, billing, security, and reporting. In this article, the author uses the .NET Framework and SQL Server 2000 to design a provisioning system that will take care of all these housekeeping tasks. He discusses the general requirements of a Web Service provisioning system, walks through the implementation, and then outlines various scenarios for putting this system to work.

Chandu Thota

MSDN Magazine December 2002

way of calling "javascript function of parent window from child window."

The article way of calling "javascript function of parent window from child window." was added by raja.s on Sunday, June 06, 2010.

Hi,Here i am going to explain how to call the javascript function of a parent window from the child window(pop-Up).Some may know before reading this post.Parent Java Script Function:script language="Javascript" type="text/javascript">

>>>How to use javascript function in aspx file?



I have a file util.js and there some funtions in same file.

For example functions name are keyUp, keyDown, isNumeric, isAlphaNumeric

I have used these functions in aspx code behind in a textbox to restrict user that he may not be able to input any special character.

Before, I used the code directly in aspx file but I have do it for different textboxes therefore to avoid much coding in aspx file I created util.js and put all code in this file but how to use these particular functions in aspx file I couldn't find the way.

Anyone have idea. Do share with me.

I used the reference like this:


' Font-Names="Verdana" Font-Size="8pt" Onkeyup= "keyUp(event.keyCode)" Onkeydown="return isAlphaNumeric(event.keyCode);" onpaste="return false;">

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend