Solved

Saving values from User Control to database

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

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

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…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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