Click here to Skip to main content
12,078,259 members (47,803 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
On submit button I have user validation to enter user id so that then can submit.
I have used javascript to show alert box.
Code:
ScriptManager.RegisterStartupScript(this, typeof(Page), "script", "alert('Please, enter valid User id.');", true);

It works fine. Then i click on one of the link to go to other page. Come back to main page.
I get alert showing Please, enter valid User id. , without clicking on submit button.

Help me out.

I view sourced it.
I found at bottom of page, as:
<script type="text/javascript">
//<![CDATA[
alert('Please, enter valid User id.');//]]>
</script>

which i didn't created it.
Posted 26-Apr-13 2:04am
Sant Osha1.6K
Comments
kkakadiya 26-Apr-13 7:08am
   
have u given your button as a default button in your form somewhere?
Sant Osha 26-Apr-13 7:35am
   
no
kkakadiya 26-Apr-13 7:38am
   
ok. where did you put your ScriptManager.RegisterStartupScript(this, typeof(Page), "script", "alert('Please, enter valid User id.');", true); ???
Sant Osha 26-Apr-13 7:39am
   
button click event
kkakadiya 26-Apr-13 7:40am
   
can you paste your code here. so i can check and revert back to you...
Sant Osha 26-Apr-13 7:42am
   
protected void ibtnLogin_Click(object sender, ImageClickEventArgs e)
{
if(txtLogin.Text.Trim() =="User ID")
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "script", "alert('Please, enter valid User id.');", true);
txtLogin.Text = "User ID";
check = false;
}
else
{
//login code
}
kkakadiya 26-Apr-13 7:52am
   
remove code

<script type="text/javascript">
//<![CDATA[
alert('Please, enter valid User id.');//]]>
</script>

it initializes every time when your page loads....

let me know if it works for you...
Sant Osha 26-Apr-13 8:05am
   
how to i remove when page load
kkakadiya 26-Apr-13 8:07am
   
delete above code which is in your .aspx page
Sant Osha 26-Apr-13 8:09am
   
dude.. this is not in my aspx page...
its created automatically when button clicked on client side
ryanb31 26-Apr-13 7:28am
   
That's because ScriptManager.RegisterStartupScript is running again. What event do you have that code in?
sri senthil kumar 26-Apr-13 7:28am
   
This will happen since you have used "RegisterStartupScript". Have you used that code in button click?
Sant Osha 26-Apr-13 7:35am
   
yes.
sri senthil kumar 26-Apr-13 8:47am
   
Can't you do the validation in javascript itself instead of going to codebehind? May it will help you to come out of this.
Praveen Kumar Chauhan (PRK) 26-Apr-13 9:13am
   
i think u can use if page.ispostback to come out from it
learner'sbug 26-Apr-13 11:14am
   
how are you going back ...clicking on some link or back button..??
learner'sbug 26-Apr-13 11:21am
   
I think you page is cached on the browser and you need to stop caching .Try adding this header on page load..Response.AddHeader("Pragma", "no-cache"); and see if it works for you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160212.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100