MS MVP 请进:如何調用在ASP.NET的C# Script中,用定義的控件?

yxdh 2003-03-22 01:52:20
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>


<html>

<script language="C#" runat="server">

protected void Page_Load(Object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);

myConnection.Open();

DataSet ds = new DataSet("Report");

myCommand.Fill(ds, "作者");

myConnection.Close();

MyDataGrid.DataSource=ds.Tables["作者"].DefaultView;
MyDataGrid.DataBind();

我想在这里用my.dll里的函数该怎么做?

}

</script>
<body>

<h3><font face="宋体">DataGrid 控件的简单选择</font></h3>

<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="宋体"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
<OBJECT id="print" classid="http:my.dll#my.init" Width="100%" Height="220" VIEWASTEXT></OBJECT>

</body>
</html>
...全文
45 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
yxdh 2003-03-23
  • 打赏
  • 举报
回复
It works!
saucer 2003-03-23
  • 打赏
  • 举报
回复
Response.Write("<xml id='xmldoc'>" + result + "</xml>");
Response.Write("<script language=javascript>function window.onload(){document.all('print').test(xmldoc.xml);}</" + "script>");
yxdh 2003-03-23
  • 打赏
  • 举报
回复
问题错不多已解决:我在页面中加了如下代码
XmlDataDocument xmlDoc = new XmlDataDocument(ds);
XslTransform xslTran = new XslTransform();
xslTran.Load("http://localhost/final/RemotePrint.xsl");
StringWriter sw = new StringWriter();
xslTran.Transform(xmlDoc, null, sw);
string result = sw.ToString();
Response.Write("<script language=javascript>function window.onload(){var XmlStr='"+result+"';document.all('print').test(XmlStr);}</" + "script>");

在my.dll用doc.LoadXml(XmlStr);

当只有两条纪录时,是通过的,但如果是30条时就不行了,难道是字符串太长了?
有解决的方法吗?
yxdh 2003-03-23
  • 打赏
  • 举报
回复
Actually, I want to let the coder make up the data set in the web code
using the DataSet, and therefor I can let my XmlDocument in my dll load the result in my style.That it is!
yxdh 2003-03-23
  • 打赏
  • 举报
回复
how to serialize my DataSet into an xml island? can you give a example?
I'm a new comer.Sorry for troubling you so much!

I want to do follow things in my dll :

XmlDataDocument xmlDoc = new XmlDataDocument(ds);
XslTransform xslTran = new XslTransform();
xslTran.Load("my.xsl");
XmlDocument doc = new XmlDocument();
doc.Load(xslTran.Transform(xmlDoc, null));

can you give me a solution to make it work?
Very glad to come across you here! Best wishes!
saucer 2003-03-23
  • 打赏
  • 举报
回复
serialize your DataSet into an xml island, and change your dll to read from a xml string or dom document on the client side
yxdh 2003-03-23
  • 打赏
  • 举报
回复
非常感谢saucer(思归, MS .NET MVP)的热心帮助
希望能继续探讨一下未决问题:

如果我想传的值是DataSet类型的ds,能实现吗?
我用
Response.Write("<script language=javascript>function window.onload(){ document.all('print').Load("+ds+");}</" + "script>");

出错显示:System未定义
saucer 2003-03-22
  • 打赏
  • 举报
回复
Response.Write("<script language=javascript>function window.onload(){ var date= new Date('" + System.DateTime.Now + "'); document.all('point').Load(date);}</" + "script>");
yxdh 2003-03-22
  • 打赏
  • 举报
回复
因为my.dll是window控件,用了System.Windows.Forms
所以在web中引用不了,请高人指教!
yxdh 2003-03-22
  • 打赏
  • 举报
回复
第一种找不到对象呀,第二种myparam可以是my.dll内的属性吗?
怎样传值初始化我的控件,或者自动调用my.dll内中的方法呢?

用<input type="button" name="Submit2" value="载入数据"
onclick="print.Load(date);">可以调用my.dll内的方法,但是
是手动的
saucer 2003-03-22
  • 打赏
  • 举报
回复
you cannot call client side script in server side code, try outputting something like

Response.Write("<script language=javascript>function window.onload(){print.SomeProperty='" + SomethingYouWantToSet + "'; print.SomeMethod();}</" + "script>");

or

<OBJECT id="print" classid="http:my.dll#my.init" Width="100%" Height="220" VIEWASTEXT>
<param id="myparam" runat="Server" />
</OBJECT>

then in your code, do
myparam.Attributes["value"] = "123";

yxdh 2003-03-22
  • 打赏
  • 举报
回复
呼唤高人救小弟一把!
yxdh 2003-03-22
  • 打赏
  • 举报
回复
或者说我怎样才能将一个string值传给my.dll的函数?

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧