Wednesday, December 14, 2016

Handling post back for jquery control

This is the way you can handle post back issues.

function pageLoad(sender, args)
{
   if (args.get_isPartialLoad())
   {
       //Specific code for partial postbacks can go in here.
   }
}

for ref:
http://stackoverflow.com/questions/301473/rebinding-events-in-jquery-after-ajax-update-updatepanel

Friday, January 27, 2012

jQuery $(document).ready() and ASP.NET Ajax asynchronous postback

I’ve been a bit skeptic about the thought of combining ASP.NET Ajax with jQuery, partly because I didn’t really know what the impact was going to be. But jQuery is very fast, very appreciated throughout general opinion, there are extremely many plugins available for free, writing your own plugins only requires little JavaScript knowledge (opposed to writing your own extender in .NET, like controls in the AjaxControlToolkit).

To be sincere, there is a very short learning curve so there is no reason for not trying jQuery. I’ve tried with regular web applications, but when I coupled jQuery with ASP.NET Ajax on little niggle stood out.

Many call it the ASP.NET jQuery postback problem, but using the technique below should make it no problem anymore. $(document).ready() isn’t called after an asynchronous postback. What this means? You lose the functionality that should be executed within $(document).ready() after an UpdatePanel rendered its contents after an asynchronous postback.

But it’s not difficult to solve this issue! Microsoft AJAX Library contains an event called: EndRequest which can be handled with JavaScript code. What actually happens in this situation is that a piece of JavaScript codes is executed whenever an asynchronous postback has ended. If we execute our logic from $(document).ready() inside the EndRequest handler we are good to go :).

As a short example I came up with the following:
- there is a TextBox on a page, and a Button (both inside an UpdatePanel)
- whenever the user pushes the Button, I fill out the textbox with the current server time
- there is a script tag on the page containing some JavaScript code to display an alert whenever the $(document).ready() has been executed.

The server side controls needed for this example are01.:

****************************************************************




















In codebehind you only need the click event handler for the Button:


protected void btnTime_Click(object sender, EventArgs e)

{

txtTime.Text = DateTime.Now.ToLongTimeString();

}
Including the following JavaScript code in your page reveals the actual problem:



The alert is shown only when you load the page, this of course would also happen after a full postback. Everything inside the $(document).ready() function will be called as soon as the DOM is ready to be manipulated. The actual problem is that we are still interested to execute the code inside $(document).ready() after an asynchronous postback using the standard ASP.NET UpdatePanel control.

The solution comes in the form of some additional JavaScript code:



This way, on each postback, on each asynchronous postback the JavaScript code will still be called. Why this is needed? Because in many cases you’ll need to bind jQuery plugins to controls that are being updated inside UpdatePanels.

Now you can still enjoy ASP.NET Ajax with the simplicity of the UpdatePanel, and you can still enjoy jQuery with all it’s speed and performance and plugins and all.

If anybody needs help with this issue I’ll gladly help!

Monday, December 20, 2010

Wednesday, September 15, 2010

Displaying the text of the UITableViewCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

// create a cell

UITableViewCell *cell=[[UITableViewCell alloc]
initWithStyle:UITableViewCellDefault
reuseIdentifer:@"sunny"];


//fill with contet


cell.textLabel.text=[test objectAtIndex:indexPath.row];


//return it

return cell;

// we done it baby =))

}

How many rows in the section

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return test.count;
}