Click here to Skip to main content
Rate this: bad
good
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 at 26-Apr-13 7:08am
   
have u given your button as a default button in your form somewhere?
Sant Osha at 26-Apr-13 7:35am
   
no
kkakadiya at 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 at 26-Apr-13 7:39am
   
button click event
kkakadiya at 26-Apr-13 7:40am
   
can you paste your code here. so i can check and revert back to you...
Sant Osha at 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 at 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 at 26-Apr-13 8:05am
   
how to i remove when page load
kkakadiya at 26-Apr-13 8:07am
   
delete above code which is in your .aspx page
Sant Osha at 26-Apr-13 8:09am
   
dude.. this is not in my aspx page...
its created automatically when button clicked on client side
ryanb31 at 26-Apr-13 7:28am
   
That's because ScriptManager.RegisterStartupScript is running again. What event do you have that code in?
sri senthil kumar at 26-Apr-13 7:28am
   
This will happen since you have used "RegisterStartupScript". Have you used that code in button click?
Sant Osha at 26-Apr-13 7:35am
   
yes.
sri senthil kumar at 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) at 26-Apr-13 9:13am
   
i think u can use if page.ispostback to come out from it
learner'sbug at 26-Apr-13 11:14am
   
how are you going back ...clicking on some link or back button..??
learner'sbug at 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
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2014
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