半点优化网 http://www.bdxc.net/
当前位置首页 > 网站技术问题> 正文

asp.net网站开发的问题

2022-10-03 01:53:58 暂无评论 209 网站技术问题 网站开发   问题   asp

我回答问题首先希望帮助到学习C#的后辈。

所以先分析原因。
你出现这个错误是因为你没有了解ASP.NET的工作原理。ASP.Net 和php,jsp ,asp等服务器语言一样 都是为了生成可供浏览器解析的页面,而可供浏览器解析的语言只有HTML。

1,如果你在aspx页面中插入一个asp:LinkButton 那么运行页面后 在浏览器中查看源代码你会发现这个标签实际被转为了一个<a>标签。
2,为什么你的写法不会转换呢?因为首先 传递给Literal1.Text 的值在asp.net中作为一段字符串被直接输出到浏览器中。那么你的写法到浏览器后源代码中仍然是一个asp:LinkButton 标签,而这个标签是无法被浏览器正确解析的。

解决办法:
知道了原因,那么如果非要按照你的写法去写,那么应该是这样的:
Literal1.Text = <li> + ((users)Session[users]).Name.ToString() + </li><li> </li><li><a ID='LinkButton1' onclick='LinkButton1_Click1'>注销</a></li><li> </li><li>信息修改</li><li> </li>;
但是当你修改完后发现点击注销按钮依然不能执行!为什么呢?
因为你的LinkButton1_Click1 事件并没有在asp.net中被解析为可供浏览器识别的js代码。

如何解决?

首先吐槽下你的写法实在另类, 但是依然可以实现。

在aspx页面中写一个asp:LinkButton按钮:
<asp:LinkButton ID='LinkButton2' runat='server' onclick='LinkButton1_Click1'>注销</asp:LinkButton>

运行页面,查看源代码 看看这个新加的注销按钮被解析为了什么html代码,大概如下
<a id=LinkButton2 onclick=xxxxx></a>

将新加的linkbutton 设置不可见属性
<asp:LinkButton ID='LinkButton2' runat='server' visible=false onclick='LinkButton1_Click1'>注销</asp:LinkButton>

重新修改后台代码
Literal1.Text = <li> + ((users)Session[users]).Name.ToString() + </li><li> </li><li><a ID='LinkButton1' onclick='xxxxx'>注销</a></li><li> </li><li>信息修改</li><li> </li>;
//也就是将标签的js事件绑定到那个隐藏的注销按钮事件上。
希望对你有帮助

微软是推荐使用membership,但肯定不像自己实现那样自由,identity没用过,不过我平时都是自己实现的,配置使用Form验证,设置相应权限目录。

猜你喜欢

随机文章


    Warning: require(): open_basedir restriction in effect. File(/www/wwwroot/bdxc.net/e/class/connect.php) is not within the allowed path(s): (/www/wwwroot/www.bdxc.net/:/tmp/) in /www/wwwroot/www.bdxc.net/1.php on line 4

    Warning: require(/www/wwwroot/bdxc.net/e/class/connect.php): failed to open stream: Operation not permitted in /www/wwwroot/www.bdxc.net/1.php on line 4

    Fatal error: require(): Failed opening required '/www/wwwroot/bdxc.net/e/class/connect.php' (include_path='.:/www/server/php/56/lib/php') in /www/wwwroot/www.bdxc.net/1.php on line 4