ScriptManager.RegisterClientScriptBlock not working.

Posted by Rickeybglr under ASP.NET on 9/3/2012 | Points: 10 | Views : 44908 | Status : [Member] | Replies : 7
Hi All,

whn i put this script in page load event, it works properly and display popup. but when i put this script in a user define function and call from different page/file it wont work why?? it goes thru the line and do nothn.

public void dispAlert()
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", "alert('fail to log in');window.location.href('./login.aspx');", true);
}




Responses

Posted by: Ranjeet_8 on: 9/3/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this

Page.ClientScript.RegisterStartupScript(typeof(Page), "Expired", "alert('fail to log in');window.location.href='../login.aspx'", true);


Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 9/3/2012 [Member] Starter | Points: 25

Up
0
Down
Hi, i think its working fine dude.

might be small mistake with the file name. Here is an example:

scriptmanager.aspx

nothing is written

.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dispAlert();
}

}



public void dispAlert()
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", "alert('fail to log in');window.location.href('./login.aspx');", true);
}




Default.aspx

nothing is written

.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("~/scriptmanager.aspx");

}


If this is not appropriate answer to your question. Please let me know.

Regards,

Awesome Coding !! :)

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 9/3/2012 [Member] Starter | Points: 25

Up
0
Down
@Ranjeet_B --Page.client is the older one. now a days ScriptManger is used. i have tried tht also.
@Vasanthmvp-- if u call the method from the same page it works fine. but i have to call this method from DAL layer, in tht case it didnt work
:(

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 9/4/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@Rickeybglr
Try this,

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", "alert('fail to log in');window.location.href='../login.aspx'", true);


Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 9/4/2012 [Member] Starter | Points: 25

Up
0
Down
still not working.. when calling the function from DAL.cs / or other page

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 9/4/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@Rickeybglr
can u plz share ur process of ( ASPX.CS and DAL.CS ) code eg..???


Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 9/4/2012 [Member] Starter | Points: 25

Up
0
Down
PFA attached file.
wat i am doing is :
want to display alert message using javascript. i am retrieving message from database using out paramameter which is in DAL file

i have remove the rest of the code for ur convinince ...luk all the three files aspx, validation(BAL), DAL files
 Download source file

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response