c# - How to put an alert box using javascript and asp.net? -




i want know how put alert box using javascript , asp.net. have created webpage admin fill form, , after clicking submit button, there should alert box popup message says upload successful or upload failed.

i tried doing code(i included javascript code , asp submit button):

<script>     function uploadstatussuccessful()     {         alert("upload successful!");     } </script>  <script>     function uploadstatusfail()     {         alert("upload failed!");     } </script>  <asp:button id="button1" runat="server" cssclass="submitbutton" text="save  item" onclick="button1_click"/> 

and here code-behind:

protected void button1_click(object sender, eventargs e) {      try     {         int item_brandid =          connectionclassbrands.getidbybrand(itembrand.text);         string item_model = itemmodel.text;         double item_price = convert.todouble(itemprice.text);         string item_image1 = session["picturepath1"].tostring();         string item_image2 = session["picturepath2"].tostring();         string item_description = itemdescription.text;         string item_necktype = itemnecktype.text;         string item_body = itembody.text;         string item_fretboard = itemfretboard.text;         string item_fret = itemfret.text;         string item_bridge = itembridge.text;         string item_neckpickup = itemneckpickup.text;         string item_bridgepickup = itembridgepickup.text;         string item_hardwarecolor = itemhardwarecolor.text;          if (itemtype1.checked)         {             int item_type =              connectionclassbrands.getidbytype(itemtype1.text);             itemtype = item_type;         }         else if (itemtype2.checked)         {             int item_type =              connectionclassbrands.getidbytype(itemtype2.text);             itemtype = item_type;         }          var item = new instrumentitem         {             typeid = itemtype,             brandid = item_brandid,             model = item_model,             price = item_price,             itemimage1 = item_image1,             itemimage2 = item_image2,             description = item_description,             necktype = item_necktype,             body = item_body,             fretboard = item_fretboard,             fret = item_fret,             bridge = item_bridge,             neckpickup = item_neckpickup,             bridgepickup = item_bridgepickup,             hardwarecolor = item_hardwarecolor         };          connectionclassguitaritems.addstringinstrumentitems(item);          button1.attributes.add("onclick", "javascript:return          uploadstatussuccessful()");          cleartextfields2();      }     catch (exception)     {         button1.attributes.add("onclick", "javascript:return          uploadstatusfail()");     }   } 

i tried doing button1.attrbute.add no alert box showing. please provide solutions or actual examples on how achieve this. kindly inform me if there wrong syntax missed can correct immediately.

you can use scriptmanager.registerstartupscript in code behind show alert message below . need scriptmanager control aspx page . recommended way

 scriptmanager.registerstartupscript(this.page, this.page.gettype(),            "err_msg",            "alert('upload failed!');",           true); 

otherwise can simple below

response.write("<script>alert('upload failed!');</script>");

link scriptmanager control

http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -