[RESOLVED] User control; different Error Message on Require Field Validator on different pages.

Hi,

I create an "Address" user control, with some textboxes; drop down lists, and requirefields.
The error message of the require field for the country textbox is like "Country is required"

I want to use this User control on customers page; suppliers page; and workers page. What I want is change the error message of the require field to an specific error message for each page.  Ex:

On customers page, error message must show "Country is required on customer form"
On suppliers page, error message must show "Country is required on supplier form"

Is it possible to do this? Thanks in advance.

You can expose a public property AddressErrorMessage on your user control and than set it in the mark up. For example:

User Control:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication12.WebUserControl1" %>

<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqAddress" ControlToValidate="txtAddress" ErrorMessage="Default error" runat="server"/>


Code Behind:

 public partial class WebUserControl1 : System.Web.UI.UserControl
    {
        public string AddressReqErrorMessage { get; set; }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            reqAddress.ErrorMessage = AddressReqErrorMessage ?? "This is default error message";
        }
    }

Web Form:

<uc1:WebUserControl1 runat="server" ID="WebUserControl1" AddressReqErrorMessage="Required on this page" />




YOu can change the error message from each page.

Like

RequireFieldValidator rq1  = (RequireFieldValidator)UC1.FindControl("rdv1").

rq1.ErrorMessage="test message";

above are sample code, not tested.

[RESOLVED] Make a combobox

Hi how do I make a combobox in c# using a web application?

the only ones i have seen are using webforms.

I wantr to populate a list that a user can make multiple selections from and then save back to db.

the list will be populated from the db as well.

Thanks

Hi,

Try using the following code which will really solve your issue i hope.

private void Form1_Load(object sender, EventArgs e)
        {

            SqlConnection conn = new SqlConnection(@"Data Source=TOM-PC\sqlexpress;Initial Catalog=Northwind;User ID=sa;Password=xyz") ;
            conn.Open();
                SqlCommand sc = new SqlCommand("select customerid,contactname from customers", conn);
                SqlDataReader reader;

                reader = sc.ExecuteReader();
                DataTable dt = new DataTable();             dt.Columns.Add("customerid", typeof(string));
             dt.Columns.Add("contactname", typeof(string));
                dt.Load(reader);

                comboBox1.ValueMember = "customerid";
                comboBox1.DisplayMember = "contactname";
                comboBox1.DataSource = dt;

                conn.Close();


        }

i already have lots of fields on my front page for the user to fill iin how does it get placed in the front page

Hi,

If you can give your code then it will make some sense, so that I will understand your issue clearly and help u out.

<div class="row">
                <div class="three columns">
                    <label class="right inline">
                        Service Area:
                    </label>
                </div>
                <div class="four columns end">
                    <asp:TextBox ID="TextBox1" runat="server">
                        <asp:>Combo box to go here !!!!!!!!!!!!!!!!!!!!!</asp:>
                    </asp:TextBox>
                </div>
            </div>
            <div class="row">
                <div class="three columns">
                    <label class="right inline">
                        Provider Contact Name:
                    </label>
                </div>
                <div class="four columns end">
                    <asp:TextBox ID="txt_ProviderContactName" runat="server"></asp:TextBox>
                </div>
            </div>

i thought you could probably make a listItem inside the textbox

Why not use a ListBox?

<asp:ListBox
          ID="lbClasses" runat="server"
          DataSourceID="myDataSource"
          DataTextField="CourseName"
          DataValueField="CourseID"
          CausesValidation="false"
          AppendDataBoundItems="false"
          SelectionMode="Multiple">
        </asp:ListBox>

[RESOLVED] pass a number from one page to another

i need to pass a number from databound gridview to another page into a textbox.

i have the navigate link below and a textbox on the other page.

<asp:HyperLinkFieldNavigateUrl="~/ProjectTasks.aspx" Text="i" />

ive tried request query string but i cannot seem to get it to work.

Use RowCommand Event for Gridview then redirect the other page as you wish with Query string/Session/Cache.

You can pass query string like given below :

<asp:HyperLink NavigateUrl="~/ProjectTasks.aspx?YourVariable=YourValue" Text="i" />

And access at another page's page load event :

int Number = int.Parse(Request.QueryString["YourVariable"].ToString());

Give it a try, let us know if have any query...

<ItemTemplate>
      <asp:HyperLink runat="server" Text="Link" NavigateUrl='<%# "http://ProjectTasks.aspx?myID=" + Eval("ObjectId")%>'></asp:HyperLink>
</ItemTemplate>

Bind id and text to hyperlink and access it on next page using query string.

int ID = int.Parse(Request.QueryString["myID"].ToString());


thanks for the replies. currently i have;

<asp: HyperLinkField DataNavigationUrlFields="JobNo"

DataNavigateUrlFormatString="ProjectDelivery.aspx?&quot;id={0}&quot;"

DataTextField="JobNo" HeaderText="JobNo" NavigateUrl="~/ProjectDelivery.aspx" />

and on the other pages page load

textbox1.text = request["JobNo"];

in the address bar it shows id="then the jobno clicked by me" but doesnt appear in the textbox what else do i need to do?!

 

instead of

textbox1.Text = request["JobNo"]

use

textbox1.Text = request["id"]

you can send data using querystring....

S.Maire

instead of

textbox1.Text = request["JobNo"]

use

textbox1.Text = request["id"]

thank you i just swapped but still the same shows in the address bar it has passed it over but does not show in the textbox

 

could you show how with the code above?

i am still learning i have tried querystring but could not get it to work

For your link

<asp: HyperLinkField DataNavigationUrlFields="JobNo"

DataNavigateUrlFormatString="ProjectDelivery.aspx?id={0}"

DataTextField="JobNo" HeaderText="JobNo" NavigateUrl="~/ProjectDelivery.aspx" />

and to retrieve

if(Request.QueryString["id"] != null)
  textbox1.Text = Request.QueryString["id"].ToString();

S.Maire

For your link

<asp: HyperLinkField DataNavigationUrlFields="JobNo"    DataNavigateUrlFormatString="ProjectDelivery.aspx?id={0}"    DataTextField="JobNo" HeaderText="JobNo" NavigateUrl="~/ProjectDelivery.aspx" />

and to retrieve

if(Request.QueryString["id"] != null)    textbox1.Text = Request.QueryString["id"].ToString();

 

great code, solved another problem i had but still does not show in the textbox :(

does Request.QueryString["id"].ToString() has correct value in code behind ?

can you show how you declare textbox1 in aspx and where you do textbox1.Text = ... ?

for the textbox i just have

<asp:TextBox ID="TextBox1" runat = "server" ontextchanged="TextBox1_textChanged"></asp:TextBox>

and to call the id i have placed in the page load

int id = int.Parse(Request.QueryString["yourid"].ToString());

or

Session["number"]=TextBox.text;
Next Page
Label1.Text=Session["number"].ToString();


Both Way to pass the Value.

that's weird...

check Request.QueryString["id"].ToString() value in debug mode

the value in the address bar? it returns projecttasks.aspx?"id=5555" or whatever i choose.

 can not get anything to show in the textbox though

 

projecttasks.aspx?"id=5555"

You should not have " around id=5555

Try with :

projecttasks.aspx?id=5555

i believe that will work when the quotes are taken out.

why would it be putting them there have i placed them somewhere i shouldnt have?

thank you for all your replies!!!

Yes, you have placed them there :

<asp: HyperLinkField DataNavigationUrlFields="JobNo"

DataNavigateUrlFormatString="ProjectDelivery.aspx?&quot;id={0}&quot;"

DataTextField="JobNo" HeaderText="JobNo" NavigateUrl="~/ProjectDelivery.aspx" />

Remove &quot; , and everything will be ok.

THANK YOU SO MUCH S.Maire!!!!!! problem solved!

In such situation I always use Global.asx...

there in a class declare variable you want to use..like below

public class A
    {
        public static int z;

    }

and use A.z to store value ...A.z=1 etc.,

then use A.z in wherever place u require..

I hope this works for u too,

[RESOLVED] Image storing in Database

Hi

      I want to store image in database.So i wrote stored procedure for storing information with image in DB.

i going to pass the image parmeter to DB using 3-Tier Architecture.How can i pass it.

my code is here.

byte[] theImage = new byte[FileUpload1.PostedFile.ContentLength];
        HttpPostedFile Image = FileUpload1.PostedFile;
        Image.InputStream.Read(theImage, 0, (int)FileUpload1.PostedFile.ContentLength);
        int length = theImage.Length; //Get the length of the image
        string fileName = FileUpload1.FileName.ToString(); //Get the file name of the posted image
        string type = FileUpload1.PostedFile.ContentType; //Get the type of the posted image
        int size = FileUpload1.PostedFile.ContentLength; //Get the size in bytes that

        ParameterName[0] = "@PropertyName"; Values[0] = Txt_propName.Text;
        ParameterName[1] = "PropertyDescription"; Values[1] = Txt_PropDesc.Text;
        ParameterName[2] = "@PropImage"; Values[2] = theImage;<--------------------------------<---Here is the problem
        ParameterName[2] = "@Price";Values[2]=Txt_Price.Text;

What is "Values"?

Hi Dinesh,

Try the following link which clearly explained about the storing and retriving image from sql server. I used it and it works fine for me.

http://www.codeproject.com/Articles/354639/Storing-and-Retrieving-Images-from-SQL-Server-Usin

http://www.codeproject.com/Articles/21208/Store-or-Save-images-in-SQL-Server

http://www.sqlhub.com/2009/03/image-store-in-sql-server-2005-database.html

I used above method to store and retrieve images,, hope it works for u too.

[RESOLVED] dataset not working

my page isn't taking Dataset, datatable , why ? it isn't a big deal to create dataset or datatable, i have done it several times but why this time ?

here is the code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Drawing;


public partial class viewCommittess : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=COSANOSTRA; MultipleActiveResultSets=true; Initial Catalog=Waleed_orsfinal;Integrated Security=True");
    int userid;
    protected void Page_Load(object sender, EventArgs e)
    {
        lblDate.Text = System.DateTime.Now.ToLongDateString();
        lblusernamepic.Text = (String)Session["EmployeeName"];
        imageload();
        if (!Page.IsPostBack)
        {
            BindCommitee();
            //BindCommiteesSearch();
        }
    }
    protected void imageload()
    {
        String connectionString = "Data Source=COSANOSTRA; MultipleActiveResultSets=true; Initial Catalog=Waleed_orsfinal;Integrated Security=True";
        SqlConnection con = new SqlConnection(connectionString);
        string sqlQuery = "select  photo from tblPersonalInfo where userid = '" + Session["EmployeeUserid"] + "'";
        SqlCommand com1 = new SqlCommand(sqlQuery, con);
        SqlDataAdapter da = new SqlDataAdapter(com1);
        DataTable dt = new DataTable();
        try
        {
            con.Open();
            da.Fill(dt);
        }
        catch (Exception ex)
        {
            Response.Write("Error:" + ex.Message);
        }
        finally
        {
            con.Close();
        }

        datalistphoto.DataSource = dt;
        datalistphoto.DataBind();
    }

    protected void BindCommitee()
    {
        userid = Convert.ToInt32(Session["EmployeeUserid"]);

        SqlCommand cmd = new SqlCommand("select teamid,name,commiteerole,userid from tblScruitnyteam where userid=" + userid, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
 DataSet ds = new DataSet();
        try
        {
            con.Open();
            da.Fill(ds);

            if (ds.Tables[0].Rows.Count > 0)
            {
                gvCommitees.DataSource = ds;
                gvCommitees.DataBind();
            }
            else
            {
                ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
                gvCommitees.DataSource = ds;
                gvCommitees.DataBind();
                int columncount = gvCommitees.Rows[0].Cells.Count;
                gvCommitees.Rows[0].Cells.Clear();
                gvCommitees.Rows[0].Cells.Add(new TableCell());
                gvCommitees.Rows[0].Cells[0].ColumnSpan = columncount;
                gvCommitees.Rows[0].Cells[0].Text = "No Records Found";
            }
        }
        catch (Exception exc)
        {
            Response.Write("Error:" + exc.Message);
        }
        finally
        {
            con.Close();
        }
    }



check bolded parts 

Hi

Wat msg ur getting .. i think BindCommitee() method is correct may be if ur not getting Dataset or DataTable in ur Editor (Visual studio) Namesapace using System.Data; is missing it seems .. Add namespace and try

Hi,

If you can give the exact error occuring in runtime, then it is easy to help you to sort out this issue.

hi

Pls use Namespace Using System.Data;

If you are geting exception on catch block then these two lines will not execute. Please past this lines in try block then check , these lines works for you or not.

datalistphoto.DataSource = dt;
datalistphoto.DataBind();

Add the namespace System.Data;

Then try it.