Solved

Saving values from User Control to database

Posted on 2012-03-21
1
266 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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