Hello,
I have created a project as web application. I use webforms and added asp button. In code behind I have added a simple alert message in the button click event handler. Everything works fine except one issue that I don't know why I am experiencing it.
Every time I click the button it doesn't show me the message in the first click attempt but it shows when I click it the second time.
Could you help me fix this issue please?
Do the following step by step to replicate the issue I am experiencing. I am using Visual Studio 2017 Visual Basics webforms.
- Create Asp.NET WebApplication(name it whatever you want)
- Your application should come with one Site.Master, one Site.Mobile.Master and three webforms (About.aspx, Contact.aspx and Default.aspx)
- In the Default HTML add one asp button(Button1) as shown below
<asp:Button ID="DefaultPage" runat="server" Text="Default Page" />
- In codebehind for Default Page click event, add a page transfer code as shown below
Protected Sub DefaultPage_Click(sender As Object, e As EventArgs) Handles DefaultPage.Click
Server.Transfer("~/About.aspx")
End Sub
- Open the About.aspx page and add one asp button(Button1) in the html as shown below
<asp:Button ID="ClickMe" runat="server" Text="Click Me" />
- In codebehind for ClickMe click event, add a code to show a message as shown below
Protected Sub ClickMe_Click(sender As Object, e As EventArgs) Handles ClickMe.Click
Dim message As String = "Testing button click"
ClientScript.RegisterStartupScript(Me.[GetType](), "myalert", "alert('" & message + "');", True)
End Sub
I am using Google Chrome. This is a very simple example and I am trying to show you my issues.
- Now go back to the Default.aspx page and ran the application.
- When the Default page opens click the button, which says “Default Page”. You should be transferred to the About.aspx page
- After you have been transferred to the About.aspx page click the button, which says “Click Me”.
- At this point the message should have been displayed but in my case it doesn’t show in the first click and I have to click the button one more time for the message to display.
- My question is why it doesn’t display the message in first click? Why click twice?
- Close it and ran, it will not show in first click.