473,775 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegisterStartup Script Question.

I'm trying to use this.RegisterSt artupScript to add some javascript to and
aspx page that will run when the page is loaded. Does anyone know if this
function only works in the Page_Load function? Or can I put it anywhere.
Right now it is inside the eventhandler function that is called on the
"CheckChang ed" event of a checkbox, but it never seems to add the javascript
code to the page. Is there another way to do this? Let me explain the
problem:

I have a page with a bunch of checkboxes. Each checkbox forces a postback.
In the eventhandler function for the "CheckChang ed" event of the checkboxes
I need to determine if two values match each other. If they do, then I want
to use some javascript to open a modal dialog to allow for the input of two
new values. Make sense? Any help would be great! Thanks.

- Bill Jones
Nov 18 '05 #1
6 1986
Bill Jones wrote:
I'm trying to use this.RegisterSt artupScript to add some javascript to and
aspx page that will run when the page is loaded. Does anyone know if this
function only works in the Page_Load function? Or can I put it anywhere.
Right now it is inside the eventhandler function that is called on the
"CheckChang ed" event of a checkbox, but it never seems to add the javascript
code to the page. Is there another way to do this? Let me explain the
problem:

I have a page with a bunch of checkboxes. Each checkbox forces a postback.
In the eventhandler function for the "CheckChang ed" event of the checkboxes
I need to determine if two values match each other. If they do, then I want
to use some javascript to open a modal dialog to allow for the input of two
new values. Make sense? Any help would be great! Thanks.

- Bill Jones


Yes, you can use it anywhere in code-behind; it will get added to the
response output. Are you positive the event is being run, have you
stepped thru in debug mode?

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2
Bill,

Is your checkbox control set to runat=server? Is the AutoPostBack=Tr ue?

You can put this anywhere. In your CheckChanged event sub, you can put:

Dim sb As New System.Text.Str ingBuilder
sb.Append("<scr ipt language='javas cript'>")
sb.Append("wind ow.open('mypage .aspx','help',' width=400,heigh t=400,left=100, t
op=100,toolbars =no,status=no,s crollbars=yes,r esizable=yes'); ")
sb.Append("</script>")
RegisterStartup Script("stp", sb.ToString)

or whatever your code is your using to open a modal dialog, the above opens
a window, but its just an example

HTH,

Raymond Lewallen

"Bill Jones" <wj****@actcci. com> wrote in message
news:#K******** ******@TK2MSFTN GP10.phx.gbl...
I'm trying to use this.RegisterSt artupScript to add some javascript to and
aspx page that will run when the page is loaded. Does anyone know if this
function only works in the Page_Load function? Or can I put it anywhere.
Right now it is inside the eventhandler function that is called on the
"CheckChang ed" event of a checkbox, but it never seems to add the javascript code to the page. Is there another way to do this? Let me explain the
problem:

I have a page with a bunch of checkboxes. Each checkbox forces a postback. In the eventhandler function for the "CheckChang ed" event of the checkboxes I need to determine if two values match each other. If they do, then I want to use some javascript to open a modal dialog to allow for the input of two new values. Make sense? Any help would be great! Thanks.

- Bill Jones

Nov 18 '05 #3

One place you shouldn't call them is Render; as a rule I always call them in PreRender.

Scott
"Craig Deelsnyder" <cdeelsny@NO_SP AM_4_MEyahoo.co m> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Bill Jones wrote:
I'm trying to use this.RegisterSt artupScript to add some javascript to and
aspx page that will run when the page is loaded. Does anyone know if this
function only works in the Page_Load function? Or can I put it anywhere.
Right now it is inside the eventhandler function that is called on the
"CheckChang ed" event of a checkbox, but it never seems to add the javascript
code to the page. Is there another way to do this? Let me explain the
problem:

I have a page with a bunch of checkboxes. Each checkbox forces a postback.
In the eventhandler function for the "CheckChang ed" event of the checkboxes
I need to determine if two values match each other. If they do, then I want
to use some javascript to open a modal dialog to allow for the input of two
new values. Make sense? Any help would be great! Thanks.

- Bill Jones


Yes, you can use it anywhere in code-behind; it will get added to the
response output. Are you positive the event is being run, have you
stepped thru in debug mode?

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #4
Scott wrote:
One place you shouldn't call them is Render; as a rule I always call them in PreRender.

Scott
"Craig Deelsnyder" <cdeelsny@NO_SP AM_4_MEyahoo.co m> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Bill Jones wrote:

I'm trying to use this.RegisterSt artupScript to add some javascript to and
aspx page that will run when the page is loaded. Does anyone know if this
function only works in the Page_Load function? Or can I put it anywhere.
Right now it is inside the eventhandler function that is called on the
"CheckChange d" event of a checkbox, but it never seems to add the javascript
code to the page. Is there another way to do this? Let me explain the
problem:

I have a page with a bunch of checkboxes. Each checkbox forces a postback.
In the eventhandler function for the "CheckChang ed" event of the checkboxes
I need to determine if two values match each other. If they do, then I want
to use some javascript to open a modal dialog to allow for the input of two
new values. Make sense? Any help would be great! Thanks.

- Bill Jones


Yes, you can use it anywhere in code-behind; it will get added to the
response output. Are you positive the event is being run, have you
stepped thru in debug mode?

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Ah, yes, there are places you could potentially cause trouble. My
statement should be for normal page event processing, where we usually
aren't dealing with page events mostly outside of Page_Load. Some of
the other events could (may or may not) get you in trouble :-) Still
not the best description by me, but thanx for the clarification.. .

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #5
Yeah, the event is being run, and the RegisterStartup Script line is
executing error free. I tried using this.Page.Regis terStartupScrip t,
this.RegisterSt artupScript, Page.RegisterSt artupScript, and just
RegisterStartup Script. When I do a view source on the rendered page, I do
not see the javascript code anywhere. I added a protected override void
OnPreRender(Eve ntArgs e) function and added break point within. When I
stepped through the code, all of the eventhandling code was executing prior
to the OnPreRender function being called, which makes me think that this
should work. Thanks again for any input.

Here is the code. One thing I did not mention before is that the checkbox
controls are being added to the page programatically in the
buildEmptyCalen dar function. The code below is the Page_Load function, the
buildEmptyCalen dar function, and the eventhandler for when the CheckChanged
event is called, timeSelect, along with the code generated by visual studio.
The line calling RegisterStartup Script is noted in the timeSelect function:

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using com.actcci.sche dule.sched_bl;

namespace com.actcci.sche dule.schedules
{
/// <summary>
/// Summary description for custompattern2.
/// </summary>
public class custompattern2 : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l Label2;
protected System.Web.UI.W ebControls.Labe l Label1;
protected System.Web.UI.W ebControls.Butt on ResetPattern;
protected System.Web.UI.W ebControls.Butt on AddWeek;
protected System.Web.UI.W ebControls.Butt on SavePattern;
protected System.Web.UI.W ebControls.Text Box IptNumWeeks;
protected System.Web.UI.W ebControls.Tabl e PatternTable;
protected System.Web.UI.W ebControls.Butt on RemoveWeek;
protected System.Web.UI.W ebControls.Drop DownList dd_patterns;
protected System.Web.UI.W ebControls.Plac eHolder calHolder;
protected System.Collecti ons.Hashtable sessionsTable;
protected int numweeks;

private void Page_Load(objec t sender, System.EventArg s e){
numweeks = Int32.Parse(Ipt NumWeeks.Text);
if(!IsPostBack) {
buildEmptyCalen dar();
}//end if
else{
if(Session["patterntab le"] == null){
Response.Write( "Session Timed Out");
Response.End();
}//end if
else{
PatternTable = (Table)Session["patterntab le"];
}//end else
}//end else

calHolder.Contr ols.Add(Pattern Table);
}

private void buildEmptyCalen dar(){
PatternTable = new Table();

TableRow tr = this.weekHeader ();

PatternTable.Ro ws.Add(tr);

TableItemStyle tis = new TableItemStyle( );
tis.BackColor = ColorTranslator .FromHtml("#fff fff");
tis.ForeColor = ColorTranslator .FromHtml("#000 000");
tis.Width = Unit.Pixel(100) ;
tis.Height = Unit.Pixel(100) ;
tis.Font.Size = FontUnit.XSmall ;
tis.BorderColor = ColorTranslator .FromHtml("#000 000");
tis.BorderStyle = BorderStyle.Sol id;
tis.BorderWidth = Unit.Pixel(1);

listOfValues tsession = new listOfValues("t ruesession");

TableCell tc = null;
CheckBox chkbx = null;
TextBox fromtime = null;
TextBox totime = null;
string idpre = null;
for(int currweek=0;curr week<numweeks;c urrweek++){
tr = new TableRow();
for(int x=0;x<7;x++){
tc = new TableCell();
tc.ApplyStyle(t is);
for(int y=0;y<tsession. Count();y++){
chkbx = new CheckBox();
chkbx.Text = tsession.listIt em(y).Descripti on
+ "<BR>";
chkbx.AutoPostB ack = true;
chkbx.CheckedCh anged += new
System.EventHan dler(this.timeS elect);
idpre = Convert.ToStrin g((x + (currweek *
7)));
while(idpre.Len gth < 3){
idpre = "0" + idpre;
}//end while
chkbx.ID = idpre+ "chk" +
tsession.listIt em(y).Val;
tc.Controls.Add (chkbx);
}//end for

fromtime = new TextBox();
fromtime.ID = idpre + "fromtime";
totime = new TextBox();
totime.ID = idpre + "totime";

tc.Controls.Add (fromtime);
tc.Controls.Add (totime);

tr.Cells.Add(tc );
}//end for
PatternTable.Ro ws.Add(tr);
}//end for

TableStyle ts = new TableStyle();
ts.CellPadding = 0;
ts.CellSpacing = 0;

PatternTable.Ap plyStyle(ts);

Session["patterntab le"] = PatternTable;
}//end private void buildEmptyCalen dar()

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.AddWeek.Cl ick += new System.EventHan dler(this.AddWe ek_Click);
this.RemoveWeek .Click += new System.EventHan dler(this.Remov eWeek_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
private void timeSelect(obje ct sender, System.EventArg s e){
CheckBox chkbx = (CheckBox)sende r;
string idpre = chkbx.ID.Substr ing(0,3);

if(Session["sessionsTa ble"]==null){
sessionsTable = new Hashtable();
}//end if
else{
sessionsTable = (Hashtable)Sess ion["sessionsTa ble"];
}//end else

CheckBox oldchk = null;

string key = null;
ArrayList al = new ArrayList(sessi onsTable.Keys);
for(int x=sessionsTable .Count-1;x>=0;x--){
key = (string)al[x];
if(key.IndexOf( idpre) >= 0){
oldchk = (CheckBox)Patte rnTable.FindCon trol(key);
oldchk.Checked = false;
sessionsTable.R emove(key);
}//end if
}//end foreach

if(chkbx.Checke d){
actSession acts = new
actSession(chkb x.ID.Substring( chkbx.ID.Length - 3));
sessionsTable.A dd(chkbx.ID,act s);
TextBox tbx = (TextBox)Patter nTable.FindCont rol(idpre +
"fromtime") ;
tbx.Text = acts.fromTime.T oShortTimeStrin g();
tbx = (TextBox)Patter nTable.FindCont rol(idpre +
"totime");
tbx.Text = acts.toTime.ToS hortTimeString( );
string jscrpt = null;
if(acts.fromTim e.CompareTo(act s.toTime) == 0){
jscrpt = "<script language=\"Java Script\">";
jscrpt += "alert(\"yo yo fred\")";
jscrpt += "</script>";
string scriptKey = "windowload :" + this.UniqueID;

//HERE IS THE REGISTERSTARTUP SCRIPT LINE

RegisterStartup Script(scriptKe y,jscrpt);
}//end if
}//end if
else{
TextBox tbx = (TextBox)Patter nTable.FindCont rol(idpre +
"fromtime") ;
tbx.Text = null;
tbx = (TextBox)Patter nTable.FindCont rol(idpre +
"totime");
tbx.Text = null;
}//end else

Session["sessionsTa ble"] = sessionsTable;
Session["patternTab le"] = PatternTable;
}//end
}
}


"Craig Deelsnyder" <cdeelsny@NO_SP AM_4_MEyahoo.co m> wrote in message
news:uQ******** ******@tk2msftn gp13.phx.gbl...
Scott wrote:
One place you shouldn't call them is Render; as a rule I always call them in PreRender.
Scott
"Craig Deelsnyder" <cdeelsny@NO_SP AM_4_MEyahoo.co m> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Bill Jones wrote:
I'm trying to use this.RegisterSt artupScript to add some javascript to andaspx page that will run when the page is loaded. Does anyone know if thisfunction only works in the Page_Load function? Or can I put it anywhere.Right now it is inside the eventhandler function that is called on the
"CheckChange d" event of a checkbox, but it never seems to add the javascriptcode to the page. Is there another way to do this? Let me explain the
problem:

I have a page with a bunch of checkboxes. Each checkbox forces a postback.In the eventhandler function for the "CheckChang ed" event of the checkboxesI need to determine if two values match each other. If they do, then I wantto use some javascript to open a modal dialog to allow for the input of twonew values. Make sense? Any help would be great! Thanks.

- Bill Jones

Yes, you can use it anywhere in code-behind; it will get added to the
response output. Are you positive the event is being run, have you
stepped thru in debug mode?

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Ah, yes, there are places you could potentially cause trouble. My
statement should be for normal page event processing, where we usually
aren't dealing with page events mostly outside of Page_Load. Some of
the other events could (may or may not) get you in trouble :-) Still
not the best description by me, but thanx for the clarification.. .

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #6

You can't do things like this; that is, you can't create a control tree and stick it into the
session and then add it back in on postback -- you'll have to recreate the table each time. I'm not
sure how you were able to see the postback event on the checkbox fire.... hummmm.....

Here's a sample that does something similar to what you have (you should look into composite
controls if you choose do things this way).

Scott

<%@ Page language="c#" AutoEventWireup ="false" trace="true" %>
<%@ Import Namespace="Syst em.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>LblCssCl ass</title>
<script language="C#" runat="server">
private void Page_Load(objec t sender, EventArgs e)
{
this.EnsureChil dControls();
}

protected override void CreateChildCont rols()
{
Table table = new Table();
TableRow tr = new TableRow();
TableCell td = new TableCell();
CheckBox cb = new CheckBox();
cb.AutoPostBack = true;
cb.CheckedChang ed += new EventHandler(Ch eckBox_Changed) ;

td.Controls.Add (cb);
tr.Cells.Add(td );
table.Rows.Add( tr);
this.Form1.Cont rols.Add(table) ;
}

protected override void OnInit(EventArg s e)
{
this.Load += new EventHandler(Pa ge_Load);
base.OnInit(e);
}

protected void CheckBox_Change d(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sende r;
this.Lbl.Text = "Changed " + cb.Checked;
AddJScript();
}

private void AddJScript()
{
string jscrpt = "<script language=\"Java Script\">";
jscrpt += "alert(\"yo yo fred\");";
jscrpt += "</";
jscrpt += "script>";
string scriptKey = "windowload :" + this.UniqueID;
RegisterStartup Script(scriptKe y,jscrpt);
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<p>
<asp:label id="Lbl" runat="server"> Hello</asp:label></p>
</form>
</body>
</html>

"Bill Jones" <wj****@actcci. com> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Yeah, the event is being run, and the RegisterStartup Script line is
executing error free. I tried using this.Page.Regis terStartupScrip t,
this.RegisterSt artupScript, Page.RegisterSt artupScript, and just
RegisterStartup Script. When I do a view source on the rendered page, I do
not see the javascript code anywhere. I added a protected override void
OnPreRender(Eve ntArgs e) function and added break point within. When I
stepped through the code, all of the eventhandling code was executing prior
to the OnPreRender function being called, which makes me think that this
should work. Thanks again for any input.

Here is the code. One thing I did not mention before is that the checkbox
controls are being added to the page programatically in the
buildEmptyCalen dar function. The code below is the Page_Load function, the
buildEmptyCalen dar function, and the eventhandler for when the CheckChanged
event is called, timeSelect, along with the code generated by visual studio.
The line calling RegisterStartup Script is noted in the timeSelect function:

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using com.actcci.sche dule.sched_bl;

namespace com.actcci.sche dule.schedules
{
/// <summary>
/// Summary description for custompattern2.
/// </summary>
public class custompattern2 : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l Label2;
protected System.Web.UI.W ebControls.Labe l Label1;
protected System.Web.UI.W ebControls.Butt on ResetPattern;
protected System.Web.UI.W ebControls.Butt on AddWeek;
protected System.Web.UI.W ebControls.Butt on SavePattern;
protected System.Web.UI.W ebControls.Text Box IptNumWeeks;
protected System.Web.UI.W ebControls.Tabl e PatternTable;
protected System.Web.UI.W ebControls.Butt on RemoveWeek;
protected System.Web.UI.W ebControls.Drop DownList dd_patterns;
protected System.Web.UI.W ebControls.Plac eHolder calHolder;
protected System.Collecti ons.Hashtable sessionsTable;
protected int numweeks;

private void Page_Load(objec t sender, System.EventArg s e){
numweeks = Int32.Parse(Ipt NumWeeks.Text);
if(!IsPostBack) {
buildEmptyCalen dar();
}//end if
else{
if(Session["patterntab le"] == null){
Response.Write( "Session Timed Out");
Response.End();
}//end if
else{
PatternTable = (Table)Session["patterntab le"];
}//end else
}//end else

calHolder.Contr ols.Add(Pattern Table);
}

private void buildEmptyCalen dar(){
PatternTable = new Table();

TableRow tr = this.weekHeader ();

PatternTable.Ro ws.Add(tr);

TableItemStyle tis = new TableItemStyle( );
tis.BackColor = ColorTranslator .FromHtml("#fff fff");
tis.ForeColor = ColorTranslator .FromHtml("#000 000");
tis.Width = Unit.Pixel(100) ;
tis.Height = Unit.Pixel(100) ;
tis.Font.Size = FontUnit.XSmall ;
tis.BorderColor = ColorTranslator .FromHtml("#000 000");
tis.BorderStyle = BorderStyle.Sol id;
tis.BorderWidth = Unit.Pixel(1);

listOfValues tsession = new listOfValues("t ruesession");

TableCell tc = null;
CheckBox chkbx = null;
TextBox fromtime = null;
TextBox totime = null;
string idpre = null;
for(int currweek=0;curr week<numweeks;c urrweek++){
tr = new TableRow();
for(int x=0;x<7;x++){
tc = new TableCell();
tc.ApplyStyle(t is);
for(int y=0;y<tsession. Count();y++){
chkbx = new CheckBox();
chkbx.Text = tsession.listIt em(y).Descripti on
+ "<BR>";
chkbx.AutoPostB ack = true;
chkbx.CheckedCh anged += new
System.EventHan dler(this.timeS elect);
idpre = Convert.ToStrin g((x + (currweek *
7)));
while(idpre.Len gth < 3){
idpre = "0" + idpre;
}//end while
chkbx.ID = idpre+ "chk" +
tsession.listIt em(y).Val;
tc.Controls.Add (chkbx);
}//end for

fromtime = new TextBox();
fromtime.ID = idpre + "fromtime";
totime = new TextBox();
totime.ID = idpre + "totime";

tc.Controls.Add (fromtime);
tc.Controls.Add (totime);

tr.Cells.Add(tc );
}//end for
PatternTable.Ro ws.Add(tr);
}//end for

TableStyle ts = new TableStyle();
ts.CellPadding = 0;
ts.CellSpacing = 0;

PatternTable.Ap plyStyle(ts);

Session["patterntab le"] = PatternTable;
}//end private void buildEmptyCalen dar()

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.AddWeek.Cl ick += new System.EventHan dler(this.AddWe ek_Click);
this.RemoveWeek .Click += new System.EventHan dler(this.Remov eWeek_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
private void timeSelect(obje ct sender, System.EventArg s e){
CheckBox chkbx = (CheckBox)sende r;
string idpre = chkbx.ID.Substr ing(0,3);

if(Session["sessionsTa ble"]==null){
sessionsTable = new Hashtable();
}//end if
else{
sessionsTable = (Hashtable)Sess ion["sessionsTa ble"];
}//end else

CheckBox oldchk = null;

string key = null;
ArrayList al = new ArrayList(sessi onsTable.Keys);
for(int x=sessionsTable .Count-1;x>=0;x--){
key = (string)al[x];
if(key.IndexOf( idpre) >= 0){
oldchk = (CheckBox)Patte rnTable.FindCon trol(key);
oldchk.Checked = false;
sessionsTable.R emove(key);
}//end if
}//end foreach

if(chkbx.Checke d){
actSession acts = new
actSession(chkb x.ID.Substring( chkbx.ID.Length - 3));
sessionsTable.A dd(chkbx.ID,act s);
TextBox tbx = (TextBox)Patter nTable.FindCont rol(idpre +
"fromtime") ;
tbx.Text = acts.fromTime.T oShortTimeStrin g();
tbx = (TextBox)Patter nTable.FindCont rol(idpre +
"totime");
tbx.Text = acts.toTime.ToS hortTimeString( );
string jscrpt = null;
if(acts.fromTim e.CompareTo(act s.toTime) == 0){
jscrpt = "<script language=\"Java Script\">";
jscrpt += "alert(\"yo yo fred\")";
jscrpt += "</script>";
string scriptKey = "windowload :" + this.UniqueID;

//HERE IS THE REGISTERSTARTUP SCRIPT LINE

RegisterStartup Script(scriptKe y,jscrpt);
}//end if
}//end if
else{
TextBox tbx = (TextBox)Patter nTable.FindCont rol(idpre +
"fromtime") ;
tbx.Text = null;
tbx = (TextBox)Patter nTable.FindCont rol(idpre +
"totime");
tbx.Text = null;
}//end else

Session["sessionsTa ble"] = sessionsTable;
Session["patternTab le"] = PatternTable;
}//end
}
}


"Craig Deelsnyder" <cdeelsny@NO_SP AM_4_MEyahoo.co m> wrote in message
news:uQ******** ******@tk2msftn gp13.phx.gbl...
Scott wrote:
One place you shouldn't call them is Render; as a rule I always call them in PreRender.
Scott
"Craig Deelsnyder" <cdeelsny@NO_SP AM_4_MEyahoo.co m> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .

>Bill Jones wrote:
>
>
>>I'm trying to use this.RegisterSt artupScript to add some javascript to and>>aspx page that will run when the page is loaded. Does anyone know if this>>function only works in the Page_Load function? Or can I put it anywhere.>>Right now it is inside the eventhandler function that is called on the
>>"CheckChange d" event of a checkbox, but it never seems to add the javascript>>code to the page. Is there another way to do this? Let me explain the
>>problem:
>>
>>I have a page with a bunch of checkboxes. Each checkbox forces a postback.>>In the eventhandler function for the "CheckChang ed" event of the checkboxes>>I need to determine if two values match each other. If they do, then I want>>to use some javascript to open a modal dialog to allow for the input of two>>new values. Make sense? Any help would be great! Thanks.
>>
>>- Bill Jones
>>
>>
>
>Yes, you can use it anywhere in code-behind; it will get added to the
>response output. Are you positive the event is being run, have you
>stepped thru in debug mode?
>
>--
>Craig Deelsnyder
>Microsoft MVP - ASP/ASP.NET

Ah, yes, there are places you could potentially cause trouble. My
statement should be for normal page event processing, where we usually
aren't dealing with page events mostly outside of Page_Load. Some of
the other events could (may or may not) get you in trouble :-) Still
not the best description by me, but thanx for the clarification.. .

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Nov 18 '05 #7

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

Similar topics

6
1012
by: Bill Jones | last post by:
I'm trying to use this.RegisterStartupScript to add some javascript to and aspx page that will run when the page is loaded. Does anyone know if this function only works in the Page_Load function? Or can I put it anywhere. Right now it is inside the eventhandler function that is called on the "CheckChanged" event of a checkbox, but it never seems to add the javascript code to the page. Is there another way to do this? Let me explain the...
11
3667
by: Stan Sainte-Rose | last post by:
Hi, I m working on a user control. I need to use a Js file, I would like to know how to load the js file using RegisterStartupScript command from the user control. Also, if I load the same user controls several times in the same webpage, do I have to check if the js file is still loaded ? Stan
2
2591
by: Guadala Harry | last post by:
I have a frameset aspx page that enables users to upload photos. One frame/page shows a thumbnail list of prevously-uploaded images, and the other frame/page includes the controls that enable selecting and uploading additional photos. After uploading a file, the list of thumbnail images needs to get refreshed to show the newly uploaded picture. This is accomplished by using the following code: string scriptString = "<script...
0
1999
by: rom | last post by:
my main aspx page has 3 user controls. they are all located in the same place of the page and each time i set the visibility of 2 of them to false and 1 to true. now, i want to use the RegisterStartupScript on one of these controls but then i write page.RegisterStartupScript i registers it on the aspx page and i get js errors on the other controls. when i try me.RegisterStartupScript (on the ascx) i get "RegisterStartupScript is not e...
5
7613
by: Ahmed | last post by:
Hi all, Is there any way to replace a script I registered in Page Load with the method Page.RegisterStartupScript
7
4446
by: sck10 | last post by:
Hello, I have the following sub in a class in my "App_Code" directory. The script is for setting focus on a particular control, but I get the error, "Name ClientScript Not declared". Also, I am using MasterPages. How do I use "ClientScript.RegisterStartupScript" in a class? Public Shared Sub SetFocusControl(ByVal FocusControl As Control) Dim Script As New System.Text.StringBuilder Dim ClientID As String = FocusControl.ClientID
3
10426
by: MJP | last post by:
I have a button which kicks off the generation of a report after which the file will be downloaded. The report generation can take a long time, so client side onclick event of the button also makes a <span> tag visible which contains a nice message to the user thanking them for their patience. Of course after the report has been generated and downloaded this message should be removed. However, the RegisterStartupScript isn't working...
3
2040
by: Rob | last post by:
Hi, We've developed an ajax enabled web app which we're currently deploying to our production server. We use System.Web.UI.Page.RegisterStartupScript throughout the app, and all has worked well until we deployed. After deploying, we get an error stating that the method is not found. We're using .Net V2. After a bit of investigation, I get the impression that System.Web.UI.Page.RegisterStartupScript has been replaced by...
4
3901
by: =?Utf-8?B?RHVuZTg4?= | last post by:
I've got some code that uses Page.ClientScript.RegisterStartupScript to call a javascript function from the Page_Load method in the code behind. The code works fine in IE but the javascript function is not called at all in Firefox. I stripped my code back to the basics and all I have now is a webform with no controls on it and the following in the code behind: protected void Page_Load(object sender, EventArgs e) {...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10107
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10048
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.