• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Trouble getting error message box to show.

I have a massive page that is almost all dynamically created in the code behind page VB.net. I am having trouble getting error messages to popup.

I have a error message that fires in the load event that does work but anytime I try to show a error message after the page has been rendered it never shows.

I have dynamically created buttons that i use to run a function to save user entered data to a sql database. I have a generic button click event that I use to evaluate which button was clicked so I update the correct data. The error messages are if the update fails or if the user enters the incorrect data type.

These are the two ways I have tried to show the errors. Keep in mind that I use both of these on other pages without issue and the first one is the one that works correctly on the load event of this page.

' Define the name and type of the client scripts on the page.
                        Dim csname1 As String = "PopupScript"
                        Dim cstype As Type = Me.GetType()
                        ' Get a ClientScriptManager reference from the Page class.
                        Dim cs As ClientScriptManager = Page.ClientScript
                        ' Check to see if the startup script is already registered.
                        If (Not cs.IsStartupScriptRegistered(cstype, csname1)) Then

                            Dim cstext1 As String = "alert('Unable to the update on the record.');"
                            cs.RegisterStartupScript(cstype, csname1, cstext1, True)

                        End If

Open in new window


ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(Page), "clientScript", "alert('" & strreturn & "')", True)

Open in new window


I can only assume that this is some post back issue however I'm not sure what to do about it.

Thanks,

Tyler
0
tybarton
Asked:
tybarton
  • 4
  • 2
1 Solution
 
CodeCruiserCommented:
With first approach, try changing

Dim cstext1 As String = "alert('Unable to the update on the record.');"

to

Dim cstext1 As String = "<script>alert('Unable to the update on the record.');</script>"
0
 
Tom BeckCommented:
Of course you would then want to remove the last argument ("True") or change it to "False" otherwise you will have a double set of script tags.

Can you confirm that the script block is printing to the page by looking at the source code.
0
 
tybartonAuthor Commented:
Ok so that maybe the issue. The code is in the button click event and I looked at the source and the script is not on the page that I can find so it never fires.

Can you make a generic error script on the page and call it from code behind? I guess I could also try using the popupextender ajax control.

Thanks,
Ty
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Tom BeckCommented:
>>Can you make a generic error script on the page and call it from code behind?

Yes, but you would do it the same way by using RegisterStartupScript to call the javascript function on the page. Not much point in that.

You could just create the error alert in code behind at the point where the update fails. For example, if you have a Try/Catch block to handle the update, you could register the start up script for the alert in the Catch section as a form of error handling. You could even include the actual error if applicable.
0
 
tybartonAuthor Commented:
Maybe I was not clear in my first post but that is where I have the code listed and neither works.

Thanks,
Tyler
0
 
tybartonAuthor Commented:
I went with the modalpopup and it is working.

Thanks for your suggestions.

Tyler
0
 
tybartonAuthor Commented:
Solved the issue by a diffrent means myself.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now