Solved

Calling a Server side sub from the onBlur event

Posted on 2009-07-08
1
726 Views
Last Modified: 2012-05-07
Hello Experts,

I have a form that needs to run a server-side function when the user tabs out of certain textboxes.  Right now it works great, except I'm using the TextChanged event.  What I really need is to run the same function, but with the onBlur event.

Now I realize that's asking client code to run a server function ... but that's really what I need here.  The textboxes are set to cause a postback, so it's already hitting the server.  The webpage is ajax enabled if that helps.  Any ideas?

Thanks!
0
Comment
Question by:GRCHELPDESK
1 Comment
 
LVL 2

Accepted Solution

by:
GRCHELPDESK earned 500 total points
ID: 24814484
Hello Experts,
Turns out this is far more tricky than I'd hoped.  This can be done, but the method is a little hacky.  To start you create the textbox for your onBlur event.  Then create a button to associate with the textbox.
Ex: txtFirstName & btnFirstName

In your Page load event, add this code:
Dim strEventHandler As String = Me.GetPostBackEventReference(Me.btnFirstName, "") Me.txtFirstName.Attributes.Add("onblur", strEventHandler)

Now, double click your button to create the event handler code.  Mission accomplished.  Enter in your blur code in the event handler of the button and it'll run on the blur event for the textbox.  Essentially, it's redirecting the client-side onBlur event of the textbox to the server-side click event of the button.  But sure to hide the button since since clicking it will cause the blur code to run.  And be sure to set the textbox as autopostback = true.
Hope this helps someone!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question