Click here to Skip to main content
14,767,619 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MainUserControl1.Name = "";//this from ascx page
string Title;//this from aspx
 SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());

        con.Open();
        SqlCommand cmd = new SqlCommand();

        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_InsertPatientAddmission";

        SqlParameter paraTitle = new SqlParameter("@Title", SqlDbType.VarChar, 50);
        paraTitle.Value = Title;
        cmd.Parameters.Add(paraTitle);//this from aspx

        SqlParameter paraName = new SqlParameter("@Name", SqlDbType.VarChar, 50);
        paraName.Value = MainUserControl1.Name;
        cmd.Parameters.Add(paraName);//is in correct format??//this from ascx page..

hi here is my code.i want to add this values to database but title is adding and Name field is not adding to database.(name field m calling to ascx to aspx page)..can anyone solve,..
Posted
Updated 10-Jan-12 18:47pm
v4

To access form field that is defined in user control, you need to define a property on that user control.
Eg.

UserControl.ascx
<asp:textbox id="NameTB" runat="server" />



in UserControl.ascx.cs:

public string Name
{
   get { return NameTB.Text; }
}
   
v2
Comments
fjdiewornncalwe 10-Jan-12 13:11pm
   
+5. Absolutely.
Elina Blank 10-Jan-12 13:20pm
   
thanks :)
ythisbug 10-Jan-12 23:44pm
   
hi elina so no need of giving set in ascx.cs page??and wat should i write in aspx.cs file..how to call that field from ascx to aspx.cs file
ythisbug 10-Jan-12 23:49pm
   
public string Name
{
get { return NameTB.Value; }
}

this code is not working..Value is coming..
Elina Blank 11-Jan-12 9:36am
   
It is Text, not Value. And you can have set, but do not have to.
aspx.cs
SqlParameter paraName = new SqlParameter("@Name", SqlDbType.VarChar, 50);
paraName.Value = MainUserControl1.Name;
cmd.Parameters.Add(paraName);

in ascx.cs
public string Name
   {
       get
       {
           return txtFname.Text;
       }
       set
       {
           txtFname.Text = value;

       }

   }


this s the code to save values in database,
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900