Is it possible to disable an ImageButton when processing? - asp.net

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

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 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

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!

asp.net CustomValidator fires, but ServerValidateEventArgs Value always empty

I'm having a problem implementing a CustomValidator, I have multiple TextBoxes with a MaskedEditExtender, they all should contain a date ("dd-MM-yyyy"). To check this date I want to use the CustomValidator, but the e.Value passed to my MyValidate function is always empty, while the TextBox is not.
code:
<asp:TextBox ID="Gereed" runat="server" CssClass="date" />
<asp:CustomValidator ID="cd1" runat="server" TargetControlID="Gereed" />
<asp:MaskedEditExtender ID="md1" runat="server" TargetControlID="Gereed"
Mask="99-99-9999" ClearMaskOnLostFocus="false"/>
code behind:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
cd1.ValidateEmptyText = True
AddHandler cd1.ServerValidate, AddressOf ValidateDate
End Sub
Protected Sub ValidateDate(ByVal sender As Object, ByVal e As ServerValidateEventArgs)
e.IsValid = MyValidate(e.Value, "dd-MM-yyyy")
End Sub
I had a ClientValidationFunction that has the same problem.
Does anyone know a solution to this? I guess I'm missing something, but I don't know what, a similar solution in another website works perfectly.
TargetControlID is not a property of CustomValidator, it should be ControlToValidate. Somehow there was no errormessage, normal Validators throw an exception if ControlToValidate was not found, but the CustomValidator does not.

Resources