It's because you were mixing types. As delayTime was numeric, when you did "+" it thought you wanted to add rather than concatinate, so tried to convert what was to the left of the "+" into a numeric format but couldn't. By converting
delayTime to a string, you are now using "+" on two strings so the compiler is in no doubt that you want to concatinate and not add.
Shyner2ASP
Member
1 Points
7 Posts
ClientScript.RegisterStartupScript error
Feb 08, 2013 08:21 AM|LINK
I have a class that i use to create script to use jNotify in my ASP.Net Application which works well without adding delay time.
But after adding delay time it generate error.
Below is my class
Public Shared Sub ShowWarningMesage(ByVal _page As Page, ByVal _message As String, _ ByVal delayTime As Integer) _page.ClientScript.RegisterStartupScript(_page.GetType(), "notificationScript", "<script type='text/javascript'> $(document).ready(function () { $.jnotify('" + _message + "', 'warning', " + delayTime + "); });</script>") End SubThis is how i call it in my page
Input string was not in a correct format.
Line 71: Public Shared Sub ShowErrorMesage(ByVal _page As Page, ByVal _message As String, _ Line 72: ByVal delayTime As Integer) Line 73: _page.ClientScript.RegisterStartupScript(_page.GetType(), "notificationScript", Line 74: "<script type='text/javascript'> $(document).ready(function () { $.jnotify('" + Line 75: _message + "', 'error', " + delayTime + "); });</script>") [InvalidCastException: Conversion from string "<script type='text/javascript'> " to type 'Double' is not valid.] Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +212 Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value) +6 AppsComponents.NotificationHelper.ShowErrorMesage(Page _page, String _message, Int32 delayTime) in C:\Users\BISM\WebApplications\HRMSolution\ProjectLibraries\AppsComponents\NotificationHelper.vb:73 benefitandrewards_Default.Button1_Click(Object sender, EventArgs e) in C:\Users\BISM\WebApplications\HRMSolution\WebUI\benefitandrewards\Default.aspx.vb:7 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563AidyF
Star
9204 Points
1570 Posts
Re: ClientScript.RegisterStartupScript error
Feb 08, 2013 08:24 AM|LINK
Try
Shyner2ASP
Member
1 Points
7 Posts
Re: ClientScript.RegisterStartupScript error
Feb 08, 2013 08:44 AM|LINK
@AidyF Thanks it worked!
AidyF
Star
9204 Points
1570 Posts
Re: ClientScript.RegisterStartupScript error
Feb 08, 2013 08:55 AM|LINK
It's because you were mixing types. As delayTime was numeric, when you did "+" it thought you wanted to add rather than concatinate, so tried to convert what was to the left of the "+" into a numeric format but couldn't. By converting delayTime to a string, you are now using "+" on two strings so the compiler is in no doubt that you want to concatinate and not add.