Using C# to disable controls - InfoPath Dev
in

InfoPath Dev

Using C# to disable controls

Last post 07-02-2008 03:56 AM by Sober. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 05-15-2006 10:29 AM

    Using C# to disable controls

    Hi

    I am trying to disable the textbox control when the button is clicked. I use the following code to select the textbox node.

    IXMLDOMNode field1=thisXDocument.DOM.selectSingleNode("//my:field1");

    How can I disable the textbox...field1.disabled=true...that doesnt work. Only thing I can do is change the text of the textbox? How can I change the color, or disable the textbox just like you can do it in a visual studio windows application?
  • 05-15-2006 11:33 AM In reply to

    Re: Using C# to disable controls

    Hello hapinder and welcome to the forum!

    Unfortunately you will not be able to use quite the same object model as you did while working in Visual Studio Windows Applications. An IXMLDOMNode object has absolutely no formatting of display attributes, this is because XML is strictly data. The seperation of data and design is a key component of why XML is so cool. Anyway, I'm rambling.

    To disable, change color, or apply other formatting instructions to a control on your view you will have to use conditional formatting. To do this, double-click the control, click the Display tab, and then click the Conditional Formatting button. From here you can add rules to change the way your control is viewed. To be able to disable the node by code you will have to follow this process:

    1. Create a node (preferably in a secondary data source), and name is "field1Enabled".
    2. Add conditional formatting on the field1 control that says to disable the control whenever the "field1Enabled" node is set to FALSE.
    3. In your code, set the "field1Enabled" node to true or false corresponding with whether or not you want to enable or disable the control.
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 05-15-2006 12:57 PM In reply to

    Re: Using C# to disable controls

    You can also use "xdExtension:method()" in the conditional formatting.

    Where "method()" is a function in the code and in this case it returns true/false.
  • 05-16-2006 01:52 AM In reply to

    Re: Using C# to disable controls

    Hi Hapinder,

    Just check out the following link that describes clearly the solution given by Agni.

    http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=223&SearchTerms=Is,it,possible,to,Hide/Disable,a,control,through,scripting(jscript),in,infopath?

    Regards,
    Abhishek
  • 05-16-2006 09:26 PM In reply to

    Re: Using C# to disable controls

    everybody has been great help. Thanks a lot :)
  • 07-01-2008 03:31 AM In reply to

    • Sober
    • Not Ranked
      Male
    • Joined on 12-24-2007
    • Turkey
    • Posts 5

    Re: Using C# to disable controls

    Hi there all,

    Here is the problem i have faced with.

    I have a dropdown listbox with two selections. As products and customers.

    And i have a customer text box(which is cannot be blank). When user selects products selection from drop down list box, i can hide customer text field. And if customers is selected you can fill the customer textbox, till now it works but if i click to submit button(with products selected) it says please fill the areas with red asterix. So i tried to make a way out and hope to disable the TEXTBOX CONTROL. as i see even using a secondary date source or by code it is not allowed by infopath. I tried to put this control inside the section control but section control also does not have disable control option. only control i see that can be disabled is dropdown list box and list box.

    So is there a way to DISABLE the textbox control in infopath i mean DISABLE not HIDE. (I use infopath 2007 with C# Language)

    Regards.

  • 07-02-2008 12:58 AM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: Using C# to disable controls

    Hi,

    You can remove the required symbol from text box when that text box is hiding.I think you have selected “Cannot be blank” check box in the text box properties. Please uncheck that and add the following data validation for text box.“Dropdownfield” is equal to “products” and “customer text field” is blank. In this you can submit the form with out showing validation when “customer text field” is hide. For your another question is about disable text box: You can disable the text box using “Read only” option in the conditional formatting.

     

    Anuma Chinthapalli /
    http://www.GGKTech.com
  • 07-02-2008 03:56 AM In reply to

    • Sober
    • Not Ranked
      Male
    • Joined on 12-24-2007
    • Turkey
    • Posts 5

    Re: Using C# to disable controls

     Thanks Anuma, i have already solved the problem yesterday and as i see, i did the same thing as you told me to do.

    Ohh also i want to share something with you, i prepared a form for the company i worked and in that form there are 3 dropdownlists and also much more controls but the interesting thing is  i filled the dropdownlist items manually. (nearly 5-12 items each hold) than i preview the dropdowncontrols and whenever i made a choose in dropdowns it didnt choose the items with lower letters (You can select IT but not Sales) but when you change the Sales to SALES it operates as wanted. There is no condition i selected for the controls. It was interesting but i cant understand the problem so all the items are in capital letters in dropdownlists :) but it works :)  

    Thanks again for reply...
    Regards.

     

Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.