C# .NET - Ambiguity Error in label and textfield

Asked By jennifer
05-Jul-11 11:54 PM

how can i solve my error when there is Ambiguity Error in all my labels and textfields??


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.Configuration;

public partial class student_fbnewmsg : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Button Button1;

protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;

protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;

protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;

protected System.Web.UI.HtmlControls.HtmlForm Form1;

private int commentid = 1;

protected System.Web.UI.WebControls.Label lbl_status;

protected System.Web.UI.WebControls.Button Button2;

protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator4;

protected System.Web.UI.WebControls.TextBox txt_name;

protected System.Web.UI.WebControls.TextBox txt_email;

protected System.Web.UI.WebControls.TextBox txt_reply;

protected System.Web.UI.WebControls.TextBox txt_title;

protected System.Web.UI.HtmlControls.HtmlInputRadioButton br_feedback;

protected System.Web.UI.HtmlControls.HtmlInputRadioButton br_suggetion;

protected System.Web.UI.HtmlControls.HtmlInputRadioButton br_general;

 

private int articleid = 1;

protected void Page_Load(object sender, EventArgs e)

{

if (Request.QueryString["id"] != null)

articleid = Convert.ToInt32(Request.QueryString["id"]);

if (Request.QueryString["Test"] != null)

{

if (String.Compare(Request.QueryString["Test"].ToLower(), "true") == 0)

{

int mParentId = 0;

int mArticleId = articleid;

string mTitle = "Test Message - This Forum Rocks";

string mUserName = "quartz";

string mUserEmail = "quartz@msn.com";

string mDescription = "Original Message - Test Description";

int mIndent = 0;

try

{

SqlConnection myC = new SqlConnection("Data Source=EN12-2-24-WS07\\SQLEXPRESS; Initial Catalog=SchWeb; Integrated Security=SSPI");

string sqlQuery = "INSERT into tb_feedback (parentID,articleID,title,student_id,useremail,description,indent) VALUES ('" + mParentId + "','" + mArticleId + "','" + mTitle + "','" + mUserName + "','" + mUserEmail + "','" + mDescription + "','" + mIndent + "')";

myC.Open();

SqlCommand myCommand = new SqlCommand();

myCommand.CommandText = sqlQuery;

myCommand.Connection = myC;

int i = myCommand.ExecuteNonQuery();

myC.Close();

//lblStatus.ForeColor = Color.Green;

lbl_status.Text = "Status: Success";

Response.Redirect("Forum.aspx?id=" + articleid);

}

catch (Exception)

{

//lblStatus.ForeColor = Color.Red;

lbl_status.Text = "Status: Error";

}

}

}

}

protected void btn_comment_Click1(object sender, EventArgs e)

{

int mParentId = 0;

int mArticleId = articleid;

string mTitle = "Test";

string mUserName = "quartz";

string mUserEmail = "quartz@msn.com";

string mDescription = "Test Description";

int mIndent = 0;

try

{

mTitle = txt_title.Text;

mUserName = txt_name.Text;

mUserEmail = txt_email.Text;

mDescription = txt_reply.Text;

 

int mCommentType = 1;

if (br_feedback.Checked)

mCommentType = 2;

//if (MsgType_3.Checked)

// mCommentType = 3;

if (br_suggetion.Checked)

mCommentType = 4;

if (br_general.Checked)

mCommentType = 5;

 

if (IsValid)

{

SqlConnection myC = new SqlConnection("Data Source=EN12-2-24-WS07\\SQLEXPRESS; Initial Catalog=SchWeb; Integrated Security=SSPI");

 

string sqlQuery = "INSERT into tb_feedback (parentID,articleID,title,student_id,useremail,description,indent,comment_type) VALUES ('" + mParentId + "','" + mArticleId + "','" + mTitle + "','" + mUserName + "','" + mUserEmail + "','" + mDescription + "','" + mIndent + "','" + mCommentType + "')";

myC.Open();

SqlCommand myCommand = new SqlCommand();

myCommand.CommandText = sqlQuery;

myCommand.Connection = myC;

int i = myCommand.ExecuteNonQuery();

myC.Close();

//lblStatus.ForeColor = Color.Green;

lbl_status.Text = "Status: Success";

Response.Redirect("Forum.aspx?id=" + articleid);

}

}

catch (Exception)

{

// lblStatus.ForeColor = Color.Red;

lbl_status.Text = "Status: Error";

}

}

}

  James H replied to jennifer
06-Jul-11 12:01 AM
Can you please mark where you are getting error ?
  jennifer replied to James H
06-Jul-11 12:05 AM

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.Configuration;

public partial class student_fbnewmsg : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Button Button1;

protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;

protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;

protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;

protected System.Web.UI.HtmlControls.HtmlForm Form1;

private int commentid = 1;

protected System.Web.UI.WebControls.Label lbl_status;

protected System.Web.UI.WebControls.Button Button2;

protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator4;

protected System.Web.UI.WebControls.TextBox txt_name;

protected System.Web.UI.WebControls.TextBox txt_email;

protected System.Web.UI.WebControls.TextBox txt_reply;

protected System.Web.UI.WebControls.TextBox txt_title;

protected System.Web.UI.HtmlControls.HtmlInputRadioButton br_feedback;

protected System.Web.UI.HtmlControls.HtmlInputRadioButton br_suggetion;

protected System.Web.UI.HtmlControls.HtmlInputRadioButton br_general;

 

private int articleid = 1;

protected void Page_Load(object sender, EventArgs e)

{

if (Request.QueryString["id"] != null)

articleid = Convert.ToInt32(Request.QueryString["id"]);

if (Request.QueryString["Test"] != null)

{

if (String.Compare(Request.QueryString["Test"].ToLower(), "true") == 0)

{

int mParentId = 0;

int mArticleId = articleid;

string mTitle = "Test Message - This Forum Rocks";

string mUserName = "quartz";

string mUserEmail = "quartz@msn.com";

string mDescription = "Original Message - Test Description";

int mIndent = 0;

try

{

SqlConnection myC = new SqlConnection("Data Source=EN12-2-24-WS07\\SQLEXPRESS; Initial Catalog=SchWeb; Integrated Security=SSPI");

string sqlQuery = "INSERT into tb_feedback (parentID,articleID,title,student_id,useremail,description,indent) VALUES ('" + mParentId + "','" + mArticleId + "','" + mTitle + "','" + mUserName + "','" + mUserEmail + "','" + mDescription + "','" + mIndent + "')";

myC.Open();

SqlCommand myCommand = new SqlCommand();

myCommand.CommandText = sqlQuery;

myCommand.Connection = myC;

int i = myCommand.ExecuteNonQuery();

myC.Close();

//lblStatus.ForeColor = Color.Green;

lbl_status.Text = "Status: Success";

Response.Redirect("Forum.aspx?id=" + articleid);

}

catch (Exception)

{

//lblStatus.ForeColor = Color.Red;

lbl_status.Text = "Status: Error";

}

}

}

}

protected void btn_comment_Click1(object sender, EventArgs e)

{

int mParentId = 0;

int mArticleId = articleid;

string mTitle = "Test";

string mUserName = "quartz";

string mUserEmail = "quartz@msn.com";

string mDescription = "Test Description";

int mIndent = 0;

try

{

mTitle = txt_title.Text;

mUserName = txt_name.Text;

mUserEmail = txt_email.Text;

mDescription = txt_reply.Text;

 

int mCommentType = 1;

if (br_feedback.Checked)

mCommentType = 2;

//if (MsgType_3.Checked)

// mCommentType = 3;

if (br_suggetion.Checked)

mCommentType = 4;

if (br_general.Checked)

mCommentType = 5;

 

if (IsValid)

{

SqlConnection myC = new SqlConnection("Data Source=EN12-2-24-WS07\\SQLEXPRESS; Initial Catalog=SchWeb; Integrated Security=SSPI");

 

string sqlQuery = "INSERT into tb_feedback (parentID,articleID,title,student_id,useremail,description,indent,comment_type) VALUES ('" + mParentId + "','" + mArticleId + "','" + mTitle + "','" + mUserName + "','" + mUserEmail + "','" + mDescription + "','" + mIndent + "','" + mCommentType + "')";

myC.Open();

SqlCommand myCommand = new SqlCommand();

myCommand.CommandText = sqlQuery;

myCommand.Connection = myC;

int i = myCommand.ExecuteNonQuery();

myC.Close();

//lblStatus.ForeColor = Color.Green;

lbl_status.Text = "Status: Success";

Response.Redirect("Forum.aspx?id=" + articleid);

}

}

catch (Exception)

{

// lblStatus.ForeColor = Color.Red;

lbl_status.Text = "Status: Error";

}

}

}

  James H replied to jennifer
06-Jul-11 12:10 AM
Hi please do like this for All labels and TextFields.Create Instance like this 
lbl_Status=new Label();
lbl_Status.Text="Hi";
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.Configuration;
 
public partial class student_fbnewmsg : System.Web.UI.Page
 
{
 
protected System.Web.UI.WebControls.Button Button1;
 
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
 
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
 
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
 
protected System.Web.UI.HtmlControls.HtmlForm Form1;
 
private int commentid = 1;
 
protected System.Web.UI.WebControls.Label lbl_status;
 
protected System.Web.UI.WebControls.Button Button2;
 
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator4;
 
protected System.Web.UI.WebControls.TextBox txt_name;
 
protected System.Web.UI.WebControls.TextBox txt_email;
 
protected System.Web.UI.WebControls.TextBox txt_reply;
 
protected System.Web.UI.WebControls.TextBox txt_title;
 
protected System.Web.UI.HtmlControls.HtmlInputRadioButton br_feedback;
 
protected System.Web.UI.HtmlControls.HtmlInputRadioButton br_suggetion;
 
protected System.Web.UI.HtmlControls.HtmlInputRadioButton br_general;
 
  
 
private int articleid = 1;
 
protected void Page_Load(object sender, EventArgs e)
 
{
 
if (Request.QueryString["id"] != null)
 
articleid = Convert.ToInt32(Request.QueryString["id"]);
 
if (Request.QueryString["Test"] != null)
 
{
 
if (String.Compare(Request.QueryString["Test"].ToLower(), "true") == 0)
 
{
 
int mParentId = 0;
 
int mArticleId = articleid;
 
string mTitle = "Test Message - This Forum Rocks";
 
string mUserName = "quartz";
 
string mUserEmail = "quartz@msn.com";
 
string mDescription = "Original Message - Test Description";
 
int mIndent = 0;
 
try
 
{
 
SqlConnection myC = new SqlConnection("Data Source=EN12-2-24-WS07\\SQLEXPRESS; Initial Catalog=SchWeb; Integrated Security=SSPI");
 
string sqlQuery = "INSERT into tb_feedback (parentID,articleID,title,student_id,useremail,description,indent) VALUES ('" + mParentId + "','" + mArticleId + "','" + mTitle + "','" + mUserName + "','" + mUserEmail + "','" + mDescription + "','" + mIndent + "')";
 
myC.Open();
 
SqlCommand myCommand = new SqlCommand();
 
myCommand.CommandText = sqlQuery;
 
myCommand.Connection = myC;
 
int i = myCommand.ExecuteNonQuery();
 
myC.Close();
 
//lblStatus.ForeColor = Color.Green;
 
lbl_status.Text = "Status: Success";
 
Response.Redirect("Forum.aspx?id=" + articleid);
 
}
 
catch (Exception)
 
{
 
//lblStatus.ForeColor = Color.Red;
 
lbl_status=new Label();
lbl_status.Text = "Status: Error";
 
}
 
}
 
}
 
}
 
protected void btn_comment_Click1(object sender, EventArgs e)
 
{
 
int mParentId = 0;
 
int mArticleId = articleid;
 
string mTitle = "Test";
 
string mUserName = "quartz";
 
string mUserEmail = "quartz@msn.com";
 
string mDescription = "Test Description";
 
int mIndent = 0;
 
try
 
{
 
mTitle = txt_title.Text;
 
mUserName = txt_name.Text;
 
mUserEmail = txt_email.Text;
 
mDescription = txt_reply.Text;
 
  
 
int mCommentType = 1;
 
if (br_feedback.Checked)
 
mCommentType = 2;
 
//if (MsgType_3.Checked)
 
// mCommentType = 3;
 
if (br_suggetion.Checked)
 
mCommentType = 4;
 
if (br_general.Checked)
 
mCommentType = 5;
 
 
 
if (IsValid)
 
{
 
SqlConnection myC = new SqlConnection("Data Source=EN12-2-24-WS07\\SQLEXPRESS; Initial Catalog=SchWeb; Integrated Security=SSPI");
 
 
 
string sqlQuery = "INSERT into tb_feedback (parentID,articleID,title,student_id,useremail,description,indent,comment_type) VALUES ('" + mParentId + "','" + mArticleId + "','" + mTitle + "','" + mUserName + "','" + mUserEmail + "','" + mDescription + "','" + mIndent + "','" + mCommentType + "')";
 
myC.Open();
 
SqlCommand myCommand = new SqlCommand();
 
myCommand.CommandText = sqlQuery;
 
myCommand.Connection = myC;
 
int i = myCommand.ExecuteNonQuery();
 
myC.Close();
 
//lblStatus.ForeColor = Color.Green;
 
lbl_status.Text = "Status: Success";
 
Response.Redirect("Forum.aspx?id=" + articleid);
 
}
 
}
 
catch (Exception)
 
{
 
// lblStatus.ForeColor = Color.Red;
 
lbl_status.Text = "Status: Error";
 
}
 
}
 
}

  [ Kirtan ] replied to jennifer
06-Jul-11 12:14 AM
it seems you are creating labels etc dynamically and you have not provided ID attribute to all of them thats why ambiguity is there .

provide ID attribute to Elements you creating dynamically 

protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;

protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;

protected void Page_Load(object sender, EventArgs e)

{

   RequiredFieldValidator3.ID = "rfv1";

}


Thanks

  James H replied to jennifer
06-Jul-11 12:16 AM
Hi you have created the Labels,TextBoxes and requiredFieldValidators .But you need to create instance also.Please do it then you wont get any error.
  Web Star replied to jennifer
06-Jul-11 12:17 AM
Ambiguity error comes due to same id of different control So make sure when you creating label or any other control at runtime you should provide unique and valid id of that control at the time of creation.
  jennifer replied to James H
06-Jul-11 12:25 AM
it does not work when i try to add new label to it
  jennifer replied to [ Kirtan ]
06-Jul-11 12:27 AM
it does not work RequiredFieldValidator3.ID = "rfv1"; the yellow part got error
  dipa ahuja replied to jennifer
06-Jul-11 04:39 AM
Hi...

you already have added the namespace so there is no need to declared the label with its whole namespace you can declare it just by refering the label..

Also you have declared the label, but you have not initialized it , before using the label you have to initialize ti.. so do the initialization:

//declaration
protected Label lbl_status;
//initialization
lbl_status = new Label();
//set
lbl_status.Text = "success";
Create New Account
help
working on remote site I have the config below in my web.config <customErrors defaultRedirect = "error / error.aspx" mode = "On"> <error statusCode = "500" redirect = "error / error.aspx" / > <error statusCode = "404" redirect = "error / error.aspx" / > < / customErrors> I have changed the mode to RemoteOnly with no success Initially i didn
complete, as it keeps stopping. The only clue in the event log is a 5014 error - The DFS Replication service is stopping communication with partner <server> due to an error. The error in question is 1722 (The RPC Server is unavailable). If I restart the DFS service 4CA5-93D3-9923AC11D640} csName:Production updateType:remote 20081001 08:32:57.251 2748 DOWN 5186 [ERROR] DownstreamTransport::RdcGet Failed on connId:{F33E154B-B106-4CA5-93D3-9923AC11D640} csId:{81BF2885-1DE4-4F26-8E2B 00000000-00000000-00000000 + similarity 00000000-00000000-00000000-00000000 + name {066AED9B-313E-4D28-A0C6-4A144863E7C5}-v1075 + Error: + [Error:9027(0x2343) RpcFinalizeContext downstreamtransport.cpp:1096 2748 C A failure was reported by the remote partner] + [Error:9027(0x2343) DownstreamTransport::RdcGet downstreamtransport.cpp:5124 2748 C A failure was reported by the remote partner] + [Error:170(0xaa) DownstreamTransport::RdcGet downstreamtransport.cpp:5124 2748 W The requested resource is in use
Reserved error (Error 3000) DataBase Does anyone know what is causing this error? Reserved error <Item> ; there is no message for this error. (Error 3000) An unexpected error occurred. The specified code identifies the conditions under which this error can occur. Please contact Microsoft Product Support Services for more information. Here's SQL: INSERT
Mapping .NET Framework Hello, I am mapping a class Error to another class YError: YError ToY(Error error) { return new YError { Id = error.ErrorId, CreatedAt = error.CreatedAt, Description = error.Description, HttpCode = error.HttpCode, }; } / / ToY Now I am trying a new version that does the mapping for many errors: IQueryable<YError> ToY(IQueryable<Error> error) { return error.Select(e = > e = <YError> ToY(error)).AsQueryable(); } / / ToY But I get the