Solved

Showing message to a user with "Ok" button in a webform

Posted on 2008-06-17
8
196 Views
Last Modified: 2013-11-26
Hi,

       I want to show a message to the user.The message  box shud have only "OK" button in it.
Once the user clicks that button, user shud be redirected to "Home.aspx".

Can it be done in c# itself or have to use js???

Urgent,

Thanks.
0
Comment
Question by:srk1982
  • 4
  • 3
8 Comments
 
LVL 6

Accepted Solution

by:
psychic_zero earned 250 total points
ID: 21809349
You can use javascript
<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -
 
function MsgBox() 
{
   alert ("Pleass press OK");
   window.location = "Home.aspx"  // Your redirect page
}
 
// - End of JavaScript - -->
</SCRIPT>
 
...
 
<INPUT NAME="goto" TYPE="Button" VALUE="Go to Page" onClick="MsgBox()">

Open in new window

0
 
LVL 7

Expert Comment

by:Zippit
ID: 21809362

<script>
 
alert("My Alert");
 
window.location = "http://www.mysite.com/Home.aspx";
 
</script>

Open in new window

0
 

Author Comment

by:srk1982
ID: 21809657
Hi psychic_zero,

    I have to call this javascript function in my pageload and not in a click event.
How to do that?
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

Author Comment

by:srk1982
ID: 21809766
Hi psychic_zero,

Page load of my code behind
like we give for a button click like this
btnDelete.Attributes.Add("OnClick","return ValidateDelete()");

in my case i just want to call that MsgBox() in the pageload of my codebehind.
0
 
LVL 6

Expert Comment

by:psychic_zero
ID: 21809829
Sorry I'm not quite understand with pageload of my codebehind. Or maybe you can give me the flow of how do you want it to work like:

From page "Intro.aspx" -> click on a "Home" button -> then a message box will appear said "You will be redirect to Home page" with OK button -> click OK button on the message box -> then the page will open "Home.aspx".
0
 

Author Comment

by:srk1982
ID: 21809960
I want to call the msgbox() when the Intro.aspx page loads.
The reason why I want to call this msgbox() in codebehind of Intro.aspx because i have to check some session values there.
Thanks
0
 
LVL 6

Expert Comment

by:psychic_zero
ID: 21810259
So you want function msgbox() to be executed automatically when page intro.aspx is load? Then how about try this code below. At the body tag, add onload function and see how it goes.
<body onload="MsgBox()">

Open in new window

0
 

Author Comment

by:srk1982
ID: 21810291
Hi psychic_zero,,

   i dont want to do that in <body> tag, since this message has to come after checking some session values in my codebehind[c#].so, i have to do this in my codebehind only.

Anyway, i did that in c#, it is working now.

Thanks.
						string strMessage = "Page not available for selected class.";
						string strScript = "<script language=JavaScript>";
						strScript += "alert(\"" + strMessage + "\");";
						strScript += "window.location = \"admListQuote.aspx\"";
						strScript += "</script>";
				
						if (! (Page.IsStartupScriptRegistered("clientScript")))
						{
							Page.RegisterStartupScript("clientScript", strScript);
						}

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question