Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Saving values from User Control to database

Posted on 2012-03-21
1
Medium Priority
?
274 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
1 Comment
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

926 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