Reputation: 5947
In my server side code, I need to display an alert message and stop the execution of the page when a certain condition is satisfied. The execution stops, but I am not getting the alert message. What am I missing? My code goes like this.
Try
If txtAmtRequested.Text > Val(HiddenTotalFeeAmount.Value) Then
ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), UniqueID,
"javascript:alert('Total Fee Amount set for this student is - '" & HiddenTotalFeeAmount.Value & "'... Enter Concession Amount lesser than this one..!')", True)
Exit Function
End If
Catch ex As Exception
End Try
Upvotes: 1
Views: 16038
Reputation: 4173
Try this:
Try
If txtAmtRequested.Text > Val(HiddenTotalFeeAmount.Value) Then
ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), UniqueID,
"javascript:alert('Total Fee Amount set for this student is - " & HiddenTotalFeeAmount.Value & "... Enter Concession Amount lesser than the..!');", True)
Exit Function
End If
Catch ex As Exception
End Try
You ended the string in javascript when inserting your value, resulting in this javascript:
javascript:alert('Total Fee Amount set for this student is - ' <Value> '... Enter Concession Amount lesser than the..!');
Instead of this you have to insert the value directly into the string, or add "+" to concat the strings:
javascript:alert('Total Fee Amount set for this student is - <Value> ... Enter Concession Amount lesser than the..!');
or
javascript:alert('Total Fee Amount set for this student is - ' + <Value> + '... Enter Concession Amount lesser than the..!');
Upvotes: 3