asp.net - How to display a message below the dropdownlist not an alert box when specific dropdownlist item is chosen? -


to provide consistency, cannot use alert box display message in code when chooses specific item in dropdownlist. needs display red message below dropdown field if has chosen specific item.

so in case if chooses alabama state dropdownlist example, red message needs display below dropdownlist box after choice made. old version of form works accurately, new version of form many changes in not displaying message.

in code behind file (the aspx.vb file) have these code snippets:

protected sub statedropdownlist_selectedindexchanged(byval sender object, byval e system.eventargs) handles statedropdownlist.selectedindexchanged     if statedropdownlist.text = "ak"         alabamapanel.visible = true         session("alabama") = "yes"     else         alabamapanel.visible = false         session("alabama") = "no"     end if             statedropdownlist.focus() end sub 

i'm using previous code edits , part of problem don't understand session("alabama") part - don't find anywhere else in code session("alabama") listed or rather understand session() , how know alabama session is... if know session() might helpful - see (https://msdn.microsoft.com/en-us/library/ms178581%28v=vs.140%29.aspx) that's not helping me understand. place in code alabama exists in items of dropdownlist. , maybe part of problem since in old code alabama noted in long list (in aspx file, not aspx.vb file) such:

<asp:dropdownlist class="dropdowns" id="statedropdownlist" runat="server" autopostback="true">     <asp:listitem></asp:listitem>     <asp:listitem value="al">alabama</asp:listitem>     <asp:listitem value="ak">alaska</asp:listitem>     <asp:listitem value="az">arizona</asp:listitem>     <asp:listitem value="ar">arkansas</asp:listitem>     <asp:listitem value="ca">california</asp:listitem>     <asp:listitem value="co">colorado</asp:listitem>     <asp:listitem value="ct">connecticut</asp:listitem>     <asp:listitem value="de">delaware</asp:listitem>     <asp:listitem value="dc">district of columbia</asp:listitem>     <asp:listitem value="fl">florida</asp:listitem>     <asp:listitem value="ga">georgia</asp:listitem>     <asp:listitem value="hi">hawai'i</asp:listitem>     <asp:listitem value="id">idaho</asp:listitem>     <asp:listitem value="il">illinois</asp:listitem>     <asp:listitem value="in">indiana</asp:listitem>     <asp:listitem value="ia">iowa</asp:listitem>     <asp:listitem value="ks">kansas</asp:listitem>     <asp:listitem value="ky">kentucky</asp:listitem>     <asp:listitem value="la">louisiana</asp:listitem>     <asp:listitem value="me">maine</asp:listitem>     <asp:listitem value="md">maryland</asp:listitem>     <asp:listitem value="ma">massachusetts</asp:listitem>     <asp:listitem value="mi">michigan</asp:listitem>     <asp:listitem value="mn">minnesota</asp:listitem>     <asp:listitem value="ms">mississippi</asp:listitem>     <asp:listitem value="mo">missouri</asp:listitem>     <asp:listitem value="mt">montana</asp:listitem>     <asp:listitem value="ne">nebraska</asp:listitem>     <asp:listitem value="nv">nevada</asp:listitem>     <asp:listitem value="nh">new hampshire</asp:listitem>     <asp:listitem value="nj">new jersey</asp:listitem>     <asp:listitem value="nm">new mexico</asp:listitem>     <asp:listitem value="ny">new york</asp:listitem>     <asp:listitem value="nc">north carolina</asp:listitem>     <asp:listitem value="nd">north dakota</asp:listitem>     <asp:listitem value="oh">ohio</asp:listitem>     <asp:listitem value="ok">oklahoma</asp:listitem>     <asp:listitem value="or">oregon</asp:listitem>     <asp:listitem value="pa">pennsylvania</asp:listitem>     <asp:listitem value="ri">rhode island</asp:listitem>     <asp:listitem value="sc">south carolina</asp:listitem>     <asp:listitem value="sd">south dakota</asp:listitem>     <asp:listitem value="tn">tennessee</asp:listitem>     <asp:listitem value="tx">texas</asp:listitem>     <asp:listitem value="ut">utah</asp:listitem>     <asp:listitem value="vt">vermont</asp:listitem>     <asp:listitem value="va">virgina</asp:listitem>     <asp:listitem value="wa">washington</asp:listitem>     <asp:listitem value="wv">west virgina</asp:listitem>     <asp:listitem value="wi">wisconsin</asp:listitem>     <asp:listitem value="wy">wyoming</asp:listitem> </asp:dropdownlist> 

but calling vb file grab state dropdown list , full set shown above no longer in code.

since there besides list no longer exists or list exist in separate vb file calling populating dropdownlist, perhaps blocking session() working?

in new code (in aspx file, not aspx.vb file), of above replaced with:

<label for="statedropdownlist">state <span class="required">*</span></label> <asp:dropdownlist class="form-control" id="statedropdownlist" runat="server"> </asp:dropdownlist> 

i'm trying use (in aspx file) :

<asp:panel id="alabamapanel" runat="server" visible="false">     <tr>         <td align="center" colspan="3">              <br />             <asp:label id="alabamalabel" runat="server" visibile="false" text="alabama text want appear right below statedropdownlist field if choose alabama."                 font-bold="true" forecolor="#e00022" />          </td>     </tr> </asp:panel> 

to text show on page below dropdown field if user chooses alabama , it's not displaying. have tried putting long list of states in instead of calling out separate dropdowns vb file.

i'm trying use update panel, wrapping dropdown list

 <asp:updatepanel id="updatepanel1"       updatemode="conditional"      runat="server">      <contenttemplate>         </contenttemplate>    </asp:updatepanel> 

and has benefited me because before wasn't able include autopostback="true" without taking me blank screen whenever chose alabama dropdown list. @ least entire screen isn't blanking out... still i'm not getting message show on screen.

also i've tried this, still no message appearing:

<asp:dropdownlist class="form-control" id="statedropdownlist" runat="server" autopostback="true" causesvalidation="false" onselectedindexchanged="statedropdownlist_selectedindexchanged"> 

any ideas or glaringly obvious why message isn't showing when chooses alabama?

try this:

<asp:scriptmanager id="scriptmanager1" runat="server"></asp:scriptmanager>  <asp:updatepanel runat="server" id="updtpnl"> <contenttemplate>     <asp:dropdownlist class="form-control" id="statedropdownlist" runat="server" autopostback="true" onselectedindexchanged="statedropdownlist_selectedindexchanged">         <asp:listitem value="al">alabama</asp:listitem>         <asp:listitem>other value</asp:listitem>     </asp:dropdownlist>      <br />     <asp:label id="alabamalabel" runat="server" visibile="false" text=""     font-bold="true" forecolor="#e00022" /> </contenttemplate> </asp:updatepanel> 

and change code-behind as:

protected sub statedropdownlist_selectedindexchanged(byval sender object, byval e system.eventargs) handles statedropdownlist.selectedindexchanged if statedropdownlist.selectedvalue = "al"     alabamalabel.text = statedropdownlist.selecteditem.text + " selected!"     alabamalabel.visible = true else     alabamalabel.visible = false end if end sub 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -