Get Button Id Sender In Grid Batch update Dev Express vb.net - asp.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:

Related

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

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

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

Basic Website Web Form - How to link DropDownList to internal .aspx pages?

I'm relatively new to using VB, and am trying to do the following:
Select DropDownList item upon Button click
Link DropDownList items to internal pages
I feel like this is basic stuff, but am having a hard time with it.
Is this correct?
1 .
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="Answer.aspx">Answer</asp:ListItem>
2 .
<asp:Button ID="Button1" runat="server" Text="Button" onselectedindexchanged="DropDownList1_SelectedIndexChanged" />`
You will need to change your code a little bit to achieve this. First, you do not need the AutoPostback on the dropdown list unless you want it to hit the server when you select a new list item.
On the button click, you will want to remove the
OnSelectedIndexChange="DropDownList1_SelectedIndexChanged"
And replace it instead with the button's OnClick event.
OnClick = "Button1_Click"
You will need to add your vb code to redirect to the new page. I'm more of a C# guy, but this should work.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim LinkText as string
LinkText = DropdownList1.SelectedItem.Value
Response.Redirect(LinkText)
End Sub
Are you trying to say, after clicking the button, it will go to the other page by selecting in dropdownlist what page it is? If I'm correct, here's how it is.
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Response.Redirect(DropDownList1.SelectedValue.ToString)
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

Button Click and LinkButton Click

I am having a strange day! I am trying to access values inside the Datagrid control. There are textboxes in each row of the Datagrid control. If I use a asp.net button control outside the datagrid control I can access all the values. But if I use LinkButton outside the datagrid control then I cannot access any value.
I have to use LinkButton.
UPDATE 1: Code
//This works
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim indexes() As Integer = dgReceipts.SelectedIndexNumbers
End Sub
//This does not work and I get 0 items in the SelectedIndexNumbers
Protected Sub LinkButtonUpdateReceipts_Click(sender As Object, e As EventArgs) Handles LinkButtonUpdateReceipts.Click
Dim indexes() As Integer = dgReceipts.SelectedIndexNumbers
End Sub
<asp:Button ID="Button1" runat="server" Text="Button" />
<c1:LinkButton ID="LinkButtonUpdateReceipts" runat="server" Text="Update Totals" Icon="images/go-blue-right.gif"></c1:LinkButton>
I'm suprised that either of those work. You do not appear to have an OnClick event for either of those buttons. At a minimum I would add an OnClick event to your LinkButton that fires LinkButtonUpdateReceipts_Click.
Also, why aren't you just using <asp:LinkButton? what is <c1:LinkButton?

Resources