الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

يا جماعة MasterPage and Ajax Updateanel

مغلق
بدأه bnitt في 9 يونيو 2007 · 10 رد · 820 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

يا جماعة المشكلة ارجو الحل ::: وهذة الصور الصورة الصورة الاجاكس ومشكلتي ::::::


using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public class Class2 : System.Web.UI.Page
{
public class class2
{
//-------------------------------------------------------------------------
//FindControls In MasterPage (Content) ContentPlaceHolder
public Control FindChildControl(Control start, string id)
{
if (start != null)
{
Control foundControl;
foundControl = start.FindControl(id);

if (foundControl != null)
{
return foundControl;
}

foreach (Control c in start.Controls)
{
foundControl = FindChildControl(c, id);
{
if (c.GetType().ToString() == "System.Web.UI.UpdatePanel")
{
FindControlInsidUpdatePanel(c);
}
}
if (foundControl != null)
{
return foundControl;
}
}
}
return null;
}
//-------------------------------------------------------------------------
//Find Controls Insid Ajax UpdatePanel:-
public Control FindControlInsidUpdatePanel(Control root)
{
foreach (Control c in root.Controls)
{
if (c.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
{
TextBox z = (TextBox)c;
z.Text = "";
}
}
return null;
}

}

}
using System;

#2

ماذا تريد !!!

ما هي الاشياء التي لا تعمل و ما الذي تريد الوصول اليه ؟

#3

اريد البحث عن الكنترولز الى فى UpdatePanel الموجودة داخل Contents التابع للMasterPage

#4

على ما اظن انت تريد ارجاع العنصر المسمى Content1 ؟

اذا كانت الاجابة بنعم فانت تسلك طريقا ملتويا لان العناصر الموجودة داخل عنصر asp:content يتم الوصول اليها عن طريق الContentPlaceHolder المربوط بها

فمثلا لو لدينا ContentPlaceHolder1 في الماستر بيج ,ولدينا عنصر content بداخل الصفحة (اي صفحة الcontent) وكان لدينا عنصر UpdatePanel1 بداخل عنصر الcontent و كان لدينا TextBox بالاسم TextBox1 داخل الupdatepanel واردنا ان نكتب القيمة madani داخل الTextBox فالكود كالتالي

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Dim UpdatePanel1 As Microsoft.Web.UI.UpdatePanel = CType(Temp.FindChildControl(Master, "ContentPlaceHolder1").FindControl("UpdatePanel1"), Microsoft.Web.UI.UpdatePanel)
		CType(UpdatePanel1.FindControl("TextBox2"), TextBox).Text = "Madani"



	End Sub

الكود اعلاه سيكتب القيمة madani في حقل النص Name عند عرض الصفحة

مدني

تم تعديل هذه المشاركة بواسطة madani في 9 يونيو 2007 في 19:11

#5

تشكر اخي الان كل شيئ اوكية

اشكرك مجددا

انا طبعا مبرمج كمبيوتر اعمل فى شركة برمجيات فى اليمن

طبعا احاول تطوير اعمالى الى تقنية AJAX

تم تعديل هذه المشاركة بواسطة bnitt في 9 يونيو 2007 في 19:56

#6

واليك طريقة اسهل للحصول على الكنترول :

public T FindMyControl<T>(Control start, string id)
		{
			T returnValue = default(T);
			Control c = start.FindControl(id);

			if (c != null)
			{
				returnValue = (T)(object)c;
				return returnValue;
			}
			else
			{
				foreach (Control c2 in start.Controls)
				{
					returnValue = FindMyControl<T>(c2, id);
					if (returnValue != null)
						return returnValue;
				}


			}
				return returnValue;

		}

لو فرضنا انك تريد تغيير قيمة TextBox1 ,تنادي الدالة كالتالي:

		Temp.FindMyControl(Of TextBox)(Me.Master, "TextBox2").Text = "Madani"

لو تود الحصول على الSelectValue لDropDownList موجودة في الUpdatePanel :

Temp.FindMyControl(Of DropDownList)(Me.Master, "DropDownList1").SelectedValue

تم تعديل هذه المشاركة بواسطة madani في 11 يونيو 2007 في 06:30

#7

شكرا خي على كل شي ولكني ما فهمت كودك او بالاصح ما قدرت استخدمه على ما اريد

انا معي كلاس فيه دوال للاضافه والتعديل الوتصفية وكافة العمليات على الشاشة في بدايه إقلاع الفورم أريد قراءة كافة الادوات الموجوده على الشاشة وتخزينها في متغير من نوع مصفوفة بعد ذلك في خاصية التصفية مثلا اعمل ForEach لهذا المتغير من نوع المصفوفة ويكون مخزن فيه كافة الكنترولز مع اسمائها وانواعها وبذالك استطيع إجراء كافة العمليات التي أريدها مثلا تصفية الكنترولز في الصفحة إليك هذا المثال:


using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public class Class2 : System.Web.UI.Page
{
public class class2
{
public int j = 0;

public Control[] CtrTemp;
//-------------------------------------------------------------------------
//FindControls In MasterPage (Content) ContentPlaceHolder
public Control FindChildControl(Control start, string id)
{

if (start != null)
{
Control foundControl;
foundControl = start.FindControl(id);

if (foundControl != null)
{
return foundControl;
}

foreach (Control c in start.Controls)
{
foundControl = FindChildControl(c, id);
{
if (c.GetType().ToString() == "System.Web.UI.UpdatePanel")
{
FindControlInsidUpdatePanel(c);
}
}
if (foundControl != null)
{
return foundControl;
}
}
}
return null;
}
//-------------------------------------------------------------------------
//Find Controls Insid Ajax UpdatePanel:-
public Control FindControlInsidUpdatePanel(Control root)
{
foreach (Control c in root.Controls)
{
if (c.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
{
TextBox z = (TextBox)c;
z.Text = "";
}
}
return null;
}

}

}
using System;

تم تعديل هذه المشاركة بواسطة bnitt في 10 يونيو 2007 في 11:22

#8

جرب للبحث ومسح محتويات textboxes

protected void Page_Load(object sender, EventArgs e)
	{

	}
	protected void ClearData(Control parent) 
{
  foreach (Control c in parent.Controls) 
  { 
	if (c.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox")) 
	{ 
		  ((TextBox) c).Text= "";
	} 

  } 
}

مثال لمجموعة تكست بوكس في بانل اسمها UpdatePanel1

 protected void Button1_Click(object sender, EventArgs e)
	{
		ClearData(UpdatePanel1);
	}

لا تنس ان تضيف Trigger للزر في UpdatePanel حسب الحاجة

The World Must Be Crazy

#9

اخى اريد تعديل على الكلاس لا اريد كلاس جديد يستدعي تغيير كلي فى الكلاس

#10

اخي الكريم,

الدالة FindMyControl التي كتبتها تفي بالغرض ,فقط اضفها الى الكلاس و استدعها كما في الشرح السابق.

#11

اخى تظهر لدى مشكلة :-

هذا الكلاس هل هو صحيح:-

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public class Class2 : System.Web.UI.Page
{
	public class class2
	{
		//-------------------------------------------------------------------------
		  //FindControls In MasterPage (Content) ContentPlaceHolder 
		public Control FindChildControl(Control start, string id)
		{

			if (start != null)
			{
				Control foundControl;
				foundControl = start.FindControl(id);

				if (foundControl != null)
				{
					return foundControl;
				}

				foreach (Control c in start.Controls)
				{
					foundControl = FindChildControl(c, id);
					{

					}
					if (foundControl != null)
					{
						return foundControl;
					}
				}
			}
			return null;
		}}

وهذا الكود فى البيج لود Page_Load

Imports System.Web
Imports System.Web.UI
Partial Class Trans
	Inherits System.Web.UI.Page
	Dim x As Class2.class2
	Dim up As UI.UpdatePanel
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Dim UpdatePanel1 As System.Web.UI.UpdatePanel = CType(x.FindChildControl(Master, "ContentPlaceHolder1").FindControl("UpdatePanel1"), System.Web.UI.UpdatePanel)
	End Sub

	Protected Sub Clear_Click(ByVal sender As Object, ByVal e As System.EventArgs)

	End Sub
End Class

فكيف سيكون كود تفريغ صناديق النصوص ClearData InText

تم تعديل هذه المشاركة بواسطة bnitt في 11 يونيو 2007 في 09:50

هذا الموضوع مغلق.

مواضيع مشابهة