View Full Version : Showing alert not working in C#
12-23-2006, 04:28 AM
I created a form and now I have to write validation. I want to show some kind of alert or message box. I wrote the following code. When the user clicks on the submit image, I get the alert but at the same time the web page is blanking out. How to make the page stay without blanking?
void button_click(object sender, EventsArgs e)
if (text1.text == "")
12-26-2006, 08:45 PM
Take a look at this message box example:
If you'd like others, do a quick Google for asp.net message box.
12-27-2006, 02:34 AM
Thanks Brandoe85. That is a great article. I will read it and hope to make it work in my page.
12-27-2006, 05:07 PM
Brandoe85, I read the article and my situation is a bit different. In my case, I have a text box and a go button. The user have to type a word in the text box and when he clicks the go button it searches for articles. So when I tried the code it always displaying the alert, whether you enter a word or not. I thing this is because of IsStartupScriptRegistered. So even if a user enters some text in the text box and submits, it displays the alert and when I click the OK then it searches for the articles/journals. But I dont want that. It shouldnt display any alert once there is something in the text box.
12-27-2006, 09:59 PM
var elm = document.getElementById('text1');
if(elm.value == '')
alert('please enter something');
Add the onsubmit handler in the form tag:
// my example form
<form id="Form1" method="post" runat="server" onsubmit="checkText();">
Then do your server validation as well in your button click. Good luck;
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.