SharePoint Webparts and Ajax - ajax

Please, I am new to webparts and I need help!!
I have a custom web part that I created. I added MS Ajax to it using an UpdatePanel which works fine. I add all my controls to the CreateChildControls method. As soon as I add a UpdateProgress control my page breaks with the following error:
Script controls may not be registered before PreRender
I do not use the OnPreRender event as what other posts suggest. Please, if anyone can give me advice it will be very much appreciated.
Thanks

I encountered similar problem before, try to call EnsureChildControls method inside your on init method override. It should be called by system automatically, but sharepoint likes to forget about it from time to time.
Like this:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
EnsureChildControls();
}

You might have forgotten to call the base method of an overrided event, which is not necessarily the OnPreRender event.
Check if the OnInit or OnLoad events are calling their base.On[...] method, e.g.:
protected override void OnLoad(EventArgs eventArgs)
{
base.OnLoad(eventArgs);
// your code...
}

Related

how to show main method exception message on mvc view page?

In my project I have use main method implementation for saving values from excel sheet to database. Now, I have to show main method exception message on view page where I have designed an interface to upload excel sheet and a button. Please help me....
You could perform your error handling by overriding Application_Error in global.asax.cs. That way you can be sure that your code will only execute when an error occurs. In here you could put a redirect to a ErrorPage.cshtml page
Here's the function:
void Application_Error(object sender, EventArgs e)
{
//do your stuff here
}

Catching pressing "Back" button in mvvmlight

How can i move
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
to the viewmodel and still be able to control "back'ing"? In the codebehind, i can use e.Cancel = true;, but how to use it in the viewmodel?
You can't bind something that isn't bindable per say. All you can do is either create a fake binding using a Behavior<T>, but not much point in that.
Instead you could just simply forward the event in the ViewModel, doing something like:
e.OnCancel = ViewModel.OnBackKeyPress();
And then have OnBackKeyPress() return a bool.
The very first idea that i got - is to leave it in codebehind, and send message to viewmodel, so it should shange its state. But i'd still prefer to bind event to VM.

wicket AjaxLink onclick not responding

I'm building a website with wicket. I have a modal window that opens from an ajaxlink from the main page. The problem is that when I added a CSS to my HTML code in order to make it more visible attractive, it stopped working. So now, when I click in the AjaxLink that opens the modal window, nothing happens and I can't figure out why. Any Ideas??
This is the code of the AjaxLink:
AjaxLink privacyLink = new AjaxLink<Void>("privacylink") {
#Override
public void onClick(AjaxRequestTarget target) {
// TODO Auto-generated method stub
modal2.show(target);
}
};
One more comment. This AjaxLink is introduced as a part of a ListView, so actually there are multiple AjaxLinks.
In order for the AjaxLink to refresh you will need to call something along the lines of:
modal2.setVisible(true);
target.addComponent(modal2Container);
Where modal2 is the component that you want to control the visibility of, and modal2Container is a WebMarkupContainer with .setOutputMarkupId(true) that modal2 is added to when the page/panel is constructed.
I have found the examples at http://www.wicket-library.com/wicket-examples-1.4.x/ajax/ to be particularly useful (I'm using 1.4, but there are other examples for whichever version of wicket you are running you can get to from http://wicketstuff.org/).
I finally found the solution!!, It was a problem of the version of jQuery that I was using (1.4.2) so I just changed it to 1.5.2 and it worked!

Handling Asynchronous operations in Windows Phone7

I am developing a Windows Phone7 application in which I have two App bar buttons both when clicked makes Asynchronous calls to Web and Callbacks will be performed upon the Web response.
Now my problem is, if I click on one button and as the Async operation is going on in the background ans meanwhile if I click on another button both callbacks are executing one after the other, which is not good for obvious reasons. Could any one help me on how to handle this???
First I thought to disable other buttons when 1 Async operation is going. But it doesnt give good feel for user. So what will be the best way to handle this problem??
You can use a Flag variable and check its value within the async call complete method. Based on your requirement you can choose to update or not update the view.
I was looking for the same answer.
I have found the solution, If you initialize an object inside a constructor like this, you will get multiple loops when you call a service function:
public partial class MainPage : PhoneApplicationPage
{
MovieServiceClient mov;
public MainPage()
{
mov = new MovieServiceClient(); //Don't do this.
InitializeComponent();
}
}
Avoid that.

Observe event created through an instance of a Winforms UserControl

In my winforms app, I have a UserControl that contains a DataGridView. I instantiate and load this UserControl when needed into a panel in my Main Form (frmMain). My problem is figuring out how to resond to or listen for events raised in my UC's DataGridView. For example, I want to handle the CellDoubleClick event of the DataGridView in my Main Form rather than through the UC.
Is this possible? I had thought of updating a property when the cell in the grid is double-clicked, and then let my Main form do whatever when that property changes - therefore I thought of using INotifyPropertyChanged. Im not heavily clued up on how to use it in m scenario however, and would deeply appreciate some help in this regard, or if anyone can suggest an alternate solution.
Much thanx!
Your user control must encapsulate some logic, so if you want to handle event of the DataGridView that is in your control the way you've described, you probably missing something in idea of user controls and encapsulation. Technically here two ways to do this:
Make a public property in your user control of type DataGridView.
Make an event wrapper. You will need to create an event in your user control that is raised when DataGridView CellDoubleClick (or any) is rased and in your calling code you will handle this event wrapper.
The second approach is more logical, cos internal logic of your control is incapsulated and you can provide end-user of you component with more logical and meaningful event then CellDoubleClidk or else.
thank u 4 your reply. Sorry for not responding earlier. I did manage to sort this issue out by creating a public event in my UC:
public event DataGridViewCellEventHandler GridRowDoubleClick {
add { dgvTasks.CellDoubleClick += value; }
remove { dgvTasks.CellDoubleClick -= value; }
}
and in my main form, after I instantiate and load the UC
_ucTask.GridRowDoubleClick += new DataGridViewCellEventHandler(TasksGrid_CellDoubleClick);
with the following attached event:
private void TasksGrid_CellDoubleClick( object sender, DataGridViewCellEventArgs e ) {
// do work here!
}
This does work, although I don't know if any of u experts out there foresee a problem with this approach.

Resources