473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Execute script from UserControl

QUESTION: How to access an object embedded in a UserControl through
Javascript file?

Another way to ask this question: How to execute script from a UserControl,
accessing other objects in that UserControl? (Script attached to, and
executed by, a UserControl embedded server control can ‘see’ the UserControl
through the root document architecture. How to get the script to execute and
‘see’ other server controls in the UserControl – as compared to addressing
the base UserControl itself?)

Visual Studio 2005 - ASP.NET 2.0 - C#

/* Page object: MyPage.aspx */

<%@ Reference Control="~/controls/MyControl.ascx" %>
<%@ Register TagPrefix="myc" TagName="MyControl"
Src="Controls/MyControl.ascx" %>
<%@ Page language="c#" Inherits="MyPage" CodeFile="MyPage.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<script language="javascript" src="MyScript.js"></script>
</HEAD>
<body>
<form id="MyForm" method="post" runat="server">
<asp:Panel ID="MyPagePanel" runat=server>
<div id="MYCDiv">
<myc:mycontrol id="MyControl" runat="server"></myc:mycontrol>
</div>
</asp:Panel>
<asp:Button id="MyButton" runat="server" Text="Code
Behind"></asp:Button>
<asp:Button id="JsButton" runat="server"
Text="Javascript"></asp:Button>
</form>
</body>
</HTML>
/* Page object code behind: MyPage.aspx.cs */

[…] // Additional code here

private void WireupPage()
{
JsButton.Attributes.Add("onclick", "javascript:HandleJsButton();");
}

protected void MyButton_Click(object sender, System.EventArgs e)
{
MyPagePanel.Height = 67; // ok
MYCDiv.Visible = true; // ok
}

/* UserControl object: MyControl.ascx */

<%@ Control language="c#" Inherits="MyControl" CodeFile="MyControl.ascx.cs" %>
<asp:Panel id="MyControlPanel" runat="server">
<div id="CONDiv">
<asp:Button id="ControlButton" runat="server"
Text="Control"></asp:Button>
</div>
</asp:Panel>

/* UserControl object code behind: MyControl.ascx.cs */
[…] // Additional code here

private void WireupControl()
{
ControlButton.Attributes.Add("onclick",
"javascript:HandleControlButton();");
}

/* Javascript file: MyScript.js */

function HandleJsButton()
{
document.getElementById('MYCDiv').style.display = 'inline';
// ok
document.getElementById('MyPagePanel').style.heigh t = 10; //
ok

// return false; // to suppress post-back
// return true; // to allow post-back
}
function HandleControlButton()
{
document.getElementById('MYCDiv').style.display = 'inline';
// ok
document.getElementById('MyPagePanel').style.heigh t = 10; //
ok

document.getElementById('CONDiv').style.display = 'inline';
// NOT OK
document.getElementById('MyControlPanel').style.he ight = 10; //
NOT OK

// return false; // to suppress post-back
// return true; // to allow post-back
}
QUESTION: How to access an object embedded in a UserControl through
Javascript file?

btw, first posted on 4/4 in scripting discussion area. No responses there,
so I posted here. Hope this doesn't bend the rules too much. Would love to
get a clue here.

Apr 11 '06 #1
0 2073

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Larry Woods | last post by:
I need to execute a Windows script (wscript/cscript) from an ASP page for some administrative functions. Anyone doing this? If so, how? TIA, Larry Woods
3
by: Tomasz Ludwiniak | last post by:
Hi, I've little problem... I try to execute asp file ( which return XML file ) and use the result it in my asp script : set xml = Server.CreateObject("MSXML2.DOMDocument") xml.async=false...
1
by: Matt | last post by:
I used to execute a command line script in IIS 4 using Dynuexec. This is a third part server object I installed on the server (http://www.dynu.com/dynuexec.asp). I installed this object onto my...
3
by: Lyle Fairfield | last post by:
MS-SQL Server utilities Enterprise Manager and Query Analyzer will model almost any MS-SQL object as a simple script file with a default ".sql" extension. But how to "run these files? They are...
1
by: Tiago Barbutti | last post by:
I have a UserControl that execute methods in Load event, but it hapens in designMode and generate an error and the control disappear from the form. I read that i can use the DesignMode to kwnow...
0
by: R. Sterrenburg | last post by:
Hi, I have a Server.Execute("MyStaticHTML.html") in the codebehind of a UserControl. When I put this UserControl on a page MyPage.aspx it correctly puts the content of the MyStaticHTML.html in...
9
by: kw | last post by:
What is the proper way to get the element ID for a client script? For example, suppose in the WebControl: TextBox t=new TextBox; t.ID=this.ClientID+"X"; .... Then elsewhere we want to access...
2
by: techsatish | last post by:
Hi, I want the double click event to call(here not able to get the MouseEventArgs) and execute the mouseup event code or any one tell me how to make my treecontrol double click nodes to behave...
5
by: Josh Nikle | last post by:
I have a webform containing a GridView control "GridView1" and usercontrol which is also a GridView "GridView2." I have a button column in the usercontrol. The code behind that button adds an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.