This is my first ASP.NET web app and every form without <form runat="server"></form>
tag is not running plus all element should be inside form tag. Now I have some buttons links for some other pages of my project.
这是我的第一个ASP.NET Web应用程序,没有
If I use following code it opens new link on another page instead of same page:
如果我使用以下代码,则会在另一个页面上打开新链接,而不是同一页面:
<asp:Button ID="ButtonAttendance" OnClientClick="window.open('AttendanceForm.aspx','AttendanceForm')" runat="server" Text="Attendance"
CssClass="btn" /><br />
And if I use following code then every buttons acts after filling the form elements only:
如果我使用以下代码,那么每个按钮仅在填充表单元素后起作用:
<asp:Button ID="ButtonAttendance" OnClick=ButtonAttendance_Click() runat="server" Text="Attendance"
CssClass="btn" /><br />
Code behind:
protected void ButtonAttendance_Click(object sender, EventArgs e)
{
Response.Redirect("AttendanceForm.aspx");
}
My requirement is when click on any button we should redirect to related page directly on the same page without filling any form elements. How it is possible?
我的要求是当点击任何按钮时我们应该直接在同一页面上重定向到相关页面而不填写任何表单元素。怎么可能?
2 个解决方案
#1
0
Your code behind looks fine.
你的代码看起来很好。
If you are using a webform you have to put your controls within the form tags for the postback to work correctly and raise the OnClick
event on the sever side.
如果您使用的是webform,则必须将控件放在表单标记内以使回发正常工作,并在服务器端引发OnClick事件。
<form runat ="server">
<asp:Button ID="ButtonAttendance" OnClick=ButtonAttendance_Click() runat="server" Text="Attendance"
CssClass="btn" /><br />
</form>
If you don't need to have the server set values or interact with the buttons on the page just make them regular HTML buttons and use the onclick event for JavaScript to do the redirection.
如果您不需要拥有服务器设置值或与页面上的按钮交互,只需将它们设置为常规HTML按钮,并使用onclick事件进行JavaScript重定向。
<button id="btnAttendance" onclick="window.location.href='AttendanceForm.aspx';return false;" class="btn">Attendance</button>
#2
0
instead of window.open use window.location it will open in the same age window.location='AttendanceForm.aspx'
而不是window.open使用window.location它将在相同的年龄window.location ='AttendanceForm.aspx'中打开
#1
0
Your code behind looks fine.
你的代码看起来很好。
If you are using a webform you have to put your controls within the form tags for the postback to work correctly and raise the OnClick
event on the sever side.
如果您使用的是webform,则必须将控件放在表单标记内以使回发正常工作,并在服务器端引发OnClick事件。
<form runat ="server">
<asp:Button ID="ButtonAttendance" OnClick=ButtonAttendance_Click() runat="server" Text="Attendance"
CssClass="btn" /><br />
</form>
If you don't need to have the server set values or interact with the buttons on the page just make them regular HTML buttons and use the onclick event for JavaScript to do the redirection.
如果您不需要拥有服务器设置值或与页面上的按钮交互,只需将它们设置为常规HTML按钮,并使用onclick事件进行JavaScript重定向。
<button id="btnAttendance" onclick="window.location.href='AttendanceForm.aspx';return false;" class="btn">Attendance</button>
#2
0
instead of window.open use window.location it will open in the same age window.location='AttendanceForm.aspx'
而不是window.open使用window.location它将在相同的年龄window.location ='AttendanceForm.aspx'中打开