VB.NET Events aren't working or displaying info? - asp.net

I am currently attempting to query my database to link it to my login screen.
So when you enter a password for the login to say "invalid user" etc.
But, I go to set the button_click function, and in the Events, I could not find button1, only found page load, even though I right clicked and went to properties on the button. It only displayed a blank drop down and something called PageLoad. Can anyone help with this issue?
Snippet:
<p class="submitButton">
<asp:Button ID="button1" runat="server" CommandName="Login" Text="Log In"
ValidationGroup="LoginUserValidationGroup" onclick="Page_Load"/>
</p>
Public Class Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString("ReturnUrl"))
End Sub
End Class
See image here.

Remove onclick="Page_Load" ,
Try to add a click handler manually like this
Protected Sub button1_Click(sender as Object, e as System.EventArgs) Handles button1.Click
End Sub

Related

Get Button Id Sender In Grid Batch update Dev Express vb.net

I have a method "Grid Batch Update", in this case, i want get an id from button clicked in this method
Private Sub grid_BatchUpdate(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataBatchUpdateEventArgs) Handles grid.BatchUpdate
'My Code
End Sub
I have tried to search but not found the answer
Ok, then as a general rule, you can use "sender".
Protected Sub Button1_Click1(sender As Object, e As EventArgs) Handles Button1.Click
Dim btn As Button = sender
Debug.Print("id of button is " & btn.ID)
End Sub
However, do note if you going to have say several buttions use the SAME event?
Then you should remove the handles from above. And then you "must" then set the on-click event.
So, above becomes:
Protected Sub Button1_Click1(sender As Object, e As EventArgs)
Dim btn As Button = sender
Debug.Print("id of button is " & btn.ID)
End Sub
And I might then say have two buttons use the same click event. eg this:
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />
<br />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button1_Click1" />
So, if you double click on a button from the web forms designer, it will NOT put in a OnClick tag, but uses the "handles button one in code behind.
Either way is fine - but you don't need (nor want) the "handles" tied to one button on the code behind - so use markup OnClick="Button1_Click1"
In above, then clicking on either button would result in this:

vb.net button click event not firing first time

I have a very simple Textbox and Button, but Button click event not firing at first time ( only firing in second click)
<asp:TextBox ID="TxtSurvey" runat="server"></asp:TextBox> <br />
<asp:Button ID="BtnGoSurvey" runat="server" Text="LetsGo"/>
The code is very simple too
Protected Sub BtnGoSurvey_Click(sender As Object, e As EventArgs) Handles BtnGoSurvey.Click
Session("IDSurvey") = TxtSurvey.Text
BtnGoSurvey.PostBackUrl = "~/Survey.aspx"
End Sub
What i'm doing wrong ?
Thanks for help
If you can use Response.Redirect, then following is supposed to work:
Protected Sub BtnGoSurvey_Click(sender As Object, e As EventArgs) Handles BtnGoSurvey.Click
Session("IDSurvey") = TxtSurvey.Text
Response.Redirect("~/Survey.aspx",True)
End Sub

Button name on Content Page From Master Page

In my master page I have two buttons:
<asp:Button ID="btnPrev" runat="server" CssClass="btn btn-prev" Text="Prev" />
<asp:Button ID="btnNext" runat="server" CssClass="btn btn-next" Text="Next" />
The user clicks on the and of course the page fires, great, except I want to do an action based on which button is pressed. I can go back and reference the Master Page as the first thing on the Content Page
Call btnNext_clickassessment(sender, e)
and
Protected Sub btnNext_clickassessment(sender As Object, e As System.EventArgs)
Me.Master.btnNext_Click(sender, e)
End Sub
However this does not determine which button was actually pressed.
I have looked at onclick and If CType(sender, Button).ID = "btnNext_Click" Then but nothave not found a solution yet (or one of those is an I've set it wrong!
Maybe even some javascript?
You can also declare a public property on your master page and then handle the events on the content page as below
MasterPage
Public btnPrev As Button
Public btnNext As Button
ContentPage
'in page load
AddHandler Me.Master.btnPrev.Click, AddressOf Me.btnPrevNext_Click
AddHandler Me.Master.btnNext.Click, AddressOf Me.btnPrevNext_Click
and then your handler
Private Sub btnPrevNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Handle your Button clicks here
dim btnName as string
btnName = sender.ID
' do stuff with the button name
End Sub
Alternatively use two distinct handlers to simplify your code
ContentPage
'in page load
AddHandler Me.Master.btnPrev.Click, AddressOf Me.btnPrev_Click
AddHandler Me.Master.btnNext.Click, AddressOf Me.btnNext_Click
and then your handler
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Handle your Previous Button click here
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Handle your Next Button click here
End Sub

Is it possible to disable an ImageButton when processing?

Is it possible to disable an ImageButton when running a process?
I found a way to disable a Button when processing, doing this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim strProcessScript As String = "this.value='Processing...';this.disabled=true;"
btnProcess.Attributes.Add("onclick", (strProcessScript + ClientScript.GetPostBackEventReference(btnProcess, "").ToString))
End If
End Sub
But it didn't work for ImageButton.
Also, I tried this code for disabling an Imagebutton:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim strProcessScript As String = "this.value='Processing...';this.disabled=true;"
btnProcess.Attributes.Add("onclick", (strProcessScript + ClientScript.GetPostBackEventReference(btnProcess, "").ToString) + ";return false;")
End If
End Sub
Neither of both ones makes ImageButton to be disabled when processing, but it works for Button.
this suits better for full postback solution, if you are using ajax, I'd recommend to consider a jquery plugin or any other javascript plugin you can search for, saying that well hereĀ“s a small work around:
you need to use the onClientClick event that's provided OOB for the image button, it's easier to manage due to it's directly tied to the onlick event over the client and there's no nee to registar a custom client event when clicking the button.
all you need to do is passing your code to the onClientClick event
<asp:ImageButton runat="server" ID="BtnSubmit"
OnClientClick="this.disabled = true; this.value = 'Processing...';"
UseSubmitBehavior="false"
OnClick="BtnSubmit_Click"
Text="Submit Me!" />
take a look to this solution

Hide control in Page_Load

I am using label control in form designing.But i want to hide that particular label control on page load.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label10.Visible = False
End Sub
What should i do? I'm new to vb.net.
Try setting the visibility property within the aspx code rather than within the load event, this may solve your issue.
<asp:Label ID="lblValidation" runat="server" BackColor="Red"
Text="Please fill in all of the date fields below to proceed" Visible="False"></asp:Label>
Hope this helps!

Resources