PDA

View Full Version : webusercontrol



azam2005
سه شنبه 04 بهمن 1384, 13:43 عصر
اگر یک usercontrol حاوی textbox را روی یک webform قرار دهیم چطور میتوان به این textbox توسط webform دسترسی پیدا کرد؟
چطور کنترلهای روی یک usercontrol میتوانند با کنترلهای روی یک usercontrol دیگر ارتباط برقرار کنند؟

reza_rad
سه شنبه 04 بهمن 1384, 13:52 عصر
کنترل رو static تعریف کنید نمیشه؟

azam2005
سه شنبه 04 بهمن 1384, 14:49 عصر
منظورم webusercontrol است وقتی در webusercontrol /add new item __ sulotion میکنیم

reza_rad
سه شنبه 04 بهمن 1384, 15:02 عصر
خوب من هم نگفتم که webusercontrol رو استاتیک تعریف کنید.گفتم کنترلهایی رو که توی اون هست مثله textbox رو استاتیک تعریف کنید.

azam2005
سه شنبه 04 بهمن 1384, 15:30 عصر
:گریه: :افسرده: مثالی ازusercontrol نداری

reza_rad
سه شنبه 04 بهمن 1384, 15:36 عصر
دارم ولی من از متغیرهاش توی بقیه صفحات استفاده نکردم ولی اگه بخواهی میشه.این یه یوزر کنترل هست که بعنوان header استفاده کردم.ببینید بدردتون میخوره؟

<%@ Control Language="c#" Inherits="Amooznet.Theme.UserControls.header" CodeFile="header.ascx.cs" %>
<%@ Register TagPrefix="loudcarrot" Namespace="LoudCarrot.WebControls" Assembly="LoudCarrot.WebControls.NavPath" %>

<HTML>
<meta http-equiv="Content-Language" content="fa">
<HEAD>
<title></title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta http-equiv="Content-Language" content="fa">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<%
Amooznet.clsConnection con = new Amooznet.clsConnection();
string strThemeName="";
//get theme from database
if (Session.Count > 0) //user logged in,let fetch theme
{
con.select("select theme from " + System.Configuration.ConfigurationSettings.AppSett ings["tblPrefix"].ToString() + "user where id='" + Session["userid"].ToString() + "'");
if (con.dtr.HasRows) //user has own theme
{
con.dtr.Read();
strThemeName = con.dtr["theme"].ToString();
if (strThemeName == "")//user hasn't own theme
{
con.close();
con.select("select value as theme from " + System.Configuration.ConfigurationSettings.AppSett ings["tblPrefix"].ToString() + "config where name='theme'");
if (con.dtr.HasRows) //site has special theme
{
con.dtr.Read();
strThemeName = con.dtr["theme"].ToString();
}
else //site hasn't special theme
strThemeName = "standard"; //default theme
}
}
else//user hasn't own theme
{
con.select("select value as theme from " + System.Configuration.ConfigurationSettings.AppSett ings["tblPrefix"].ToString() + "config where name='theme'");
if (con.dtr.HasRows) //site has special theme
{
con.dtr.Read();
strThemeName = con.dtr["theme"].ToString();
}
else //site hasn't special theme
strThemeName = "standard"; //default theme
}
con.close();
}
else //no user logged in
{
con.select("select value as theme from " + System.Configuration.ConfigurationSettings.AppSett ings["tblPrefix"].ToString() + "config where name='theme'");
if (con.dtr.HasRows) //site has special theme
{
con.dtr.Read();
strThemeName = con.dtr["theme"].ToString();
}
else //site hasn't special theme
strThemeName = "standard"; //default theme

con.close();
}

//theme fetched ,now search for style sheet files
string[] strFiles;
string strDir=System.IO.Path.DirectorySeparatorChar+"theme";
strDir=System.Configuration.ConfigurationSettings. AppSettings["DirRoot"].ToString() + strDir+System.IO.Path.DirectorySeparatorChar+ strThemeName;
strFiles = System.IO.Directory.GetFiles(strDir,"*.css");

int i=0;
for (i = 0;i<strFiles.Length; i++)
{
strFiles[i] = strFiles[i].Remove(0, strDir.Length);%>
<LINK REL="stylesheet" TYPE="text/css" HREF="<%Response.Write(System.Configuration.Configuration Settings.AppSettings["wwwRoot"].ToString());%>/theme/<%Response.Write(strThemeName);%>/<%Response.Write(strFiles[i]); %>">
<%
}

%>

</HEAD>
<!-- Web Page Direction -->
<%if((Application["lan_index"].ToString()=="0") || (Application["lan_index"].ToString()=="2"))%>
<body dir="rtl"><% ; %>
<% if(Application["lan_index"].ToString()=="1") %>
<body dir="ltr"><% ; %>
<!-- Web Page Direction -->


<table cellpadding=0 cellspacing=0 border=0 width=100% height=91 bgColor=#ffffff>
<tr>
<td valign="top" width=1001 height=91 bgcolor=#993300
background="<%Response.Write(System.Configuration.Configuration Settings.AppSettings["wwwRoot"].ToString());%>/theme/MPTheme/Header_Logo.jpg"></td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="headerhome" >
<tr>
<td width="100%" valign="top" class="headerhomemain">

<!-- Navigation Bar -->
<%if((Application["lan_index"].ToString()=="0") || (Application["lan_index"].ToString()=="2"))%>
<LoudCarrot:NavPath id="NavPath" pathseparator=" > " sitemapfile="/localamooznet/language/fa.sitemap" runat="server"></LoudCarrot:NavPath><% ; %>
<%if(Application["lan_index"].ToString()=="1") %>
<LoudCarrot:NavPath id="Navpath1" pathseparator=" > " sitemapfile="/localamooznet/language/en.sitemap" runat="server"></LoudCarrot:NavPath><% ; %>
<!-- Navigation Bar -->
</td>
</tr>
<tr>
<td bgcolor="#ffffff" width="100%" height=15 align="right" valign="top" class="headerhomemenu">
<%if((Application["lan_index"].ToString()=="0") || (Application["lan_index"].ToString()=="2"))%>
<% { %>
<div align=right><font size=2>
<%if(Session.Count<=0){%><a href="<%Response.Write(System.Configuration.Configuration Settings.AppSettings["wwwRoot"].ToString());%>/login/index.php">ورود به سیستم</a><%;}%>
<%if(Session.Count>0){%><a href="<%Response.Write(System.Configuration.Configuration Settings.AppSettings["wwwRoot"].ToString());%>/login/logout.php">خروج از سیستم</a><%;}%>
<% } %>
<% if(Application["lan_index"].ToString()=="1") %>
<% { %>
<div align=left><font size=2>
<%if(Session.Count<=0){%><a href="<%Response.Write(System.Configuration.Configuration Settings.AppSettings["wwwRoot"].ToString());%>/login/index.php">Login</a><%;}%>
<%if(Session.Count>0){%><a href="<%Response.Write(System.Configuration.Configuration Settings.AppSettings["wwwRoot"].ToString());%>/login/logout.php">Logout</a><%;}%>
<% } %>
</font></div></td>
</tr>

azam2005
پنج شنبه 06 بهمن 1384, 09:21 صبح
یک راه پیدا کردم از طریق property که رویUser control تعریف کنیم میتوانیم به کنترلها مقدار بدهیم

azam2005
پنج شنبه 06 بهمن 1384, 09:22 صبح
چطور کنترلهای روی یک usercontrol میتوانند با کنترلهای روی یک usercontrol دیگر ارتباط برقرار کنند؟

mirza
شنبه 08 بهمن 1384, 07:43 صبح
چطور کنترلهای روی یک usercontrol میتوانند با کنترلهای روی یک usercontrol دیگر ارتباط برقرار کنند؟
این مشکل من هم هست
لطفا اگه کسی میدونه راهنمایی کنه

Behrouz_Rad
شنبه 08 بهمن 1384, 22:22 عصر
زمانی که یک User Control ایجاد می کنید، تمامی کنترل های درون آن، به عنوان یک کنترل واحد و تحت نام User Control قرار خواهند گرفت.
به منظور دستیابی به هر یک از اجزای یک User Control، می بایست برای خصوصیت یا روال مورد نظر هر یک از کنترل های موجود در User Control، به صورت جداگانه، Property یا Event تعریف کنید تا بدین وسیله، کنترل های دیگر قادر به استفاده از خواص و روال های کنترل های موجود در User Control شما باشند.
موفق باشید.

iekrang
یک شنبه 09 بهمن 1384, 08:05 صبح
به منظور دستیابی به هر یک از اجزای یک User Control، می بایست برای خصوصیت یا روال مورد نظر هر یک از کنترل های موجود در User Control، به صورت جداگانه، Property یا Event تعریف کنید
اگر امکان داره این قسمت رو توضیح بیشتری بدید.چون فکر میکنم بقیه دوستان هم مثل من احتیاج به یک مثال یا توضیح دارند.

Behrouz_Rad
یک شنبه 09 بهمن 1384, 09:43 صبح
بله البته.
به User Control هایی که مجموعه ای از کنترل ها رو در بر می گیرند، Composite Control ها گفته میشه.
به عنوان مثال، ایجاد یک User Control به منظور لوگین کاربران در سایت.
این User Control مشتمل بر 3 کنترل است. (دو Text Box و یک Button)
قصد دارید که با برنامه نویسی، به کاربر استفاده کننده از User Control این امکان را دهید که رنگ پس زمینه ی یکی از Text Box های این User Control را تغییر دهد.
بسیار ساده، با ایجاد یک Property برای تغییر رنگ پس زمینه ی TextBox، قادر به عملی کردن مقصود خود خواهید بود:


Private _userBoxBackColor As Color
Public Property UserBoxBackColor As Color
Get
Return _userBoxBackColor
End Get
Set(ByVal Value As Color)
_userBoxBackColor = Value
End Set
End Property

و در روال Page_Load یوزر کنترل، بنویسید:


TextBox1.BackColor=_userBoxBackColor

موفق باشید.

azam2005
دوشنبه 10 بهمن 1384, 13:53 عصر
با عرض سلام و تشکر آقای behrouz_rad
برای اینکه وقتی uc1 بر روی فرم1 قرار میگیرد و uc2 بر روی فرم2 قرار میگیردهرuc در هر کدام از این فرمها به طور جداکانه تعریف میشود و Property آن مقدار میگیرد
اگرuc1 دارای drwpdownlist است و در uc_load مقدار میگیرد و uc2_load بهdrwpdownlist.selectvalue نیاز دارد

آیا میباید برایuc2 خصوصیت ساخت ودر uc1_load باDIM UC2 AS UC2 تعریف کرد وبه Property آن مقدار داد.

Behrouz_Rad
دوشنبه 10 بهمن 1384, 14:32 عصر
در مورد انتقال مقادیر بین دو وب فرم، قبلا مقاله ی جامعی ارائه دادم.
جستجو بفرمایید.

Arian_61
شنبه 02 شهریور 1387, 09:13 صبح
با سلام و خسته نباشید
من می خوام متغیر های توی User Control، رو از صفحه مثلا Default.aspx مقدار دهی کنم که بتونم با اون متغیر یه سری فیلدهای خاص و به کاربر نشون بدم . برای این کار کلاس همراه User Control رو Public کردم و متغییر رو هم از نوع Public تعریف کردم ولی اجازه نمی ده من از نوع او کلاس متغیر یعریف کنم و به متغیر های تو صفحه دسترسی داشته باشم این کدها:







User Control



Public Class NewsPortalWithAJAX_main_WebUserControl
Inherits System.Web.UI.UserControl
Public t1 As Integer



Default.aspx



Partial Class NewsPortalWithAJAX_main_Default
Inherits System.Web.UI.Page


Protected WithEvents box2Holder As System.Web.UI.WebControls.PlaceHolder
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim box2 As WebUserControl = LoadControl("WebUserControl.ascx")

box2.t1 = 12

Me.box2Holder.Controls.Add(box2)




آقای راد اگه براتون امکان داره به من کمک کنید . چند روزه دارم سایتا رو زیر و رو می کنم نتیجه نگرفتم.:گریه: