Javascript错误,无法获得所需的客户端ID父子层次结构 [英] Javascript Error getting the desired client ID Parent-Child Hierarchy

查看:60
本文介绍了Javascript错误,无法获得所需的客户端ID父子层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,开发人员,我要开发的页面是在gridview(grdCategory)里面有一个嵌套的用户控件.因此,我已经设法使用可以随时调用的Sub以编程方式绑定它(毫无疑问,毫无疑问).
使用Parent-child(usercontrol)层次结构,具有gridview的用户控件可响应grdCategory我的代码,如下所示

Hello fellow developer, the catch is I am developing a page wherein there is a nested user control inside my gridview(grdCategory). So Ive manage to bind it programically(woking no doubt) using Sub that I could call anytime.
Using Parent-child(usercontrol) hierarchy, the user control which has a gridview that respond on the ID of the grdCategory My code are as follows

Private Sub CreateCourseGrid(Optional ByVal parentIsPostBack As Boolean = False)
        For iCatRow As Integer = 0 To grdCategory.Rows.Count - 1
            Dim ccId As String = _
            DirectCast(grdCategory.Rows(iCatRow).Cells(1).FindControl("lblCourseCatIDMain"), Label).Text
            Dim year As String = drpdwnYear.Text
            Dim disciplineId As String = "0"

            _coursesdataDAL = New CoursesDataDAL
            Dim coursedata As New CoursesData
            coursedata.Year = year
            coursedata.CourseCatID = ccId
            coursedata.DisciplineID = disciplineId

            Dim pnlCourse As Panel = DirectCast(grdCategory.Rows(iCatRow).Cells(1).FindControl("pnlCourse"), Panel)
            Dim courseUC As CourseUserControl = LoadControl("~/CourseUserControl.ascx")
            courseUC.CData = coursedata
            courseUC.MyParent = CourseUserControl.ParentType.TrainingPlanTemplate
            'e.Row.Cells(1).Controls.Add(courseUC)
            pnlCourse.Controls.Add(courseUC)
        Next

    End Sub



所以我的错误在这里:
我创建了一个javascript:对我的gridview(grdCategory)的rowdatabound进行验证,该数据包含其模板内部的另一个clientID



So my error goes here:
I created a javascript: validate on rowdatabound of my gridview(grdCategory) that contains the other clientID that is inside of its template

Dim txtID As TextBox = DirectCast(e.Row.FindControl("txtCourseCatID"), TextBox)
            Dim txttry As TextBox = DirectCast(e.Row.FindControl("txtCourseCategory"), TextBox)
            Dim labeltry As Label = DirectCast(e.Row.FindControl("lbllastname"), Label)
            labeltry.Attributes.Add("onclick", "javascript:return validate('" + labeltry.ClientID + "','" + txttry.ClientID + "','" & txtID.ClientID & "')")



在我的客户端,这是我的代码



and on my client side here is my code

function validate(linkobj, textobj, labelobj) {
          var textme = document.getElementById('hidIsChildEditMode').value;
          textme = textme + 1
          document.getElementById('hidIsChildEditMode').value = textme
          if (textme == 11) {
              document.getElementById('ctl00_ContentPlaceHolder1_grdCategory_ctl02_ctl02_ButtonDELL').click();
              //alert("wew")
              var CategoryID = document.getElementById(labelobj).value;
              document.getElementById('<%= txt1.ClientID %>').value = CategoryID

              document.getElementById('hidlinkObj').value = linkobj;
              document.getElementById(linkobj).style.display = 'none';

              document.getElementById('hidtextObj').value = textobj;
              document.getElementById(textobj).style.display = 'inline';
          }
          else {
              document.getElementById(linkobj).style.display = 'inline';
              document.getElementById(textobj).style.display = 'none';
          }


      }


请注意,单击了一个buttonclickDELL,这非常重要,因为它在内部重新绑定了usercountrol. buttonDELL在用户控件内部,并声明为默认按钮,代码如下所示,位于我的用户控件的客户端


Note that there is a buttonclickDELL that is clicked which is really important since it rebinds the usercountrol inside. The buttonDELL is inside the usercontrol and declared as default button, Code are as follow on client side of my user control

<asp:Panel ID="Panel1" runat="server" DefaultButton="ButtonDELL">
    <asp:GridView ID="grdCourse" runat="server" Width="800px" HorizontalAlign="Center"

        AutoGenerateColumns="False" align="center" DataKeyNames="TrainingPlanID,CourseID"

        Font-Names="verdana,arial,helvetica,sans-serif" Font-Size="8pt" BackColor="White"

        GridLines="Vertical" OnRowCommand="grdCourse_RowCommand">
        <Columns>
            <asp:ButtonField Text="SingleClick" CausesValidation="false" CommandName="SingleClick"

                Visible="False" />
            <asp:TemplateField HeaderText="TrainingPlanID" SortExpression="TrainingPlanID" HeaderStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:Label ID="lblTrainingPlanID" runat="server" Text='<%# Eval("TrainingPlanID")%>'

                        Width="30px" Height="10px"> </asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Course Name" SortExpression="CourseName" HeaderStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:Label ID="lblCoursename" runat="server" Text='<%# Eval("CourseName")%>' Width="300px"

                        Height="10px"> </asp:Label>
                    <asp:TextBox ID="txtCourseName" runat="server" Text='<%# Bind("CourseName") %>' Font-Size="XX-Small"

                        Visible="false" Font-Names="Verdana" CausesValidation="false" OnTextChanged="txtCourseName_TextChanged"

                        Width="300px" ></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ErrorMessage="*"

                        ControlToValidate="txtCourseName" Font-Names="verdana" ForeColor="white" Font-Size="XX-Small"></asp:RequiredFieldValidator>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Course Code" HeaderStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:Label ID="lblCourseCode" Width="120px" runat="server" Text='<%# Eval("CourseCode")%>'

                        Height="10px"> </asp:Label>
                    <asp:TextBox ID="txtCourseCode" Width="120px" runat="server" Text='<%# Eval("CourseCode") %>'

                        Font-Size="XX-Small" Visible="false" Font-Names="Verdana" CausesValidation="false"

                        OnTextChanged="txtCourseName_TextChanged"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator100" runat="server" ErrorMessage="*"

                        ControlToValidate="txtCourseCode" Font-Names="verdana" ForeColor="white" Font-Size="XX-Small"></asp:RequiredFieldValidator>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Duration" HeaderStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:Label ID="lblDuration" Width="100px" runat="server" Text='<%# Eval("Duration")%>'

                        Height="10px"> </asp:Label>
                    <asp:TextBox ID="txtDuration" Width="100px" runat="server" CausesValidation="false"

                        OnTextChanged="txtCourseName_TextChanged" Text='<%# Eval("Duration")%>' Font-Size="XX-Small"

                        Visible="false" Font-Names="Verdana"></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtDuration"

                        Font-Names="verdana" ForeColor="white" Font-Size="XX-Small" ErrorMessage="No/Dec only"

                        ValidationExpression="(^\d*\.?\d*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$)"></asp:RegularExpressionValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"

                        ControlToValidate="txtDuration" Font-Names="verdana" ForeColor="white" Font-Size="XX-Small"></asp:RequiredFieldValidator>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Edit Detail" HeaderStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:ImageButton ID="EditDetail" Height="15px" ImageUrl="Images/edit2.png" runat="server"

                        CommandName="cmdlink" CommandArgument='<%# Eval("TrainingPlanID")%>' PostBackUrl='<%#"TrainingPlanDetails.aspx?TPID=" & Eval("TrainingPlanID")%>' />
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Delete" HeaderStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:ImageButton ID="ImageDeleteCourse" Height="15px" ImageUrl="Images/Delete.png"

                        runat="server" CommandName="cmdDelete" CommandArgument='<%# Eval("TrainingPlanID") + ";" + Eval("CourseID") %>'

                        OnClientClick="return confirm('Are you sure to delete this Course?')" /><!-- onclick="ImageDeleteCourse_Click" -->
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:CommandField ShowDeleteButton="True" />
            <asp:TemplateField HeaderText="DisciplineID" HeaderStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:Label ID="DisciplineCourseID" runat="server" Text='<%# Eval("DisciplineID")%>'

                        Height="10px"> </asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="EditCourse" HeaderStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:ImageButton ID="ImageEdit" Height="15px" ImageUrl="Images/edit.png" runat="server"

                        CommandName="cmdlink" CommandArgument='<%# Eval("TrainingPlanID")%>' />
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="CourseID" SortExpression="CourseID" HeaderStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:Label ID="lblCourseID" runat="server" Text='<%# Eval("CourseID")%>' Width="30px"

                        Height="10px"> </asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <RowStyle BackColor="White" ForeColor="#333333" />
        <FooterStyle BackColor="White" ForeColor="#333333" />
        <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
    </asp:GridView>
    <asp:Button ID="ButtonDELL" runat="server" Text="Button" style="display:none;" CausesValidation="false" CommandName="defaultButton"

         />
</asp:Panel>


So overall when I click the the label of my grdCategory it must change to textbox but before that the user control must rebind (in which case I use default button to rebind)
Here is my huge problem:
using the javascript validate when I add alert It is working fine but when I try to remove it, events turn out what I did not want to happen, that is client side first before server side. So reading my code I found out that the error occurs when the buttonDELL was clicked because it rebinds and I think it returns to his original state.
My trial is putting it to a hidden input field(hidlinkObj,hidtextObj) and call it on ButtonDELL_clicked on server side but nothing works.Can you help me sort this out?
My trial on ButtonDELL_clicked


So overall when I click the the label of my grdCategory it must change to textbox but before that the user control must rebind (in which case I use default button to rebind)
Here is my huge problem:
using the javascript validate when I add alert It is working fine but when I try to remove it, events turn out what I did not want to happen, that is client side first before server side. So reading my code I found out that the error occurs when the buttonDELL was clicked because it rebinds and I think it returns to his original state.
My trial is putting it to a hidden input field(hidlinkObj,hidtextObj) and call it on ButtonDELL_clicked on server side but nothing works.Can you help me sort this out?
My trial on ButtonDELL_clicked

Protected Sub ButtonDELL_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonDELL.Click
     ScriptManager.RegisterStartupScript(Me, Me.GetType, "Any", "document.getElementById('hidlinkObj').style.display = 'none';;", True)
     ScriptManager.RegisterStartupScript(Me, Me.GetType, "Any2", "document.getElementById(hidtextobj).style.display = 'inline';", True)
 End Sub

推荐答案

)|(^[1-9]+\d*\.\d*
)|(^[1-9]+\d*\.\d*


)"></asp:RegularExpressionValidator> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate =" txtDuration" Font-Names="verdana" ForeColor="white" Font-Size="XX-Small"></asp:RequiredFieldValidator> < /ItemTemplate > < /asp:TemplateField > <asp:TemplateField HeaderText="Edit Detail" HeaderStyle-HorizontalAlign="Left"> < ItemTemplate > < asp:ImageButton ID =" 高度 15px " ImageUrl Images/edit2.png" runat =" CommandName="cmdlink" CommandArgument='<%# Eval("TrainingPlanID")%>' PostBackUrl='<%#"TrainingPlanDetails.aspx?TPID=" & Eval(" )%> ' / > < /ItemTemplate > < ItemStyle =" Center" / < /asp:TemplateField > < asp:TemplateField HeaderText =" HeaderStyle-Horizo​​ntalAlign 左" > < ItemTemplate > < asp:ImageButton ID =" 高度 15px " ImageUrl Images/Delete.png" 符文 =" CommandName="cmdDelete" CommandArgument='<%# Eval("TrainingPlanID") + ";" + Eval("CourseID") %>' span> OnClientClick =" return confirm('Are you sure to delete this Course?')" /><!-- onclick="ImageDeleteCourse_Click" --> < /ItemTemplate > < ItemStyle =" Center" / < /asp:TemplateField > < asp:CommandField ShowDeleteButton =" / < asp:TemplateField HeaderText =" HeaderStyle-Horizo​​ntalAlign 左" > < ItemTemplate > < asp:Label ID =" runat 服务器" 文本 <%#Eval(" )%> ' span> 高度 =" > </asp:Label> < /ItemTemplate > < /asp:TemplateField > < asp:TemplateField HeaderText =" HeaderStyle-Horizo​​ntalAlign 左" > < ItemTemplate > < asp:ImageButton ID =" 高度 15px " ImageUrl 图片/edit.png" runat =" CommandName="cmdlink" CommandArgument='<%# Eval("TrainingPlanID")%>' /> < /ItemTemplate > < ItemStyle =" Center" / < /asp:TemplateField > <asp:TemplateField HeaderText="CourseID" SortExpression="CourseID" HeaderStyle-HorizontalAlign="Left"> < ItemTemplate > <asp:Label ID="lblCourseID" runat="server" Text='<%# Eval("CourseID")%>' Width="30px" span> 高度 =" > </asp:Label> < /ItemTemplate > < /asp:TemplateField > < /列 > < RowStyle =" 白色" ForeColor >#333333" / > < FooterStyle =" 白色" ForeColor >#333333" / > < PagerStyle =" #336666" ForeColor 白色" Horizo​​ntalAlign =" 居中" / < SelectedRowStyle =" #339966" 字体粗体 True" ForeColor =" 白色" / > < HeaderStyle =" #336666" 字体粗体 True" ForeColor =" 白色" / > < /asp:GridView > <asp:Button ID="ButtonDELL" runat="server" Text="Button" style="display:none;" CausesValidation="false" CommandName="defaultButton" span> / < /asp:Panel >
)"></asp:RegularExpressionValidator> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtDuration" Font-Names="verdana" ForeColor="white" Font-Size="XX-Small"></asp:RequiredFieldValidator> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Edit Detail" HeaderStyle-HorizontalAlign="Left"> <ItemTemplate> <asp:ImageButton ID="EditDetail" Height="15px" ImageUrl="Images/edit2.png" runat="server" CommandName="cmdlink" CommandArgument='<%# Eval("TrainingPlanID")%>' PostBackUrl='<%#"TrainingPlanDetails.aspx?TPID=" & Eval("TrainingPlanID")%>' /> </ItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> <asp:TemplateField HeaderText="Delete" HeaderStyle-HorizontalAlign="Left"> <ItemTemplate> <asp:ImageButton ID="ImageDeleteCourse" Height="15px" ImageUrl="Images/Delete.png" runat="server" CommandName="cmdDelete" CommandArgument='<%# Eval("TrainingPlanID") + ";" + Eval("CourseID") %>' OnClientClick="return confirm('Are you sure to delete this Course?')" /><!-- onclick="ImageDeleteCourse_Click" --> </ItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> <asp:CommandField ShowDeleteButton="True" /> <asp:TemplateField HeaderText="DisciplineID" HeaderStyle-HorizontalAlign="Left"> <ItemTemplate> <asp:Label ID="DisciplineCourseID" runat="server" Text='<%# Eval("DisciplineID")%>' Height="10px"> </asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="EditCourse" HeaderStyle-HorizontalAlign="Left"> <ItemTemplate> <asp:ImageButton ID="ImageEdit" Height="15px" ImageUrl="Images/edit.png" runat="server" CommandName="cmdlink" CommandArgument='<%# Eval("TrainingPlanID")%>' /> </ItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> <asp:TemplateField HeaderText="CourseID" SortExpression="CourseID" HeaderStyle-HorizontalAlign="Left"> <ItemTemplate> <asp:Label ID="lblCourseID" runat="server" Text='<%# Eval("CourseID")%>' Width="30px" Height="10px"> </asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <RowStyle BackColor="White" ForeColor="#333333" /> <FooterStyle BackColor="White" ForeColor="#333333" /> <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" /> </asp:GridView> <asp:Button ID="ButtonDELL" runat="server" Text="Button" style="display:none;" CausesValidation="false" CommandName="defaultButton" /> </asp:Panel>


So overall when I click the the label of my grdCategory it must change to textbox but before that the user control must rebind (in which case I use default button to rebind)
Here is my huge problem:
using the javascript validate when I add alert It is working fine but when I try to remove it, events turn out what I did not want to happen, that is client side first before server side. So reading my code I found out that the error occurs when the buttonDELL was clicked because it rebinds and I think it returns to his original state.
My trial is putting it to a hidden input field(hidlinkObj,hidtextObj) and call it on ButtonDELL_clicked on server side but nothing works.Can you help me sort this out?
My trial on ButtonDELL_clicked


So overall when I click the the label of my grdCategory it must change to textbox but before that the user control must rebind (in which case I use default button to rebind)
Here is my huge problem:
using the javascript validate when I add alert It is working fine but when I try to remove it, events turn out what I did not want to happen, that is client side first before server side. So reading my code I found out that the error occurs when the buttonDELL was clicked because it rebinds and I think it returns to his original state.
My trial is putting it to a hidden input field(hidlinkObj,hidtextObj) and call it on ButtonDELL_clicked on server side but nothing works.Can you help me sort this out?
My trial on ButtonDELL_clicked

Protected Sub ButtonDELL_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonDELL.Click
     ScriptManager.RegisterStartupScript(Me, Me.GetType, "Any", "document.getElementById('hidlinkObj').style.display = 'none';;", True)
     ScriptManager.RegisterStartupScript(Me, Me.GetType, "Any2", "document.getElementById(hidtextobj).style.display = 'inline';", True)
 End Sub


这篇关于Javascript错误,无法获得所需的客户端ID父子层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆