473,244 Members | 1,322 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,244 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 2067

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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.