Category Archives: General

Sharepoint web services + autocompleteextender

Oh boy that was fun.  I’m not even going to get into what I had to do and how long it took to get this working.  However, some code below will be helpful for those of you that want to try this yourselves (it’s not mine; I pulled it from the Smarttools source).  This solves the issue that Sharepoint has with Ajax postbacks/callbacks.

Also, you’re going to want to make sure that your “servicepath” attribute of the autocompleteextender is setup like this: “~/_vti_bin/nameofyourwebservice.asmx” or else you’ll get prompted to log in every time you call the service (which, incidentally, should be deployed to the ISAPI directory in your “12” hive).

If you need additional details, let me know.


ScriptManager sm = ScriptManager.GetCurrent(this.Page);

if (sm == null)
{
    //create new ScriptManager and EnablePartialRendering

    sm = new ScriptManager();
    sm.EnablePartialRendering = true;
    sm.EnableScriptLocalization = true;

    // Fix problem with postbacks and form actions (DevDiv 55525)
    Page.ClientScript.RegisterStartupScript(typeof(AgencyCodePicker),
    this.ID, "_spOriginalFormAction = document.forms[0].action;", true);

    //tag:"form" att:"onsubmit" val:"return _spFormOnSubmitWrapper()"
    //blocks async postbacks after the first one
    //not calling "_spFormOnSubmitWrapper()" breaks all postbacks
    //returning true all the time, somewhat defeats the purpose of
    //the _spFormOnSubmitWrapper() which is to block repetitive postbacks,
    //but it allows MS AJAX Extensions to work properly
    //its a hack that hopefully has minimal effect

    if (this.Page.Form != null)
    {
        string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
        if (!string.IsNullOrEmpty(formOnSubmitAtt)
        && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
        {
            this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
        }
        //add the ScriptManager as the first control in the Page.Form
        //I don't think this actually matters, but I did it to be consistent
        //with how you are supposed to place the ScriptManager when used declaritevly
        this.Controls.AddAt(0, sm);
    }
}

LINQ to XML subquery

I didn’t find a clear example online about how to do a subquery of an element, so I thought I would share.

First, here’s the XML I’m reading:


<response> 
    <name>Test</name> 
    <states> 
        <state>OH</state> 
        <state>MI</state> 
    </states> 
</response> 

I want to use LINQ to parse through the responses and create new objects for each one of them.  The object I created to hold the info is below:


 [Serializable()]
    public class User
    {
        public string userName { get; set; }a
        public List states { get; set; }

        public User(string UserName,List States)
        {
            userName = UserName;
            states = States;
        }
    }

I was at a loss at how to get the state elements into my “States” list. Here’s the query I ended up using:


var responses = from response in loginResult.Descendants("response")
      select new
      {
            authenticationToken = response.Element("authentication_token").Value,
            states = (from st in response.Descendants("states").Elements()
                         select st.Value).ToList(),

      };

It was obvious after I got it and I probably should have been able to figure it out quicker, but such as life when learning something new.

Prototypical First Blog Post

Hello all. This is your typical “first post” post. I hope to use this blog to convey my experiences in both my work and my life.

Switch to our mobile site