求教如何让用户自定义页面上的控件? 100分求解,有帮助的也给分!!! 如题,现在要做个asp.net程序,可以让用户在某个页面上自己定义用什么控件,它的位置、类型等等,定义完成后可保存,下次可动态显示出来,大家帮帮忙吧~~~昨天已经发过,可没人回复阿,现在加大给分,望各位大虾指点!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 回kandyasp:就算有办法把这些信息保存,可到时候怎么把这些信息动态的在页面上显示出来呢,这个我还是不明白阿~~~请大虾说具体些吧另外怎么样保存也是一个问题啊。 能实现,也不难,只是比较麻烦!你将他设置内容的属性全部写入数据库或者XML保存,然后根据用户登录ID判断显示每个人自己定义的页面。如:表一:用户ID 控件名 X位置 Y位置 属性对应ID表二:属性对应ID 控件属性名 属性值 这个hedonister当然是用表存储信息咯~~~,问题在于怎么动态存储阿,意思就是本来一个空的页面,最好要让用户自己拖控件上去,并且可以定义它的各种信息,当然我觉得这个要求好像高了点,其他类似方法也可以~~~ 你其实就是想帮用户做一个页面设计器吧;是不是应该生成一个静态的html文件就可以了 要想做成你说的那样会比较难:你的JavaScript要必须很强:他选择一种控件你就要用JavaScript动态创建控件,还要用JavaScript实现拖动功能,拖动功能你看看MSN的首页(页里面的东西可以拖动)或许会有帮助。 我本以为你只是让他选选而已呢!比如:他选Button,填Text属性为“提交”等等这样,而没想到你要求能“图形化操作” 唉,我对javascript可以说基本不懂如果全动态的比较麻烦,类似的也可以 cqzhangq(空空)说的倒是真话,Javascript很有用,是要好好学学。“有没有什么取巧的方法?”我没什么好注意! 参考一下:http://www.evget.com/view/viewProductInfo.asp?productId=117 不好意思,我先前回答的“拖动功能你看看MSN的首页(页里面的东西可以拖动)”不对,刚刚我看了一下发现不是我以前打开的那个网站,可能是我记错了。但用JavaScript是可以达到拖动效果的 javascript的确很有用,这个我也知道,不过现在临时抱佛脚可能来不及,下星期三之前要想出方案的 参考一下吧,可能有帮助:(老实说主要还是靠javascript实现)<%@Page Language="C#"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><script language="JScript"><!--function ShowHTMLContent() { var strURL = 'http://<% = Request.ServerVariables["SERVER_NAME"] %><% = Request.Path %>?<% = Request.QueryString %>'; var strDisplay = new String; var objHTTP = new ActiveXObject("microsoft.XMLHTTP") objHTTP.open('GET', strURL, false); objHTTP.send(); var strReply = objHTTP.responseText; var intStart = strReply.indexOf('<!' + '--start-->') + 12; var intEnd = strReply.indexOf('<!' + '--end-->'); if ((intStart > 0) && (intEnd > intStart)) var strDisplay = strReply.substring(intStart, intEnd); document.all['outHTML'].innerText = strDisplay + ' ';}function SetCheck(strCheckboxName) { document.all[strCheckboxName].checked = true;}//--></script><!-- #include file="style.inc" --></head><body bgcolor="#ffffff" onload="ShowHTMLContent()"><!---------------------------------------------------------------------------><span class="heading">HtmlInputText Control</span> <!--start--><input type="text" id="MyControl" value="My HTML Textbox" runat="server" /><!--end--><p /><div id="outError" runat="server" /><font face="Courier New" size="2"><div style="background-color:gainsboro; padding-left:10px" id="outHTML">Fetching HTML content...</div></font><form runat="server" method="get"><table border="0"><tr><td nowrap="nowrap"><input type="checkbox" id="chkDisabled" runat="server" /> Set: </td><td align="right" nowrap="nowrap">Disabled =</td><td nowrap="nowrap"><select id="selDisabled" size="1" runat="server" onchange="SetCheck('chkDisabled')"><option>True</option><option>False</option></select></td><td nowrap="nowrap"> </td><td nowrap="nowrap"></td><td align="right" nowrap="nowrap">ID =</td><td nowrap="nowrap"><% = MyControl.ID %></td></tr><tr><td nowrap="nowrap"><input type="checkbox" id="chkMaxLength" runat="server" /> Set: </td><td align="right" nowrap="nowrap">MaxLength =</td><td nowrap="nowrap"><input type="text" size="2" id="txtMaxLength" runat="server" onkeypress="SetCheck('chkMaxLength')" /></td><td></td><td nowrap="nowrap"></td><td align="right" nowrap="nowrap">Name =</td><td nowrap="nowrap"><% = MyControl.Name %></td></tr><tr><td nowrap="nowrap"><input type="checkbox" id="chkSize" runat="server" /> Set: </td><td align="right" nowrap="nowrap">Size =</td><td nowrap="nowrap"><input type="text" size="2" id="txtSize" runat="server" onkeypress="SetCheck('chkSize')" /></td><td></td><td nowrap="nowrap"></td><td align="right" nowrap="nowrap">TagName =</td><td nowrap="nowrap"><% = MyControl.TagName %></td></tr><tr><td nowrap="nowrap"></td><td align="right" nowrap="nowrap">Type =</td><td nowrap="nowrap"><% = MyControl.Type %></td><td></td><td nowrap="nowrap"><input type="checkbox" id="chkValue" runat="server" /> Set: </td><td align="right" nowrap="nowrap">Value =</td><td nowrap="nowrap"><input type="text" size="20" id="txtValue" runat="server" onkeypress="SetCheck('chkValue')" /></td></tr><tr><td nowrap="nowrap"><input type="checkbox" id="chkVisible" runat="server" /> Set: </td><td align="right" nowrap="nowrap">Visible =</td><td nowrap="nowrap"><select id="selVisible" size="1" runat="server" onchange="SetCheck('chkVisible')"><option>True</option><option>False</option></select></td><td></td><td nowrap="nowrap"><input type="button" Value="Reset" onclick="javascript:location.href='http://<% = Request.ServerVariables["SERVER_NAME"] %><% = Request.Path %>'"></td><td nowrap="nowrap"></td><td nowrap="nowrap"><input type="submit" Value="Update" runat="server" /></td></tr></table></form><script language="C#" runat="server"> void Page_Load(Object sender, EventArgs e) { outError.InnerHtml = ""; try { if (IsPostBack) { if (chkDisabled.Checked) MyControl.Disabled = Convert.ToBoolean(selDisabled.Value); if (chkMaxLength.Checked) MyControl.MaxLength = Convert.ToInt32(txtMaxLength.Value); if (chkSize.Checked) MyControl.Size = Convert.ToInt32(txtSize.Value); if (chkValue.Checked) MyControl.Value = txtValue.Value; if (chkVisible.Checked) MyControl.Visible = Convert.ToBoolean(selVisible.Value); } selDisabled.Value = MyControl.Disabled.ToString(); txtMaxLength.Value = MyControl.MaxLength.ToString(); txtSize.Value = MyControl.Size.ToString(); txtValue.Value = MyControl.Value; selVisible.Value = MyControl.Visible.ToString(); } catch (Exception objError) { outError.InnerHtml = "<b>* Error</b>: " + objError.Message + "<p />"; } } </script><!---------------------------------------------------------------------------></body></html> AllenTing(),首先非常感谢你写了那么多的代码 ,不过这段代码实现的是什么功能?能不能给我说一下,因为看起来实在好累~~~ warren1999(warren1999) ,你给的网站是全洋文的阿汗 给你留消息了 cjie15(杰) 注意查收 它是用js实现的,他的缺点是从启以后结果不能保存。应该可以把改动保存下来。当然只是一个参考,我估计你的本意是想做一个类似于可以自定义显示格式的工具。如果是这样的话,可以考虑wiki的 我的本意是让用户来定义他自己的操作界面,这个wiki是什么? 看看这个:http://wiki.sunyear.com.tw/index.php?title=%E9%A6%96%E9%A0%81 现在我用的是这样的方法(也是在以前的帖子里看到的) TextBox newControls=new TextBox(); newControls.ID = "textbox1"; newControls.Width = 100; newControls.Style.Add("LEFT","50"); newControls.Style.Add("TOP","50"); Page.Controls[1].Controls.Add(newControls);另外这个方法添加的控件只是暂时的,页面一刷新就没了,有什么方法可以让它一直显示在页面上。而且让这样添加的控件以后要响应某个事件也是个难点。 我现在就在做一个程序是用户自定义界面,然后把数据信息都放入ORACLE中,界面弹起的时候访问数据库再显示到界面上,不过我目前就做了可以在界面上自定义文字,图片和FLASH 我现在定义是可以了,只是 TextBox newControls=new TextBox(); newControls.ID = "textbox1"; newControls.Width = 100; newControls.Style.Add("LEFT","50"); newControls.Style.Add("TOP","50"); Page.Controls[1].Controls.Add(newControls);用这个方法定义出的控件页面一刷新就没了,而且不能加在事件。知不知道有什么方法。 ........我是写在ASP里面的,不是写在CS里的 TextBox newControls=new TextBox(); newControls.ID = "textbox1"; newControls.Width = 100; newControls.Style.Add("LEFT","50"); newControls.Style.Add("TOP","50"); Page.Controls[1].Controls.Add(newControls);用这个方法定义出的控件页面一刷新就没了,而且不能加载事件。知不知道有什么方法。过完年了,大家来帮帮忙了阿,我会额外发红包的哦 如何给treeview的 TreeNode节点增加点击事件? 谢谢~~ 写个让textbox边框变成红色,背景成绿色的样式表 急!Login控件的访问问题 做一个GPS软件大概要多久 sos,非常急,在线等待__doPostBack提示缺少对象 定义变量的问题! 服务器端控件与客户端控件的区别 从那可以找到treeview空件,急待。 owc高手请注意,能否帮忙看看我的疑问? 哪位有ASP.net下面编写树形菜单的源码? 利用存储过程动态删除表的语句拆分问题 那位能给一个在C#里用DSN连结数据库读取数据的小例子?
另外怎么样保存也是一个问题啊。
你将他设置内容的属性全部写入数据库或者XML保存,然后根据用户登录ID判断显示每个人自己定义的页面。如:
表一:
用户ID 控件名 X位置 Y位置 属性对应ID表二:
属性对应ID 控件属性名 属性值
你的JavaScript要必须很强:他选择一种控件你就要用JavaScript动态创建控件,还要用JavaScript实现拖动功能,拖动功能你看看MSN的首页(页里面的东西可以拖动)或许会有帮助。
比如:他选Button,填Text属性为“提交”等等这样,而没想到你要求能“图形化操作”
如果全动态的比较麻烦,类似的也可以
但用JavaScript是可以达到拖动效果的
<%@Page Language="C#"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><script language="JScript">
<!--
function ShowHTMLContent() {
var strURL = 'http://<% = Request.ServerVariables["SERVER_NAME"] %><% = Request.Path %>?<% = Request.QueryString %>';
var strDisplay = new String;
var objHTTP = new ActiveXObject("microsoft.XMLHTTP")
objHTTP.open('GET', strURL, false);
objHTTP.send();
var strReply = objHTTP.responseText;
var intStart = strReply.indexOf('<!' + '--start-->') + 12;
var intEnd = strReply.indexOf('<!' + '--end-->');
if ((intStart > 0) && (intEnd > intStart))
var strDisplay = strReply.substring(intStart, intEnd);
document.all['outHTML'].innerText = strDisplay + ' ';
}
function SetCheck(strCheckboxName) {
document.all[strCheckboxName].checked = true;
}
//-->
</script><!-- #include file="style.inc" -->
</head>
<body bgcolor="#ffffff" onload="ShowHTMLContent()">
<!--------------------------------------------------------------------------->
<span class="heading">HtmlInputText Control</span> <!--start-->
<input type="text" id="MyControl" value="My HTML Textbox" runat="server" />
<!--end--><p /><div id="outError" runat="server" />
<font face="Courier New" size="2"><div style="background-color:gainsboro; padding-left:10px" id="outHTML">Fetching HTML content...</div></font><form runat="server" method="get">
<table border="0">
<tr>
<td nowrap="nowrap"><input type="checkbox" id="chkDisabled" runat="server" /> Set: </td><td align="right" nowrap="nowrap">Disabled =</td><td nowrap="nowrap"><select id="selDisabled" size="1" runat="server" onchange="SetCheck('chkDisabled')"><option>True</option><option>False</option></select></td>
<td nowrap="nowrap"> </td>
<td nowrap="nowrap"></td><td align="right" nowrap="nowrap">ID =</td><td nowrap="nowrap"><% = MyControl.ID %></td>
</tr><tr>
<td nowrap="nowrap"><input type="checkbox" id="chkMaxLength" runat="server" /> Set: </td><td align="right" nowrap="nowrap">MaxLength =</td><td nowrap="nowrap"><input type="text" size="2" id="txtMaxLength" runat="server" onkeypress="SetCheck('chkMaxLength')" /></td><td></td>
<td nowrap="nowrap"></td><td align="right" nowrap="nowrap">Name =</td><td nowrap="nowrap"><% = MyControl.Name %></td>
</tr><tr>
<td nowrap="nowrap"><input type="checkbox" id="chkSize" runat="server" /> Set: </td><td align="right" nowrap="nowrap">Size =</td><td nowrap="nowrap"><input type="text" size="2" id="txtSize" runat="server" onkeypress="SetCheck('chkSize')" /></td><td></td>
<td nowrap="nowrap"></td><td align="right" nowrap="nowrap">TagName =</td><td nowrap="nowrap"><% = MyControl.TagName %></td>
</tr><tr>
<td nowrap="nowrap"></td><td align="right" nowrap="nowrap">Type =</td><td nowrap="nowrap"><% = MyControl.Type %></td><td></td>
<td nowrap="nowrap"><input type="checkbox" id="chkValue" runat="server" /> Set: </td><td align="right" nowrap="nowrap">Value =</td><td nowrap="nowrap"><input type="text" size="20" id="txtValue" runat="server" onkeypress="SetCheck('chkValue')" /></td>
</tr><tr>
<td nowrap="nowrap"><input type="checkbox" id="chkVisible" runat="server" /> Set: </td><td align="right" nowrap="nowrap">Visible =</td><td nowrap="nowrap"><select id="selVisible" size="1" runat="server" onchange="SetCheck('chkVisible')"><option>True</option><option>False</option></select></td><td></td>
<td nowrap="nowrap"><input type="button" Value="Reset" onclick="javascript:location.href='http://<% = Request.ServerVariables["SERVER_NAME"] %><% = Request.Path %>'"></td><td nowrap="nowrap"></td><td nowrap="nowrap"><input type="submit" Value="Update" runat="server" /></td>
</tr>
</table>
</form><script language="C#" runat="server"> void Page_Load(Object sender, EventArgs e)
{
outError.InnerHtml = ""; try
{
if (IsPostBack)
{
if (chkDisabled.Checked) MyControl.Disabled = Convert.ToBoolean(selDisabled.Value);
if (chkMaxLength.Checked) MyControl.MaxLength = Convert.ToInt32(txtMaxLength.Value);
if (chkSize.Checked) MyControl.Size = Convert.ToInt32(txtSize.Value);
if (chkValue.Checked) MyControl.Value = txtValue.Value;
if (chkVisible.Checked) MyControl.Visible = Convert.ToBoolean(selVisible.Value);
} selDisabled.Value = MyControl.Disabled.ToString();
txtMaxLength.Value = MyControl.MaxLength.ToString();
txtSize.Value = MyControl.Size.ToString();
txtValue.Value = MyControl.Value;
selVisible.Value = MyControl.Visible.ToString();
}
catch (Exception objError)
{
outError.InnerHtml = "<b>* Error</b>: " + objError.Message + "<p />";
}
}
</script><!---------------------------------------------------------------------------></body>
</html>
当然只是一个参考,我估计你的本意是想做一个类似于可以自定义显示格式的工具。
如果是这样的话,可以考虑wiki的
http://wiki.sunyear.com.tw/index.php?title=%E9%A6%96%E9%A0%81
TextBox newControls=new TextBox();
newControls.ID = "textbox1";
newControls.Width = 100;
newControls.Style.Add("LEFT","50");
newControls.Style.Add("TOP","50");
Page.Controls[1].Controls.Add(newControls);
另外这个方法添加的控件只是暂时的,页面一刷新就没了,有什么方法可以让它一直显示在页面上。而且让这样添加的控件以后要响应某个事件也是个难点。
newControls.ID = "textbox1";
newControls.Width = 100;
newControls.Style.Add("LEFT","50");
newControls.Style.Add("TOP","50");
Page.Controls[1].Controls.Add(newControls);
用这个方法定义出的控件页面一刷新就没了,而且不能加在事件。知不知道有什么方法。
newControls.ID = "textbox1";
newControls.Width = 100;
newControls.Style.Add("LEFT","50");
newControls.Style.Add("TOP","50");
Page.Controls[1].Controls.Add(newControls);
用这个方法定义出的控件页面一刷新就没了,而且不能加载事件。知不知道有什么方法。过完年了,大家来帮帮忙了阿,我会额外发红包的哦