Calling a Javascript function in code behind.

Posted by Laghaterohan under Regular Expressions on 2/23/2011 | Points: 10 | Views : 58513 | Status : [Member] | Replies : 12
Hello,

I want to call a javascript confirm in my else { } block. How should i do it ? I am using follwing code but is not giving me confirm box...also, how can i know if the user has clicked Yes or No? Please help me..

I am using the below code but it is not working....where am i going wrong? Also please let me know how to collect the response given by the user..

 string script = "<script type="text/javascript">alert('Please note your New Password : " + password + "');</script>";

Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(MyPage), "alert", script);
}


Best Regards,
Rohan Laghate



Responses

Posted by: Madhu.b.rokkam on: 2/23/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Confirm dialog will return true if you have clicked yes and false if clicked No button.


Thanks and Regards
Madhu

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

Posted by: Madhu.b.rokkam on: 2/23/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hey to your first question ..

Add a literal control at the end of your aspx page and set your script where ever you need
like

literalcontrol.text = your javascript code and once done you need to make that blank again.


Thanks and Regards
Madhu

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

Posted by: Laghaterohan on: 2/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hey Madhu,

i tried following in my else condition....

   ltrLiability.Text = "<script type=\"text/javascript\">confirm('Please note your New Password : " + lblAssurerName + "');</script>";

do i need to write any thing more????? i am at my wits end...its not working since morning...i dont uderstand where am i going wrong :(

but it still not working ....:(

Thanks!

Best Regards,
Rohan Laghate

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

Posted by: Laghaterohan on: 2/23/2011 [Member] Starter | Points: 25

Up
0
Down
Please any one help me out :(

Best Regards,
Rohan Laghate

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

Posted by: Laghaterohan on: 2/23/2011 [Member] Starter | Points: 25

Up
0
Down
Am i missing out proper quotation marks?? because of which my js is not executing?

here is my else block for your reference :
   string script = "<script type='text/javascript'>alert('Please note your New Password : " + lblAssurerName.Text + "');</script>";

Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(LoanApplication), "alert", script);
}


WHY IS MY JS CODE NOT EXECUTING IN CODE BEHIND...

MADHU I EVEN TRIED EXECUTING WITH LITERATL STILL ITS NOT WORKING...PLZ REFER MY ABOVE POSTS..

PLEASE HELP :)

Best Regards,
Rohan Laghate

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

Posted by: Naimishforu on: 2/23/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Is this got resolved??

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

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

Posted by: Laghaterohan on: 2/23/2011 [Member] Starter | Points: 25

Up
0
Down
No, the issue is not resolved Naimish...does any one have solution?


Thanks!

Best Regards,
Rohan Laghate

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

Posted by: Naimishforu on: 2/23/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Check this link out,

http://www.codedigest.com/Articles/ASPNET/314_Multiple_Ways_to_Call_Javascript_Function_from_CodeBehind_in_ASPNet.aspx

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

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

Posted by: Karthikanbarasan on: 2/23/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi Laghaterohan

What exact error you getting now?

Thanks
Karthik
www.f5Debug.net

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

Posted by: Laghaterohan on: 2/24/2011 [Member] Starter | Points: 25

Up
0
Down
@Karthik
I am not getting error...however , my JS is not getting called either.....its not working still :(

Basically, what i need is:

On my Text Change Event if my control goes in the else condition written then i should get a confirm pop up asking user if he/she wishes to continue ...if the user selects yes then the rest of the activity follows or else the user is return.

I am unable to achieve this ....since yesterday...am not understanding where am i going wrong!


Thanks

Best Regards,
Rohan Laghate

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

Posted by: Madhu.b.rokkam on: 2/27/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Are you getting any javascript error. Check in the Status bar ?????

Thanks and Regards
Madhu

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

Posted by: Naimishforu on: 2/27/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
May be if you are getting any error is status bar, you can expand it and paste it here too.

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

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

Login to post response