Search code examples
c#javascriptasp.netajaxcontroltoolkit

update flag value with hiddenfield value in static method


Javascript

function btnNewPatientClick()
        {
            hidFlag.value = "false";}
function btnExistingPatient_Click()
        {
            hidFlag.value = "true";}  

ASPX..

    <asp:TextBox ID="txtPatientID" AutoCompleteType="Disabled" CssClass="csstextbox"
                                    runat="server"></asp:TextBox><span class="csstexterror">*</span>
                                <asp:AutoCompleteExtender ID="txtPatientID_AutoCompleteExtender" runat="server" ServiceMethod="GetPatientID"
                                    MinimumPrefixLength="1" CompletionSetCount="1" TargetControlID="txtPatientID"
                                    UseContextKey="True" DelimiterCharacters="" Enabled="True">
                                </asp:AutoCompleteExtender>

C#

 static string flag = "";
 protected void Page_Load(object sender, EventArgs e)
 {
    flag = hidFlag.Value;
 }

 [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
 public static string[] GetPatientID(string prefixText, int count, string contextKey)
 {
     if(flag == "true"){
        ///code to get patientID
     }
 }

I have two buttons NEW Patinet,Existing Patinet and one textbox For selection of Patinet name Used autocompleteExtender of ajax toolkit. If i click on new student button then i dont allow to populate students in textbox and if click on Existing student then allow to populate students in textbox.I have set flag but fails what is the solution.


Solution

  • Follow these steps:

    1)Take button in update panel.

    <asp:UpdatePanel ID="updatePanel" runat="server">
            <ContentTemplate>
                <asp:Button ID="btnUpdatePanel" runat="server" OnClick="btnUpdatePanel_Click" Style="display: none;" />
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnUpdatePanel" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
    

    2)call update panel button click from javascript.

    function btnNewPatientClick()
            {hidFlag.value = "false";
                btnUpdatePanel.click();
    //rest of ur code...}
    

    3)on server side button click change flag value with hiddenFiled value.

    protected void btnUpdatePanel_Click(object sender, EventArgs e)
        {
            flag = hidFlag.Value;
        }
    

    It should work tested...