PDA

View Full Version : FindControl chekbox



ERIKA
چهارشنبه 23 فروردین 1391, 01:35 صبح
سلام
من میخاستم همچین کاری انجام بدم براش یک کدی نوشتم جواب نگرفتم
اين کلا به اين صورت که من يک خبر دارم که شامل يک سري گروه خبري هست ميخام به يوزر ها دسترسي به اين گروه خبري بدم و بعد وقتی میخاد خبر ها را ثبت کنه هر کسي به جز اون فرد نتوند به ساير گروه هاي خبر دسترسي داشته باشه
براي همين من اين کار رانجام دادم به ازاي يوزر هايي که ثبت ميشه همزمان با ثبت يوزر ها چک باکسی هایی که شامل گروه های خبری بود که گروه هاي خبري با يک ابجکت ديتا سورس پر شدند مياد انها را ثبت ميکنه
در واقع
ميخام همزمان که يوزر را ثبت ميکنه گروه هاي خبري که اين يوزر بهش دسترسي داره را هم ثبت کنم
چند تا جدول هم داریم
یکی جدول یوزر ها-جدول گروه های خبری- یک جدول هم به صورت واسط که یوزر نیم و نام گرو های خبری داخلش ثبت میشوند.
وقتی ثبت انجام میشه 2 تا ثبت انجام میشه یکسری اطلاعات یوزر ها در جدول یوزر ها و یکی هم یوزرنیم و گروه خبری در جدول اخری

من این کد را نوشتم ولی نتونستم جواب بگیرم
توی قسمت
findcontrol chekboxlist moshkel dare
میخاستم یک جور کد تغییرداده شود که عمل ثبت انجام بشه
ممنون

خطا:
System.NullReferenceException: Object reference not set to an instance of an object



public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{

// Create an empty Profile for the newly created user
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWiza rd1.UserName, true);

// Populate some Profile properties off of the create user wizard
p.name = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtName")).Text;
p.family = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtFamily")).Text;
p.identityNumber = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtIdentity")).Text;
p.nationalIdentityNumber = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtNationalIdentity")).Text;
p.fatherName = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtFatherName")).Text;
p.mobile = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtMobile")).Text;
p.tel = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtTel")).Text;
p.address = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtAddress")).Text;
p.stockNum = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtStockNum")).Text;
p.indebted = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtIndebted")).Text;
p.creditor = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtCreditor")).Text;

// Save the profile - must be done since we explicitly created this profile instance
p.Save();
string username = p.UserName;

CheckBoxList Chk = (CheckBoxList)FindControl("ChkBLNewsCat");

foreach (ListItem listitem in Chk.Items)
{
if (listitem.Selected)
{
ObjectDSUserAccessToNewsCat.InsertParameters["UserName"].DefaultValue = username;
ObjectDSUserAccessToNewsCat.InsertParameters["newsCatID"].DefaultValue = listitem.Value;
ObjectDSUserAccessToNewsCat.InsertParameters["newsCatName"].DefaultValue = listitem.Text;
ObjectDSUserAccessToNewsCat.Insert();
}
}
}

fakhravari
چهارشنبه 23 فروردین 1391, 09:10 صبح
در بین کد c# بزارید تا خواناتر بشود

ERIKA
چهارشنبه 23 فروردین 1391, 10:20 صبح
سلام
من کدش را به این صورت تغییر دادم


public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
TextBox TextBoxUserName = new TextBox();
TextBoxUserName.FindControl("TextBoxUserName");


//CheckBoxList ChkBLNewsCat = new CheckBoxList();
//ChkBLNewsCat.FindControl("CheckBoxList1");

// Create an empty Profile for the newly created user
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWiza rd1.UserName, true);

// Populate some Profile properties off of the create user wizard
p.name = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtName")).Text;
p.family = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtFamily")).Text;
p.identityNumber = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtIdentity")).Text;
p.nationalIdentityNumber = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtNationalIdentity")).Text;
p.fatherName = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtFatherName")).Text;
p.mobile = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtMobile")).Text;
p.tel = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtTel")).Text;
p.address = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtAddress")).Text;
p.stockNum = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtStockNum")).Text;
p.indebted = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtIndebted")).Text;
p.creditor = ((TextBox)CreateUserWizard1.CreateUserStep.Content TemplateContainer.FindControl("txtCreditor")).Text;

// Save the profile - must be done since we explicitly created this profile instance
p.Save();
TextBoxUserName.Text = p.UserName;
CheckBoxList ChkBLNewsCat = (CheckBoxList)CreateUserWizard1.CreateUserStep.Con tentTemplateContainer.FindControl("CheckBoxList1");

foreach (ListItem listitem in ChkBLNewsCat.Items)
{

if (listitem.Selected)
{


ObjectDataSource2.InsertParameters["newscatid"].DefaultValue = listitem.Value;

ObjectDataSource2.InsertParameters["UserName"].DefaultValue = TextBoxUserName.Text;

ObjectDataSource2.Insert();

}
}


}




ولی الان این خطا را میدهد
Exception has been thrown by the target of an invocation.

ghafoori
پنج شنبه 24 فروردین 1391, 12:38 عصر
شما داخل صفحه تون از آژاکس استفاده می کنید ؟؟؟

ERIKA
پنج شنبه 24 فروردین 1391, 13:45 عصر
شما داخل صفحه تون از آژاکس استفاده می کنید ؟؟؟

بله اتفاقا وقتی میخام برنامه را اجرا کنم به دو خط که شامل یک devexpress هست خطا میگیره من هم فعلا برای اینکه رد کنه ان را پاک کردم...ولی داخل کد ها ایجکس هم هست!

ghafoori
پنج شنبه 24 فروردین 1391, 15:04 عصر
طبق راهنمایی این صفحه (http://forums.asp.net/t/1070216.aspx/1)خصوصیت
EnablePartialRendering="false"
اسکریپت منجر صفحه را مقدار دهید ببینید مشکل حل میشه
نشد اطلاعات کاملتری در مورد خطا بدهید کل پیام خطا را قرار دهید