Problem dealing with the confirm message box in C#.net

Hi..i am actually trying to do something like this.When a user select a particular option from a dropdown list and click a 'Go' button, a confirm message box will be displayed if the user has selected that particular option.Other options selected will not display that confirm box when the 'Go' button is clicked.Once the user press the ok button on the confirm box,it will proceed to perform other tasks.How do i do that?..I try using the following code but it doesnt really work..the confirm box will always popup everytime the 'Go' button is clicked except for the first time u clicked on it.


<script language=javascript>
function Go()
{
if (<%=drop1.SelectedIndex%> == 1)
confirm("Please select a 'Sort By' field!");

}
</script>
-1
wingshya
4/6/2004 7:23:04 AM
asp.net.getting-started 91979 articles. 2 followers. Follow

2 Replies
889 Views

Similar Articles

[PageSpeed] 43


The reason that it works the way you have described is because the first time the page is accessed the if statement will actually read:
    if (0 == 1)
Once the DropDownList has been changed (say to the second item, which results in SelectedIndex equalling 1) the if statement will read:
    if (1 == 1)
If the DropDownList had been changed to the third item the if statement would read:
    if (2 == 1)
The reason for this is that you are trying to mix your client-side and server-side scripting, which won't work.
What you need to do is pass this as the parameter to the Go function and then use the selectedIndex property in the if statement. For example:
    <select onChange="Go(this)">

function Go (ddl) {
if ( ddl.selectedIndex == 1 ) { ... }
}

Steven Bey

Recursion: see Recursion
1
stevenbey
4/6/2004 8:51:55 AM
Hi..tks a lot. i understand what u mean. but what i want is for the user to select the item first followed by clicking a  'Go' button before popping up the confirm message box and not popping up the box on instant change of the selected item.I would appreciate yr guidance again..tks.
1
wingshya
4/6/2004 9:23:22 AM
Reply:

Web resources about - Problem dealing with the confirm message box in C#.net - asp.net.getting-started

Problem novel - Wikipedia, the free encyclopedia
Working class, or proletarian novels are often also social problem novels . This was in many ways a reaction to rapid industrialization , and ...

The problem with celebrity charities
THE world erupted in praise this week for one of the most generous acts in history.

Recharge Wrap-up: NEDC's NOx problems, autonomous Chevy Volts
Filed under: Green , Chevrolet , GM , Renault , Emissions , Transportation Alternatives , Autonomous , Diesel , Electric Many diesels fail Euro ...

Late Night Open Thread: Problem Solved
... female” from the pin-ups and tattoos favored by the human scum villains at the Mos Eisley cantina… The post Late Night Open Thread: Problem ...

"Old-timers, guys that are 60-plus, have no problem with a gang shower and whatever."
"The Gen X-ers are a little bit more sensitive to what they’re spending and what they’re expecting. And the millennials, these are the special ...

E. coli isn’t Chipotle’s only problem
Chipotle's meteoric sales growth moderated even before its E. coli problems surfaced.

How to fix Windows 10 printing problems
... 3.1 and Windows for Workgroups, printer drivers could be particularly vexing. Since then and until the release of Windows 10, printer problems ...

Michigan GOPer Blames School Problems On Black Children
Michigan state Senator Marty Knollenberg decided he'd be a wise guy and blame failing school districts on African-American kids during a debate. ...

Tallahassee Police Finally Admit Problems With Investigation Of Jameis Winston Rape Case
One of the most sinister things that came to light in the Jameis Winston case was how Florida State and local police protected athletes accused ...

'If We Are To Profit From Gains A Company Makes We Are Also Responsible For Problems It May Cause'
... on maximizing returns over a three-month to three-year time horizon, "currently make investing incompatible with solutions to the real problems ...

Resources last updated: 12/8/2015 9:57:05 AM