多视图返回第一视图
我有一个带有多视图控件的 .net 页面。在第一个“视图”中,我有一个用户需要填写的表单(数据存储在数据库中),第二个“视图”带来一条“谢谢”消息和刚刚创建的 ID。工作正常。问题是我在第二个“视图”中添加了“打印此页”链接,以便用户可以打印他们的 ID(他们还收到一封电子邮件)。但是,当他们按下第二个“视图”中的链接按钮时,它会返回到第一个“视图”。会发生什么?
这是我的代码:
<asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View id="View1" runat="server">
fields here
</asp:View>
<asp:View id="View2" runat="server">
<asp:Label ID="Label1" runat="server"></asp:Label>
<p>
<img alt="print" style="vertical-align:middle" src="images/printing.gif" /> <asp:LinkButton ID="LinkButton1" OnClientClick="window.print();" runat="server">
Remember to print this page</asp:LinkButton></p>
</asp:View>
</asp:MultiView>
代码隐藏:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
InsertNew()
End Sub
Sub InsertNew()
'all code here for inserting in database then
MultiView1.SetActiveView(View2)
Label1.Text = Text here with message
End Sub
I have a .net page with a multiview control. In the first "view" I have a form users need to fill in (data is stored in database), a second "view" brings a 'thank you' message and the ID just created. It works ok. The thing is that I added a 'print this page' link in the second "view " so users can print their IDs (they also reciben an email). But when they press the linkbutton in the second "view" it retuns to the first one. What happens?
This is my code:
<asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View id="View1" runat="server">
fields here
</asp:View>
<asp:View id="View2" runat="server">
<asp:Label ID="Label1" runat="server"></asp:Label>
<p>
<img alt="print" style="vertical-align:middle" src="images/printing.gif" /> <asp:LinkButton ID="LinkButton1" OnClientClick="window.print();" runat="server">
Remember to print this page</asp:LinkButton></p>
</asp:View>
</asp:MultiView>
Code-behind:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
InsertNew()
End Sub
Sub InsertNew()
'all code here for inserting in database then
MultiView1.SetActiveView(View2)
Label1.Text = Text here with message
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除此之外,我认为您不想在用户单击打印按钮时发回,对吗?
使客户端脚本返回 false 以防止回发。
OnClientClick =“window.print();返回错误;”
Besides everything, i don't think you want to be posting back when the user clicks the print button right?
Make the clientscript return false to prevent postback.
OnClientClick="window.print(); return false;"