我有以下代码:
<asp:Content ID="HeadContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
function SetText(id) {
if (Button2.value == "Disable automatic page refresh")
Button2.value = "Automatic Refresh Disabled";
return false;
}
</script>
</asp:Content>
<asp:Button ID="Button2" runat="server" Text="Disable automatic page refresh" OnClick="Button2_Click" OnClientClick="return SetText(this)" />
Run Code Online (Sandbox Code Playgroud)
当我点击按钮时,按钮名称不会改变,但C#背后的代码仍然可以正常工作.谁能指出我正确的方向?我认为它可能是OnClick事件,但删除后,它仍然无法正常工作.我也尝试将OnClick更改为OnServerClick以防万一,但无济于事.
我正在开始编写网站编码工作,目前我正在进行用户创建页面.所有验证工作正常,但我不确定要将什么放入checkUsername方法以验证用户名是否已存在.下面是我的ASP.NET代码.
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<p>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="There were errors on the page:" />
</p>
<p>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="username" ErrorMessage="Username is required."> *</asp:RequiredFieldValidator>
Enter Username <asp:TextBox ID="username" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="username" ErrorMessage="Username must be 4-10 letters or numbers." ValidationExpression="[a-zA-Z0-9]{4,10}" />
<asp:CustomValidator ID="CustomValidator1" runat="server" controltovalidate="username" errormessage="Username is already in use." OnServerValidate="checkUsername" />
</p>
<p>
Enter Password <asp:TextBox ID="entPWD" runat="server" TextMode="Password"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" display="dynamic" ControlToValidate="entPWD" ErrorMessage="Password must contain one of the following: @#$%^&*/." ValidationExpression=".*[@#$%^&*/].*" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" …Run Code Online (Sandbox Code Playgroud) 我正在使用 URL 重写来强制 http 到 https 重定向。它正在工作,只是它在 URL 中添加了第二个尾部斜杠。例如,如果我访问http://example.com,重写的 URL 最终会是https://example.com//。我什至不想要 1 个尾部斜杠,更不用说 2 个,而且我无法摆脱它。我尝试了这个解决方案,但没有成功。可能是因为这个人想去掉结尾的斜杠,而我有两个斜杠,所以它不匹配?
我的 web.config 文件中有以下规则。我正在运行带有 IIS 10 和 URL 重写模块的 Windows Server 2019。如果有人能告诉我哪里出错了,我将不胜感激!
<rule name="HTTPS Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{REQUEST_URI}" appendQueryString="false" />
</rule>
<rule name="SEO - Remove trailing slash" stopProcessing="false">
<match url="(.+)/$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action …Run Code Online (Sandbox Code Playgroud) 我正在关注使用我的ASP.NET站点创建持久登录cookie的这篇文章:
http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.encrypt.aspx
问题是当我导航到页面时,我得到以下编译器错误:
Compiler Error Message: CS1061: 'ASP.administration_login_aspx' does not contain a definition for 'Login_Click' and no extension method 'Login_Click' accepting a first argument of type 'ASP.administration_login_aspx' could be found (are you missing a using directive or an assembly reference?)
任何人都可以告诉我为什么会这样.错误消息并没有真正说明,我不相信我错过了指令或程序集引用.代码构建没有任何问题.
编辑:我没有包含代码,因为我说我正在关注包含代码的链接.我从示例中复制/粘贴.
我有下面的代码,给我以下错误:
System.InvalidCastException:'无法将
'System.Windows.Forms.TextBox'类型的对象强制转换为'System.IConvertible'.'
textBox1.Text = Math.Sqrt(10.0 * (Convert.ToInt32(textBox2Value)) /
(Convert.ToInt32(textBox3Value))).ToString();
Run Code Online (Sandbox Code Playgroud)
文本框2(命名textBox2Value)和3(命名textBox3Value)值是整数,我假设使用ToString()将其评估为textBox1.Text就足够了,但事实并非如此.我不知道为什么.我尝试将textBox值转换为Doubles或Floats,但它没有区别所以我认为它不是公式本身,而是将该值显示为字符串?
任何人都可以协助我出错的地方吗?