asp.net - calling alert from code-behind -


i have dropdownlist , listbox both asp.net controls

i trying prevent user add duplciate items listbox control

i able block want display div or alert box saying,"duplciate names not allowed"

protected void btn_addrecipientaction_onclick(object sender, eventargs e)         {             if (convert.toint32(this.ddlrecipient.selectedvalue) > 0)             {                 if (ddlrecipient.text.length > 0)                 {                     //var items = new system.collections.arraylist(this.lstrecipient.items);                       for(var = lstrecipient.items.count - 1; >= 0; --i)                      {                                               if (lstrecipient.items[i].text == ddlrecipient.selecteditem.text)                         {                             lstrecipient.items.removeat(i);                             **//alert("duplicate entry not allowed")                             //div display message , disappears after few seconds?**                         }                      }                      listitem newlist = new listitem();                     newlist.text = ddlrecipient.selecteditem.text;                     newlist.value = ddlrecipient.selectedvalue;                     this.lstrecipient.items.add(newlist);                 }               }          } 

alert way:

you use line assuming have scriptmanager

scriptmanager.registerclientscriptblock(this,this.gettype(),"alert","alert('duplicate entry not allowed');",true); 

this, still postback since script run when page loaded again after click. better solution validate in client using javascript before submitting page.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -