我正在使用OnItemDataBound事件尝试激活转发器中的禁用按钮.很简单,如果事件被触发,我知道转发器中有项目,因此想要启用该按钮.我遇到的问题是在函数中强制转换按钮,因此我可以启用它.转发器代码的相关部分如下:
<asp:Repeater ID="RptEnterHours" runat="server" DataSourceID="SQL_EmployeeGetTimesheet" ClientIDMode="Predictable" OnItemDataBound="RptEnterHours_Bound">
'.....Irrelevant code.....
<FooterTemplate>
<asp:Button Enabled="false" ID="SubmitTimesheets" Text="Submit All Timesheets" OnClick="processTimesheetEntry" runat="server" OnClientClick="checkValues();" />
</FooterTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
这是我的代码背后:
Sub RptEnterHours_Bound(Sender As Object, e As RepeaterItemEventArgs)
'Exposes the Submit All Timesheets button if timesheets are available.
If (e.Item.ItemType = ListItemType.Item) Or _
(e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim sButton As Button = TryCast(Me.FindControl("SubmitTimesheets"), Button)
sButton.Enabled = True
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
这个和所有其他尝试产生了可怕的"对象引用未设置为对象的实例"消息.任何人都可以告诉我我做错了什么以及为什么我的代码背后找不到按钮?
我在部分视图中的IF语句中有一个Html.ActionLink,它没有按预期为我呈现超链接.我在行上放置了一个断点,并确认IF语句实际上已得到满足,并且其中的代码正在运行.我也是,作为一个额外的措施,尝试用硬字符串替换Substring.任何想法为什么没有链接为我呈现此代码?
<p>
Resume (Word or PDF only): @if (Model.savedresume.Length > 0) { Html.ActionLink(Model.savedresume.Substring(19), "GetFile", "Home", new { filetype = "R" }, null); }
</p>
Run Code Online (Sandbox Code Playgroud) 我有一个MVC应用程序,它使用自己的用户数据库和身份验证系统,而不是标准的帐户控制器和aspnet auth系统(没有计划改变它).作为其中的一部分,我有一个jQuery事件,在发送到服务器的表单发布之前检查是否存在用户名以创建新用户.当我在.submit函数的开头放置一个event.preventDefault时,一切似乎都正常工作.但是,如果用户名已存在,我只想阻止帖子.在下面的例子中,我从未收到过警报,并且发布了帖子任何人都可以告诉我我做错了什么?谢谢!
$(document).ready(function () {
$('#ProcessApplication').submit(function (event)
{
var un = encodeURIComponent($("input[name='form_email1']").val());
var myurl = '/Home/IsUser/' + un;
alert(myurl);
$.ajax({
url: myurl,
success: function (response) {
if (response == '1') {
alert("This e-mail address is already registered. Please login, then resubmit your application.");
event.preventDefault(); // <-- I've tried both event.preventDefault(); and return false; here
}
}
});
});
});
Run Code Online (Sandbox Code Playgroud)