Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8670687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:46:01+00:00 2026-06-12T18:46:01+00:00

I have this code to show/hide Canvas with some text boxes, and when I

  • 0

I have this code to show/hide Canvas with some text boxes, and when I press a button it submits data from TextBox1 to database. The problem is that I don’t know how to access TextBox1 in C# code behind.

For example this is some of my XAML code:

<ContentControl  Background="{x:Null}" >
  <ContentControl.Template>
     <ControlTemplate>
      <StackPanel Grid.Row="3" Height="500" Name="stack1" Width="280">
        <Canvas x:Name="canvas1"  Height="400" >
              <TextBox Height="23" Name="TextBox1"  Width="70" />

    <Button Content="Submit" Name="submit_button" Click="submit_button_Click" />
        </Canvas>

  <ToggleButton x:Name="toggleshowhide" Content="Show/Hide" IsChecked="True" Height="50" />
      </StackPanel>
     <ControlTemplate.Triggers>
      <Trigger SourceName="toggleshowhide" Property="IsChecked" Value="True">
        <Setter TargetName="canvas1" Property="Visibility" Value="Visible" />
          </Trigger>
      <Trigger SourceName="toggleshowhide" Property="IsChecked" Value="False">
        <Setter TargetName="canvas1" Property="Visibility" Value="Hidden" />
          </Trigger>
    </ControlTemplate.Triggers>
      </ControlTemplate>
  </ContentControl.Template>
     <Button Content="Button" Height="23" Name="submit" Width="74" />
</ContentControl>

And this is what I’m trying to achieve:

private void submit_button_Click(object sender, RoutedEventArgs e)
{
      OleDbCommand cmd = new OleDbCommand("INSERT INTO Table VALUES (this.TextBox1.Text), con); 

      cmd.Connection = con;

         int temp = cmd.ExecuteNonQuery();

        if (temp > 0)
        {
            MessageBox.Show("OK", "Info !");
        }
        else
        {
            MessageBox.Show("Some text !", "Error");
        }

If anyone can help I`ll really appreciate it. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:46:02+00:00Added an answer on June 12, 2026 at 6:46 pm

    When accessing elements generated from a ControlTemplate, you need to use the FindName method of the Template. In this case, give your ContnetControl a name:

    <ContentControl  Background="{x:Null}" x:Name="MyContentControl">
    

    And in the code behind, you can access the value of any of the generated elements by name using the FindName method:

    TextBox tb = (TextBox)MyContentControl.Template.FindName( "TextBox1", MyContentControl);
    

    For more information, see: How to: Find ControlTemplate-Generated Elements

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code if (IsValid(textBox.Text)) { toolTip.Hide(textBox); } else { toolTip.Show(Please enter an
I have this code that Show/Hide a text box if I select a category
i have this static code that will hide/show some combo box but what if
i have this code in the button click to show selection image when the
i have this code from a tutorial: // Do the search and show the
I have this code to hide selected options: function connect() { $(.selectbox option).show(); $(.selectbox).each(function(i)
I have this code $(td).hover(function(){ $(this).find('a.btn').show(); }, function(){ $(this).find('a.btn').hide(); }) How can i convert
I have this code to show/hide (toggle) a div when clicking a link: $('#complete-services-link').toggle(
I have this HTML code: <p>Hello <span class=hide style=display:none>there</span> jquery</p> <button class=toggle>Toggle</button> <p>Hello <span
I have this sniplet of code in jQuery $element.parent().children().last().hide().show('slide', {direction : 'left'}, 700, function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.