MessageBox for Wrong Selection in DropDownList

Hi guys... i'm just a beginner in using this ASP.NET... i'm doing a simple program here where a user will select a product in the dropdownlist then click next... if the user didn't select any product then click next, a message box will pop up and stated invalid selection... so my problem here is i can't find a way to make this error message box... can you guys help me with this ??? thanks a lot guys... really hope you all can help me... :)

Here is my simple code for the scripts...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
lblError1.Text = "Page Refreshed at : " & DateTime.Now
End If
Session("page1") = dropdownlist1.SelectedItem.Value
End Sub

Private Sub build1_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles build1_btn.Click
If dropdownlist1.SelectedItem.Value = "Please Select Your Processor" Then
Exit Sub
End If
Response.Redirect("build_step2.aspx")
End Sub
End Class

HTML Code...

<body bgColor="#000000" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:button id="build1_btn" style="Z-INDEX: 101; LEFT: 344px; POSITION: absolute; TOP: 248px" runat="server" Height="32px" Width="86px" Text="Next" CssClass="Btn"></asp:button>

<asp:dropdownlist id="dropdownlist1" style="Z-INDEX: 102; LEFT: 280px; POSITION: absolute; TOP: 208px" Runat="server">
<asp:ListItem Value="Please Select Your Processor">Please Select Your Processor</asp:ListItem>
<asp:ListItem Value="AMD SEMPRON 2800+">AMD SEMPRON 64 2800+</asp:ListItem>
<asp:ListItem Value="AMD ATHLON 64 3500+">AMD ATHLON 64 3500+</asp:ListItem>
<asp:ListItem Value="INTEL CELERON 336 D">INTEL CELERON 336 D</asp:ListItem>
<asp:ListItem Value="INTEL PENTIUM 4 630">INTEL PENTIUM 4 630</asp:ListItem>
</asp:dropdownlist>

<asp:label id="lbl1" style="Z-INDEX: 103; LEFT: 168px; POSITION: absolute; TOP: 136px" runat="server" Height="40px" Width="24px" Font-Bold="True" Font-Size="X-Large" Font-Names="Times New Roman" ForeColor="#80FF80">1.</asp:label>
</body>Hi,

you need to make sure the user is clicked something from your drop down list by calling the "selectedindex" method off your control.


Private Sub build1_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles build1_btn.Click

'-1 means not selected anything
If dropdownlist1.SelectedIndex = -1 then
lblError1.Text = "<font color='red'> Please select an item</font>"
return

'ur other code goes down here....
End Sub


p.s: you may wanna rename your control to something else instead of dropdownlist1...thanks a lot mate... i twisted a bit your code and managed to do it now... if you didn't mentioned it i wouldn't know it... cheers...

one more question here... i'm using this code now... what if i wanted my mouse pointed to the selection in the dropdownlist ( let say the first choice = AMD.. ) instead of showing the tooltips ( with words ) i wanted to show an image of that item next to the mouse where pointed... is it possible to do it ??? thanks a lot guys... :)

<script language="JavaScript">
showHideTooltip = function ()
{
var obj = event.srcElement;
with(document.getElementById("tooltip1"))
{
innerHTML = obj.options[obj.selectedIndex].text;
with(style)
{
if(event.type == "mouseleave")
{
display = "none";
}
else
{
display = "inline";
left = event.x;
top = event.y;
}
}
}
}

</script>
</HEAD>
<body bgColor="#000000" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<span id="tooltip1" style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 3px; BORDER-TOP: black 1px solid; DISPLAY: none; PADDING-LEFT: 3px; Z-INDEX: 101; BACKGROUND: yellow; LEFT: 480px; PADDING-BOTTOM: 3px; BORDER-LEFT: black 1px solid; PADDING-TOP: 3px; BORDER-BOTTOM: black 1px solid; POSITION: absolute; TOP: 216px">
</span>
<asp:button id="build1_btn" style="Z-INDEX: 102; LEFT: 336px; POSITION: absolute; TOP: 248px"
text="Next" runat="server" Height="40" Width="88"></asp:button>
<asp:DropDownList id="dropdownlist1" onmouseleave="showHideTooltip()" style="Z-INDEX: 104; LEFT: 280px; POSITION: absolute; TOP: 200px"
onmouseenter="showHideTooltip()" runat="server" Width="200">
<asp:ListItem value="Please Select Your Processor" Selected="true">Please Select Your Processor</asp:ListItem>
<asp:ListItem Value="AMD SEMPRON 2800+">AMD SEMPRON 64 2800+</asp:ListItem>
<asp:ListItem Value="AMD ATHLON 64 3500+">AMD ATHLON 64 3500+</asp:ListItem>
</form>
</body>
</HTML>Hi,
I'm not familiar with javascript nor a javascript fan, but there's a "Attributes" method you can use with any of your asp.net control. You can use it to add your javascript function call.

i.e:

dropdownlist1.Attributes.add("onmouseover","function1()");



<script language="JavaScript">
function1() {
//ur code goes here
}
</script>
 
Back
Top