8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

当从 asp.net 页面调用用户控件时,它仅调用 csharp,而不调用 jquery 或 java 脚本函数?

Oran G. Utan 3月前

28 0

我在 asp.net 项目上工作时遇到问题,当从 asp.net 页面调用 Web 用户控件时,调用成功,但脚本 JavaScript 或 jQuery 未被调用,那么为什么不调用脚本,只能从调试页面加载...

我在 asp.net 项目上工作时遇到问题,当从 asp.net 页面调用 Web 用户控件时

成功但未调用脚本 JavaScript 或 jQuery

那么为什么脚本没有被调用

仅从调试页面加载用户控件仅在index.asp.net页面上调用

因此函数脚本 jQuery GET_ITO_PROJECTS_DASHBOARD 未调用或运行,为什么

调用用户控件的 c# 页面加载事件

索引.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/WebPages/main.Master" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="ITO.WebPages.index" EnableEventValidation="false" %>

<%@ Register Src="~/WebUserControls/UC_ProjectsDashboard.ascx" TagPrefix="uc2" TagName="UC_ProjectsDashboard" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <uc2:UC_ProjectsDashboard runat="server" />
</asp:Content>

用户控件 UC_ProjectsDashboard.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UC_ProjectsDashboard.ascx.cs" Inherits="ITO.WebUserControls.UC_ProjectsDashboard" %>
<div class="row">
    <div class="col-12">
        <div id="card-main_Index" class="card customCard card-outline-primary">
   
                     <div class="card-header">
                <h4 class="m-b-0 text-white card-title text-center">
                    <label id="lblTitle" runat="server" clientidmode="Static">Project Dashboard</label>
                </h4>
            </div>
             
                        <div class="card-body">

                         
                             
                        
                          
                              
                              
                               <div class="row" style="margin-top:10px;">
                             
                                <div class="col-12 col-lg-1">
                        
                                       </div>
                                   <div class="col-12 col-lg-5 gvResultmeeting-container hide">
                                    <div class="form-group">
                                          <div class="card card-outline-success">
                                            <div class="card-header" style="background-color: #808080; font-size: 18px; padding: .75rem 1.25rem; font-weight: 600; height: 50px; color: #ffffff;">
                                              الاجتماعات التمهيديه
                                            </div>
                                            <div class="card-body">
                                                <table id="gvResultmeeting" class="table table-striped table-hover table-bordered">
                                                    <thead>
                                                    </thead>
                                                    <tbody>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                               
                        
                                <div class="col-12 col-lg-5  gvResultrequests-container hide">
                                    <div class="form-group">
                                        <div class="card card-outline-success">
                                            
                                                  <div class="card-header" style="background-color: #ffcc00; font-size: 18px; padding: .75rem 1.25rem; font-weight: 600; height: 50px; color: #ffffff;">
                                           الرد على الاستفسارات
                                            </div>
                                            <div class="card-body">
                                                <table id="gvResultrequests" class="table table-striped table-hover table-bordered">
                                                    <thead>
                                                    </thead>
                                                    <tbody>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                   <div class="col-12 col-lg-1">
                     
                                       </div>
                            </div>
                              <div class="row" style="margin-top:10px;">
                             
                                
                                   <div class="col-12 col-lg-12">
                                    <div class="form-group">
                                          <div class="card card-outline-success">
                                            <div class="card-header" style="font-size: 18px; padding: .75rem 1.25rem; font-weight: 600;color: #ffffff;">
                                              المشروعات
                                            </div>
                                            <div class="card-body">
                                                <table id="gvResultprojects" class="table table-striped table-hover table-bordered">
                                                    <thead>
                                                    </thead>
                                                    <tbody>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                        
                             
                            </div>

                            </div>

                   
                
                </div>
            </div>
        </div>




<script>
    $(function () {
        debugger
        if ($("#txtP_PERM_ID").val() == "2059") {
            GET_ITO_PROJECTS_DASHBOARD();
        }
       
    });
</script>
帖子版权声明 1、本帖标题:当从 asp.net 页面调用用户控件时,它仅调用 csharp,而不调用 jquery 或 java 脚本函数?
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由Oran G. Utan在本站《asp.net》版块原创发布, 转载请注明出处!
最新回复 (0)
  • 出现此问题的主要原因是由于最新的版本速度更快而从 AutoMapper 更改为 Mapperly。我遇到的问题是我不知道如何自动将 UpdateBarDTO 映射到 Bar,忽略...

    出现这个问题的主要原因是由于最新的版本速度更快,所以从 AutoMapper 改为 Mapperly。

    我遇到的问题是我不知道如何自动将 Update的 idDTO Bar Bar Bar ,以便它修改正确的数据库对象而不会出现错误:

    System.InvalidOperationException: The property 'Bar.Id' is part of a key and so cannot
    be modified or marked as modified. To change the principal of an existing entity with an
    identifying foreign key, first delete the dependent and invoke 'SaveChanges',
    and then associate the dependent with the new principal.
    
    
    public record class UpdateBarDTO
    (
        [Required][StringLength(255)] string Name,
        [Required] string Address,
        [Required] string PhoneNumber,
        [Required] string Email,
        string Website,
        string CuisineType,
        [Required] string OpeningHours,
        DateTime CreationDate
    );
    
    public class Bar
    {
        public int Id { get; set; }
        public required string Name { get; set; }
        public required string Address { get; set; }
        public required string PhoneNumber { get; set; }
        public required string Email { get; set; }
        public string? Website { get; set; }
        public string? CuisineType { get; set; }
        public required string OpeningHours { get; set; }
        public DateTime? CreationDate { get; set; }
    }
    
    

    我已设法通过以下方法找到解决方案:使用 UpdateBarFromDto() 设置 id,以便数据库知道要更新哪个对象

    [Mapper]
    public partial class BarMapper
    {
    public partial Bar ToUpdateBar(UpdateBarDTO bar);
    public Bar UpdateBarFromDto(UpdateBarDTO updateBarDTO, Bar bar)
        {
            var dto = ToUpdateBar(updateBarDTO);
            dto.Id = bar.Id;
            return dto;
        }
    
    

    有效载荷:仅名称发生变化

    PUT <http://localhost:5294/bars/1>
    Content-Type: application/json
    
    {
        "Name": "Sunset Lounge Skyy",
        "Address": "123 Ocean Drive, Miami, FL 33139",
        "PhoneNumber": "305-555-1234",
        "Email": "[email protected]",
        "Website": "<http://www.sunsetlounge.com>",
        "CuisineType": "Seafood",
        "OpeningHours":"Monday: 10:00 AM - 11:00 PM,Tuesday: 10:00 AM - 11:00 PM,Wednesday: 10:00 AM - 11:00 PM,Thursday: 10:00 AM - 11:00 PM,Friday: 10:00 AM - 12:00 AM,Saturday: 10:00 AM - 12:00 AM,Sunday: 10:00 AM - 10:00 PM",
        "CreationDate": "2020-08-15T00:00:00"
    }
    
    

    控制器

    //PUT /bars/1
    group.MapPut("/{id}", async (int id, UpdateBarDTO updatedBar, ServitusDbContext dbContext) =>
    {
        var existingBar = await dbContext.Bars.FindAsync(id);
    
        if (existingBar is null)
            return Results.NotFound();
    
        //set the id of updatedBarDTO
        var bar = new BarMapper().UpdateBarFromDto(updatedBar, existingBar);
    
        //locate the bar you want to update, map it to DTO and set the values
        dbContext.Entry(existingBar)
                .CurrentValues
                .SetValues(bar);
    
        await dbContext.SaveChangesAsync();
    
        return Results.NoContent();
    });
    
    

    对于那些了解 AutoMapper 的人来说,我希望实现与此相同的效果:

    var bar = mapper.Map<UpdateBarDTO, Bar>(updatedBar, opt => opt.AfterMap((src, dest) => dest.Id = id));
    
    

    非常感谢!

返回
作者最近主题: