如何使用母版页从 Web 用户控件获取标签值到内容页
我有一个网络用户控件 book.ascx 和一个表单视图:
<formview runat="server" id="fv">
<ItemTemplate>
<asp:Label runat="server" id="bookID" Text='<%# Eval ("bookId") %>' />
</ItemTemplate>
</FormView>
这个表单视图是动态数据绑定的。 现在我有一个内容页面 Default.aspx:
<%@ Register src="Book.ascx" tagname="Book" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<uc1:Book id="book1" runat="server"/>
<asp:Label runat="server" id="lblBookId" />
</asp:Content>
我想从 Web 用户控件获取标签的值到 default.aspx 页面。 解决这个问题的最佳方法是什么。 谢谢。
I have a web user control book.ascx and a formview:
<formview runat="server" id="fv">
<ItemTemplate>
<asp:Label runat="server" id="bookID" Text='<%# Eval ("bookId") %>' />
</ItemTemplate>
</FormView>
This formview is databind dynamically.
Now i have a Content page Default.aspx:
<%@ Register src="Book.ascx" tagname="Book" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<uc1:Book id="book1" runat="server"/>
<asp:Label runat="server" id="lblBookId" />
</asp:Content>
I want to get the value of the label from web user control to a default.aspx page.
Whats the best method to solve this issue.
Thank You.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 Default.aspx.cs 后面的代码:
From the code behind in the Default.aspx.cs:
我想实现你想要的方法是让书籍控件在知道值是什么后触发一个事件。
您现在需要从页面访问控件内的值。这可以通过通过属性公开值来实现,或者您可以创建自己的 EventArgs 并引发事件。
I guess the way to achieve what you want is to let the book-control fire an event after it knows what the value is.
You now need to gain access from the page to the value inside the control. That can be achieved by exposing the value via a property or you can create your own EventArgs and throw an Event.
你想通过 javascript 在客户端获取它吗?
我还建议您获取 firefox 的 firebug,然后您可以查看生成的网页 html。您还可以单步执行并调试您的 JavaScript。
如果试图在服务器端找到它,请尝试这个。
如果这不起作用,你可以明白这个想法。继续深入下去,直到找到您要找的东西。
you wanted to get it on the client side via javascript?
I would also recommend getting firebug for firefox and then you can take a look at the generated html of the webpage. You'll also be able to step though and debug your javascript.
if trying to find this on the server side try this.
if this doesn't work, you can get the idea. keep drilling down until you find what you're looking for.