Weird functionality when using ScriptManager.RegisterStartupScript - vb.net

I'm having this weird problem using the ScriptManager.RegisterStartupScript. Basically what I'm trying to accomplish when I click a button control, it goes back to the server, checks to see if any errors, and what I want to happen is that if there are any errors, want to use a popup box. The button control is inside an update panel. I thought the easiest way to accomplish this was to use a javascript alert box. So I finally got it working but when the alert box comes up it messes up my menu control until the alert box is going then its ok. Its kinda of hard to explain so I have insert a image to show you guys whats going on once the button is clicked. I dont know how to fix or whats going on, if someone could point me into the right direction. Also he my code im using.
Protected Sub btnPlan_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPlan.Click
'Dim sb As New System.Text.StringBuilder
sb.Append("<script language='javascript'>")
sb.Append("alert(' No data in the database ');")
sb.Append("</script>")
If (Not ClientScript.IsStartupScriptRegistered("JSScript")) Then
ScriptManager.RegisterStartupScript(UpdatePanel5, Me.GetType(), "JSScript", sb.toString(), True)
End If

You may try to use RegisterClientScriptBlock:
Protected Overrides Sub Page_Load(ByVal sender as Object, ByVal e As System.EventArgs)
MyBase.Page_Load(sender, e)
Try
If Not ScriptManager.IsInAsyncPostBack Then
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "AlertScript", "<script type='text/javascript' language='javascript'>function YourAlert(){alert(' No data in the database ');}</script>")
EndIf
Catch ex As Exception
End Try
End Sub

Thanks for all your suggestion. I skinned this a different way and got it to work the way I wanted. What i did was put the message in a hidden textbox and used jquery to ensure that the page was already load then alert the message if needed.

Related

Why does my subroutine, which handles a double-click event on a listbox, not work?

I have declared a Sub that is meant to trigger when the listbox 'lstStudents' is double-clicked. However, it does not trigger when this happened. There can't be an error in the code itself as it is auto-generated. Why does the code not function as expected? The code is below:
Private Sub lstStudents_DoubleClick(sender As Object, e As EventArgs) Handles lstStudents.DoubleClick
Msgbox("test")
End Sub
The message box is only present for testing purposes.
Could You try to delete that previous "lstStudents" and add new one then apply the "ListBox1_DoubleClick" on it again to make sure it works.
Otherwise let us know what is going there because I think your code is normally and it should be working 100%.

VB.Net - Manage errors label

I'm working on visual studio 2015 and I'm working on a classic subscribing form.
I want to generate error labels when the user type wrong password, the wrong pseudo, etc. But I can work on it myself.
But when I write those error labels and set their visible at false in "Dev mode", I have to juxtapose those labels if I want my labels at the same place, and it's not what I want when I have many errors to manage on one textBox for example.
Is there a solution to gererate those labels, without write them before playing with hide() or show() ?
Here is the screenshot in order to illustrate my problem.
It's not really a problem itself, but It's not practical when I'm develop many errors.
Sorry for my english, I hope you understood my problem, I can give you more details =)
Have a nice day full of code !
Here the button code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "Password" Then
Label2.Text = "Your answer is wrong"
End If
End Sub
This is what it looks like:

How to get more than one parent control in form

Newbie here :)
In order to achieve a transparency-type effect for pictureboxcharacter1 on the background, I have set pictureboxbackground1 as its parent.
this works fine.
For the second picturebox (on the same form) I tried the same thing and set pictureboxbackground2 as its parent so it would look transparent over pictureboxbackground2. However when I debug the application pictureboxcharacter2 disappears and only pictureboxbackground2 is visible.
the code I have is:
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.pictureboxcharacter1.Parent = Me.pictureboxbackground1
Me.pictureboxcharacter2.Parent = Me.pictureboxbackground2
End Sub
Really strange: if I put pictureboxcharacter2 on pictureboxbackground1 in the designer tab, while debugging it shows up on picturebackground2 and transparent (like how I wanted it to be)??
Does anyone know what's going on at all?
Please I'm NEED any help I could get
Is pictureboxcharacter1 and pictureboxcharacter2 one over other ? If so try making the one be other's parent.
Have a play with bring to front option and see if that works.

Converting C# to VB.net is not working

I have translated some code from C# to VB.net for the purpose of getting Folder Browser functionality. The link to the code is here.....
http://www.codeproject.com/KB/aspnet/DirectoryBrowsing.aspx
My issue is that I have not been able to correcly translate these two lines of code to VB.net.
TreeView1.TreeNodeExpanded +=new TreeNodeEventHandler(TreeView1_TreeNodeExpanded);
TreeView1.SelectedNodeChanged += new EventHandler(TreeView1_SelectedNodeChanged);
Every translator I have used has simply dropped the semicolon from the end of each line. But the editor still does not like them.
I could some help with this as it seems this effects the refresh of the selected folder in the tree view control.
I don't get to see the C drive folder unless I type the path in the text box, and the folder will still not expand.
thank you,
Use this:
AddHandler TreeView1.TreeNodeExpanded, AddressOf TreeView1_TreeNodeExpanded
AddHandler TreeView1.SelectedNodeChanged, AddressOf TreeView1_SelectedNodeChanged
Edit:
A different way to do this would be to apply it at the method level:
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender as Object, ByVal e as TreeNodeEventArgs) Handles TreeView1.TreeNodeExpanded
' Some code
End Sub
Protected Sub TreeView1_SelectedNodeChanged(ByVal sender as Object, ByVal e as EventArgs) Handles TreeView1.SelectedNodeChanged
' Some code
End Sub
You should run this in debug to find out what exactly is going on. I find a lot of times when events of this nature are run in asp.net, you have a conflicting event that "resets" the controls you are attempting to change.

Lost Focus problems

I use the LostFocus Event in vb.net to check the validity of a field for the name.
After this field a have another one which is the for the password validity, and i'm handilg the same event in order to check the password.
My problem comes when i run the (name) lost focus, runs the code inside the sub and after that automatically goes to the password_lostfocus which brings me alot of troubles.
That happens even i use the error provider which works fine and bring to me the error with the red flashing.After that i put the command (name_textbox.focus), which logically has to bring the control in the name_textbox.. But NO.. the control goes to the Password_textbox sub automatically.
Please see my sub
Private Sub UsernameTextBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles UsernameTextBox.LostFocus
Select Case DB_Access.IfExistUser(UsernameTextBox.Text, sender, e)
Case True
PasswordTextBox.Focus()
Case False
ErrorProvider1.SetError(UsernameTextBox, "Ο χρήστης ΔΕΝ υπάρχει παρακαλώ καλέστε τον Administrator")
Beep()
UsernameTextBox.Text = ""
UsernameTextBox.Focus()
End Select
End Sub
Please if anyone have seen this issue and face it, assist me.
Excuse me for some Greek characters they are meaningless, they are comments
Well finally i found that.
In order to handle the Login Form as it give it from visual studio 2010 you need to do it in only one sub (Lost Focus) and that is only the password_LostFocus.
I believe the particular form is meant to be like that.
Any way i solve the issue and if anybody needs assistance on that just "asc a question"