Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

baskar
More...


Forums » .NET » ASP.NET »

Alert box from code behind


Posted Date: 06 Jul 2012      Posted By:: preethi m     Member Level: Silver    Member Rank: 0     Points: 5   Responses: 1



Hi,

I want to display alert box in button click event from code behind.
below code is working fine but the page is blinking when alert pops out.
I need to display popup with out page blink.

string scriptMessage = "<script language= javascript >function window.onload(){alert('invalid phone number');}</script>";
if (!ClientScript.IsClientScriptBlockRegistered("MyMessage"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(),"MyMessage", scriptMessage.ToString());
}

Any suggestions please.

Thanks.




Responses

#679313    Author: SonyMadhu      Member Level: Gold      Member Rank: 45     Date: 08/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi Preethi,


To call alert in code behind

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Hi", "alert('The Field " + sMandatoryFields + " is mandatory');", true);


And To call javascript function from codebehind

Ex:
<script type="javascript">
function sampleValidation()
{
if(document.getElementById('txt1').value=="")
{
alert("textbox shouldn't be empty..");
}
}
</script>

Server side:
ClientScript.RegisterStartupScript(GetType(), "anyString", "sampleValidation();", true);

Sometimes
btn.Attributes.Add("onclick", "return sampleValidation();")




Hope this will help you

Regards,
Madhu
Be so hapy wen others look at you,they become hapy too



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Inside Item Templeate check box getting error
Previous : Label is clearing inside the gridview
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.