Solved

Saving values from User Control to database

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now