Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jscript in ASP.net (c#) and ascx files

Status
Not open for further replies.

mooniron

Programmer
Dec 15, 2002
26
TR
Hi all. I have some problems with using jscript asp.net (c#) and ascx files. Firstly, I have created several ascx files and included them in my page. For example I created an ascx file to hold logged in session information. But I couldn't send information from this .ASCX file instance to the container ASPX file or other include .ASCX instances. How can I communicate theese controls.
Second, I want to use java script code but I don't know how to use that on a server side control. For example a Button control.
Thanks.
 
1. In you control, create public properties to hold session values. Then you can get a reference to those properties from within the container page like this:
Code:
MyApp.MyControl control = (MyApp.MyControl)Page.FindControl("MyControl1");
string p = control.stringProperty;
int i = control.numericProperty;
2. You can attach javascript to a server side control in the code behind:
Code:
private void Page_Load(object sender, System.EventArgs e)
{
  if(myButton.Attributes["onclick"] == null)
  {
   myButton.Attributes.Add("onclick", "javascript:myFunction()");
  }
}
myFunction should exist on the page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top