2

I previous asked for assistance but don't think I ask the right question. I am new to coding & have a web app with a form on it which has a yes/no dropdown & a textbox after for a reason. I managed to write the code behind for a msgbox but I need it on the client side. I know it's not nearly as complicated as I thihk. This is the code behind I used for the server side msgbox:

Protected Sub SubmitButton_Click(sender As Object, e As Event Args) Handles SubmitButton.Click
If CriticalList.Text = "Yes" THEN
 If TextBox13.Text <> "" THEN
   SqlDataSource1.Insert()
 Response.Redirect("FormsReport.aspx")
ELSE
  MsgBox("If critical, you MUST provide a reason.")
 End IF
ELSE
   SqlDataSource1.Insert()
  Response.Redirect("FormsReport.aspx")
End IF
End SUB

Can someone, ANYONE please give me some guidance of how I would write this for a client side alert? Preferably in code behind.

Malachi
  • 3,205
  • 4
  • 29
  • 46
Kathy
  • 25
  • 1
  • 1
  • 2
  • This has been answered here: http://stackoverflow.com/questions/7673795/call-javascript-from-vb-net-code-behind – Henry O Aug 13 '13 at 19:10
  • possible duplicate of [JS Statement for Client Side Alert in .aspx.vb](http://stackoverflow.com/questions/18112270/js-statement-for-client-side-alert-in-aspx-vb) – Malachi Aug 13 '13 at 19:18

2 Answers2

1
Dim message As String = "If Critical, you MUST provide a reason."
Dim script As String = "<script type='text/javascript'> alert('" + message + "');</script>"

correction for the Above will be as this

ClientScript.RegisterClientScriptBlock(Me.GetType(), "AlertBox", script)

Dont forget the single qouts at the alert code

gofr1
  • 15,741
  • 11
  • 42
  • 52
0

http://social.msdn.microsoft.com/Forums/en-US/7d156d49-ea9a-4f58-a17f-228c9470ee7a/display-a-message-box-in-a-vbnet-web-application

this is one of the answers found on the link given above. of course you will have to adapt it to your code a little bit.

Dim message As String = "If Critical, you MUST provide a reason."
Dim script As String = "<script type='text/javascript'> alert(" + message + ");</script>"

ClientScript.RegisterClientScriptBlock(Me.GetType(), "AlertBox", script)

I have not tested this code so I don't know that it works the way you intend it to, please test

Malachi
  • 3,205
  • 4
  • 29
  • 46