Click event for textbox - asp.net

There is one column of textbox in my item template. When I run the page and click on the textbox I want an event to fire. How can I make this happen?

What do you want to do when someone clicks? Odds are it's something you'd be best off processing on the client in JavaScript, possibly using jQuery. JavaScript will happily handle a "textbox" click event, although by the time your textbox hits the browser it's been rendered as an <input type="text">.
Think of ASP.Net as being a tool that generates and manipulates HTML, and sends it to/from the browser. ASP.Net events are the result of the browser posting the entire page back to the server, the server doing something to it, and the server sending the whole page back. There's obviously times when that is what you'd want, and times when it's not, I suspect this will be the latter, unless you're doing something data related.
To show a div on textbox click, I would use the jQuery Show() and Hide() methods. Create your content in ASP.net, and use 1 jQuery function to hide the div when the page loads (on browser, not server), and another to show them. Have a look at these - http://api.jquery.com/show/ and http://api.jquery.com/hide/ . The examples on that page will translate to what you're after; don't let the ASP.Net thing distract you, by the time your page is on the browser it's in HTML.

Related

JQueryMobile dialog shows twice because of a postback

I have an asp.net page with a timer embedded in an UpdatePanel (UpdateMode="Conditional", ChildrenAsTriggers="false"). The timer is responsible for updating some components of that page every few seconds.
There are also some HyperLink controls on the page and they open a JQueryMobile dialog when clicked (data-rel="dialog"). The problem is that the timer i mentioned causes postback every few seconds. So when a dialog is opened and then closed, the first such postback after then causes the dialog to open once again.
Using the rel="external" as another attribute of the HyperLinks I mentioned solves the problem, but this is no solution for me. This causes full redirection to the dialog page instead of showing it using AJAX (as if on top of current page).
My idea was to stop the timer when any hyperlink is clicked. This solves the problem, but I have no idea how to start the timer again when the dialog closes. Is it possible to detect when a JQueryMobile dialog is closed? I know, this sounds stupid, but I can't come up with a better idea. Will you help me, please?
So basically, I don't want the JQueryMobile dialog page to show up for the second time after a timer tick. Could you please advise me how to achieve that?
jQuery Mobile with asp.net Web Forms and an UpdatePannel? This just sounds like a horrible combination.
jQuery Mobile and Web Forms fundamentally don't work well together. The specific issue that Web Forms requires a single <form /> element that wraps all controls (and most content). jQuery Mobile attempts to build up the DOM with "virtual" pages via ajax loading. This breaks the PostBack model by submitting the entire form instead of the individual form found within each page template. Now throw UpdatePanels in there...
Your only hope is go exclusively with Single page templates and to disable all ajax loading data-ajax="false" on both links and forms. And just say no to UpdatePanels.
asp.net MVC would give you much greater control over these issues.

WebForms with ASP.NET AJAX: HyperLink vs LinkButton & Response.Redirect from GridView

I have 2 asp.net web forms. The first has a ScriptManager, History, UpdatePanel and GridView; the later is ScriptManager, UpdatePanel and TextBoxes. The premise here is a list that links to a detail form where an item can be edited.
From within the GridView (inside the UpdatePanel), if I use a HyperLink control with the url set to the edit page (with the necessary parameters), change something, save it and then click the back button I see the original list with no updates. Pressing F5 to refresh shows the changes.
If instead I use a LinkButton inside the GridView, and handle that LinkButton in code-behind to perform a Response.Redirect to the same edit page (with the same parameters), make the same changes, save and then click the back button, the list on the original page refreshes automatically to show my changes.
Note that the code in the detail page where the editing/saving takes place does not change - only the way it is first displayed is changed.
My question is this: what is it about the Response.Redirect that causes the page to be refreshed when the back button is clicked, and it it possible to replicate this for the direct HyperLink approach? I would prefer to use the HyperLink method as I see no reason for the postback, but I want the GridView to refresh when the user browses back to it.
Thanks.
A LinkButton causes a postback, the response to which is a HTTP 302 redirect command triggered on the server side by your Response.Redirect. Your web browser therefore does not cache the old version of the page.
The Hyperlink control simply renders a regular <a> tag which takes you to the detail page on the client side. The browser has no reason to believe the page may have changed, so it presents the cached version when you hit the back button.
If you want to tell the browser specifically not to cache the page if the back button is used,
use the cache-control HTTP header. W3C Link,
In any case, you should provide a link on the detail page (or automatic redirect on accepting changes) which takes the user back to the GridView/summary page, so they don't have to resort to using the back button.
Edit:
Sorry, the previously provided header example was not for Asp.net, but basically you'll want to do something like this:
Response.AppendHeader("Cache-Control", "no-cache")

jQuery UI + ASP.NET: Make Modal Popup Load After AJAX is Ready

I was hoping for a little help. I am currently using some of the jQueryUI widgets in an ASP.Net Web App. I have successfully got everything working. Basically, I have a GridView on a page which contains some hidden fields in each row containing data. I also have a dialog div containing an update panel and a few Labels.
When a user clicks on an Image Button on the GridView, the jQuery is fired to show the jQueryUI dialog and code behind is used to fill the labels from the selected GridView row. Unfortunately, the AJAX communication takes quite a bit longer to update versus showing the dialog div.
The same question actually applies to the loading of an ASP page into a jQuery popup window also as I will need to eventually do this.
So my questions are:
How can I make jQuery wait to execute until after the partial postback has returned with the AJAX information for the popup?
Is the above method the right way to go?
Is there a better way?
Is there a way to speed up AJAX
communications to make it more
instantaneous?
Thanks in advance for your input.
without knowing exactly what you're doing (code wise), the best I can understand is that you want to trigger some behavior after the ajax call has completed, which is actually supported like so:
$.ajax({
url: 'myurl.aspx',
success: function(data) {
//everything you want to happen after the ajax completes.
//this can either be code, or a call to another function that loads your div
}
});

Firing server side validations on moving from one page to another in Asp.NEt

I need to fire certain server side validation for a page when the user is trying move from that page to another..
Even though he is not clicking on any buttons these server side validations have to be fired when he is moving out of this page..
Could you please help me how to handle this.. Required field validations will not happen as the user is entering the page and leaving the page without doing any action in the page..
So you mean he's just changing the URL in the address bar? Or is he clicking something? If it's via clicking anything; you can just make whatever that thing is part of the appropriate validation group, and it will validate.
If he's just changing the URL, then you're going to need to detect leaving of the page (in JavaScript), and do some work. But depending on your scenario, I wouldn't recommend that.

Passing data to server code from a client-side control using ASP.NET AJAX

I have a ListView on a page that displays a list of widgets. When a user clicks on one of the items in the list, I want to display a ModalPopup that contains controls allowing the user to operate on the item they selected.
I could easily accomplish this by placing a Panel and a ModalPopupExtender in the ListView's ItemTemplate, but this mean one set of hidden controls for each and every widget, which would massively bloat the page size. (There are going to be some rather heavyweight controls in there.) Instead I want to reuse a single ModalPopup for each of the widgets in the list.
I've done some searching but I haven't found anything that applies directly to my situation before. From what I've been able to figure out, however, I have to do something like this:
Place a Panel and a ModalPopupExtender on the page inside an UpdatePanel.
Build a custom WidgetManipulator user control that has a WidgetID property. Put this in the Panel, along with a couple OK/Cancel buttons.
In Javascript on the page, attach a click handler to each widget in the ListView that triggers a postback on the UpdatePanel.
On the UpdatePanel_Load event on the server, display the ModalPopup and then set the WidgetID propety on the WidgetManipulator to the ID of the clicked widget.
On the OKButton_Click event or CancelButton_Click event on the server, hide the ModalPopup. If OKButton was clicked, call WidgetManipulator.SaveChanges() first.
The part I haven't figured out is: How the heck do I know what widget was clicked on, and how do I pass that back to the server when I refresh the UpdatePanel? Is this even the right approach at all?
If you can use jQuery instead you could do something along the lines of these two posts:
Modal Delete Confirmation Version
Two Using jQuery SimpleModal Plugin
Demo
Inserting Content Using
jQuery SimpleModal Plugin Demo
When I need to pass data from client to server in ASP.NET AJAX, I generally use an asp:HiddenField with runat="server". Both can see it freely, but beware potential postback asynchronicity.
Sounds like you need to notify the server the widget was clicked - You may use a Timer to postback; or I'd go with option 5.

Resources