javascript in user control.
javascript in user control.
am 22.04.2008 08:01:34 von archana
Hi all,
i am having one user control. what i want is to add javascript which
will gets called on button click of user control.
but user control is not working if i add javascript in user control..
but if i add javascript in page in which i am adding user control then
that javascript is executed properly.
i tested by displaying alert message in javascript. can anyone tell
me how will i add javascript in user control.
and one more thing controls present in user control, can't be access
directly in javascript. i checked viewsource of page what i found is
for controls of user control 'ctl' get prefixed. can nyone tell me
reason behind this?
any how will i get this id of controls of user control?
please help me asap.
thanks in advance
Re: javascript in user control.
am 22.04.2008 09:10:52 von arnabit
Javascript does work in webusercontrol .Can you post your code here?
archana wrote:
> Hi all,
>
> i am having one user control. what i want is to add javascript which
> will gets called on button click of user control.
>
> but user control is not working if i add javascript in user control..
> but if i add javascript in page in which i am adding user control then
> that javascript is executed properly.
>
> i tested by displaying alert message in javascript. can anyone tell
> me how will i add javascript in user control.
>
> and one more thing controls present in user control, can't be access
> directly in javascript. i checked viewsource of page what i found is
> for controls of user control 'ctl' get prefixed. can nyone tell me
> reason behind this?
>
> any how will i get this id of controls of user control?
>
> please help me asap.
>
> thanks in advance
Re: javascript in user control.
am 22.04.2008 09:20:38 von Stan
On 22 Apr, 07:01, archana wrote:
> Hi all,
>
> i am having one user control. =A0what i want is to add javascript which
> will gets called on button click of user control.
>
> but user control is not working if i add javascript in user control..
> but if i add javascript in page in which i am adding user control then
> that javascript is executed properly.
>
> i tested by displaying alert message in javascript. =A0can anyone tell
> me how will i add javascript in user control.
>
> and one more thing controls present in user control, can't be access
> directly in javascript. =A0i checked viewsource of page what i found is
> for controls of user control 'ctl' get prefixed. =A0can nyone tell me
> reason behind this?
>
> any how will i get this id of controls of user control?
>
> please help me asap.
>
> thanks in advance
Try inserting the script using the Page.ClientScript property to
create a ClientScriptManager class to insert the script.
The ClientID property of web server controls is constructed to
guarantee a unique id within the context of the rendered page. The
control's ID property is not used as it is because scoping rules allow
identifiers to be re-used within code and within templates inside
databound controls.
Re: javascript in user control.
am 22.04.2008 10:15:28 von archana
On Apr 22, 12:20=A0pm, Stan wrote:
> On 22 Apr, 07:01, archana wrote:
>
>
>
>
>
> > Hi all,
>
> > i am having one user control. =A0what i want is to add javascript which
> > will gets called on button click of user control.
>
> > but user control is not working if i add javascript in user control..
> > but if i add javascript in page in which i am adding user control then
> > that javascript is executed properly.
>
> > i tested by displaying alert message in javascript. =A0can anyone tell
> > me how will i add javascript in user control.
>
> > and one more thing controls present in user control, can't be access
> > directly in javascript. =A0i checked viewsource of page what i found is
> > for controls of user control 'ctl' get prefixed. =A0can nyone tell me
> > reason behind this?
>
> > any how will i get this id of controls of user control?
>
> > please help me asap.
>
> > thanks in advance
>
> Try inserting the script using the Page.ClientScript property to
> create a ClientScriptManager class to insert the script.
>
> The ClientID property of web server controls is constructed to
> guarantee a unique id within the context of the rendered page. The
> control's ID property is not used as it is because scoping rules allow
> identifiers to be re-used within code and within templates inside
> databound controls.- Hide quoted text -
>
> - Show quoted text -
Thanks a lot for reply.
how will i access controls of user cotrol in parent page?
please help me asap.
Re: javascript in user control.
am 23.04.2008 07:08:36 von wisccal
Hi Archana,
I'm not sure if you would like to access the controls in your user
control in codebehind or in Javascript. The below sample does both. In
both cases, the trick is to use FindControl on your user control.
Please post back if this doesn't answer your question.
Default.aspx:
<%@ Page Language=3D"C#" AutoEventWireup=3D"true"
CodeBehind=3D"Default.aspx.cs" Inherits=3D"JSInUserControlTest._Default"
%>
<%@ Register Src=3D"~/WebUserControl1.ascx" TagName=3D"UserCtrl"
TagPrefix=3D"my" %>
Untitled Page
Default.aspx.cs:
using System;
using System.Web.UI.WebControls;
namespace JSInUserControlTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void theAspButton_Click(object sender, EventArgs e)
{
Label lbl =3D (Label)myUserCtrl.FindControl("theLabel");
lbl.Text =3D "Changed in codebehind";
}
}
}
WebUserControl1.ascs:
<%@ Control Language=3D"C#" AutoEventWireup=3D"true"
CodeBehind=3D"WebUserControl1.ascx.cs"
Inherits=3D"JSInUserControlTest.WebUserControl1" %>
==============
Regards,
Steve
www.stkomp.com
archana wrote:
> On Apr 22, 12:20ï¿=BDpm, Stan wrote:
> > On 22 Apr, 07:01, archana wrote:
> >
> >
> >
> >
> >
> > > Hi all,
> >
> > > i am having one user control. ï¿=BDwhat i want is to add javascrip=
t which
> > > will gets called on button click of user control.
> >
> > > but user control is not working if i add javascript in user control..
> > > but if i add javascript in page in which i am adding user control then=
> > > that javascript is executed properly.
> >
> > > i tested by displaying alert message in javascript. ï¿=BDcan anyon=
e tell
> > > me how will i add javascript in user control.
> >
> > > and one more thing controls present in user control, can't be access
> > > directly in javascript. ï¿=BDi checked viewsource of page what i f=
ound is
> > > for controls of user control 'ctl' get prefixed. ï¿=BDcan nyone te=
ll me
> > > reason behind this?
> >
> > > any how will i get this id of controls of user control?
> >
> > > please help me asap.
> >
> > > thanks in advance
> >
> > Try inserting the script using the Page.ClientScript property to
> > create a ClientScriptManager class to insert the script.
> >
> > The ClientID property of web server controls is constructed to
> > guarantee a unique id within the context of the rendered page. The
> > control's ID property is not used as it is because scoping rules allow
> > identifiers to be re-used within code and within templates inside
> > databound controls.- Hide quoted text -
> >
> > - Show quoted text -
>
> Thanks a lot for reply.
>
> how will i access controls of user cotrol in parent page?
>
> please help me asap.