Search code examples
c#asp.netwebformsuser-controlswebmethod

How to send a parameter to service method of c# user control?


I am using following code in my HTML.

<uc1:BaseIntelliSenseControl ID="SmartPhrasesIntellisence" runat="server" 
                        ContextKey="0" ServiceMethod="GetSmartPhrases_Intellisence" ServicePath="~/patient/clinical/case/soap/smartphrases/lstSmartPhrases.aspx" 
                        Width="100%" OnClientItemSelected="selected_Item"  OnClientPopulated="clientPopulated" hint="Search Smart Phrases ..." />

I want to send a parameter which I have set in jquery ready function like this

$("#hdnCurrentlySelectedCategory").val($(this).val());

Service method is as follows

[WebMethod(EnableSession = true)]
public static string[] GetSmartPhrases_Intellisence(string prefixText, int count, string contextKey)
{

}

Is there any way I can pass another parameter or send set Context Key through jquery/javascript method?

I tried to do the following in jquery ready function

        var listObject = $find('autocompleteEx1');
        listObject.set_contextKey("Value");

But it did not work. Any help will be most appreciated.


Solution

  • I have just discovered the solution to my problem. Here is the following code I did to update context key through jquery.

            var listObject = $find('<%=SmartPhrasesIntellisence.ControlID %>');
            listObject.set_contextKey("Value");
    

    Here "SmartPhrasesIntellisence" is the id of user control that I set. It first finds it and use set_contextKey method. Previously I was using wrong id due to which I was facing problems.

    Happy Coding!