Solved

Saving values from User Control to database

Posted on 2012-03-21
1
271 Views
Last Modified: 2012-03-21
I have a user control that has two textboxes

<tr>
<td align="right" >Select Question Color:</td>
<td ><asp:TextBox ID="txtquestioncolor" class="color" value="ffffff" runat="server" /></td>
</tr>
<tr >
<td align="right">Select Font Color:</td>
<td ><asp:TextBox ID="txtfontcolor" class="color"  value="66ff00" runat="server"  /></td>
</tr>

The page that uses this control has a reference to the usercontrol:

<%@ Register src="~/UserControls/ColorPicker_03.ascx" tagname="ColorPicker_03" tagprefix="uc1" %>

and is called here:

<uc1:ColorPicker_03 ID="colorpicker1" runat="server" />


The user will  see a page where, among other things, are able to select two colors.  I need to save the colors selected to my database.

I have a Save function in the code behind like so that is saving to a class

            Question.Question = txtQuestion.Text
            Question.ShortDesc = txtShrtDesc.Text.Trim()
            Question.PrintDesc = txtPrintDesc.Text.Trim()
            Question.QuestionColor = txtquestioncolor.Text
            Question.FontColor = txtfontcolor.Text


Before I put the color text boxes into a user control, I was able to save the values of txtquestioncolor and txtfontcolor.  Now those two text boxes are empty.

My question is how do I read the values from the two text boxes on the user control?
0
Comment
Question by:sherbug1015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 500 total points
ID: 37748371
on the user control code-behind page create two property like

public string GetQuestionColor
{
   get { return txtQuestionColor.Text;}
}
public string GetFontColor
{
   get { return txtFontColor.Text;}
}


Now,on the code-behind of the Page where you have used this User Control, you can access this control property by the code like
 
string questionColor = ControlName1. GetQuestionColor;
string fontColor =  ControlName1. GetFontColor;

Hope, you understand the concept,and this will help you to fix your problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question