Monday, March 26, 2012

Call RegisterStartupScript problem

Dear friends,

I'm having problems to execute a RegisterStartupScript when I click on a button.
For example:

protected void btnSave_Click(object sender, ImageClickEventArgs e)
{
Page.ClientScript.RegisterStartupScript(typeof(Page), "OnLoad", "<script language='javascript'>alert('OK');</script>" );
}

If I disable the Atlas tags, the RegisterStartupScript works OK, but if I enable the Atlas tags, It doens't work.

How I correct this?

Try setting addScript Tags = True instead

Page.ClientScript.RegisterStartupScript(typeof(Page), "OnLoad", "alert('OK');", True);

RG


I put the True in the last parameter but not works.
Remember thar I'm using Atlas ok.

Do you havy any other sugestion?


just putting the following line in a button even which is inside the update panel works fine for me

Page.ClientScript.RegisterStartupScript(typeof(Page),"OnLoad","alert('OK');",true);

there must be some other issues in the page, you have to show the code.

Thanx


Not work again.

All my controls are inside the same updatepanel, for example:
...
<body>
<form .....>
<atlas:updatepanel .....>
//Here all tags and all controls
</atlas>
</form>
</body>

Is It a problem?


well you have to paste the whole non working code, without the code its hard to tell...


use following code

protected void btnSave_Click(object sender, ImageClickEventArgs e)
{
Page.ClientScript.RegisterStartupScript(typeof(Page), "OnLoad", "alert('OK');",true );
}

I think u'r code remain having "<script language='javascript'>alert('OK');</script>" . This is the problem. U shouldn't use "<script" tag if last parametere is 'true'


I have found that I must have the semi-colon after the script. EG:


page.ClientScript.RegisterClientScriptBlock(typeof(Page), "ShowMsg", "alert('hi')", true);


doesn't work BUT


page.ClientScript.RegisterClientScriptBlock(typeof(Page), "ShowMsg", "alert('hi');", true);

does!


is there a solution? I have the same porblem like rasl


http://ajax.asp.net/docs/mref/T_System_Web_UI_ScriptManager.aspx

You can use the scriptmanager.

Dim msgAsString ="Group '" & u.GroupCode &"' has been deleted."
ScriptManager.RegisterStartupScript(Me.Page,GetType(String),"alertdelete","reportMessage('" & Utils.ForJavascript(msg) &"');",True)

No comments:

Post a Comment