Datagrid disappearing - client side coding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sue

    Datagrid disappearing - client side coding

    I have a datagrid populated with 6 visible read-only
    labels and several hidden fields. Below the datagrid, I
    have a table with various textboxes, dropdowns, etc. I've
    managed to decypher the client-side coding needed for the
    user to click a "select" button (HTMLButton) in column 0
    of the datagrid and have the table objects auto-fill with
    corresponding values from the dataset row in the datagrid
    without making a roundtrip to the server.

    I am trying to add code in the datagrid's itemdatabound to
    allow the user to click any place in a row and have
    the "onclick" client-side button code fire. I've been
    looking at Page.GetPostBac kClientHyperlin k, however I'm
    not using a hyperlink button, and when I click anywhere on
    the datagrid, it disappears, leaving only the table.

    Any ideas on why this is munching my datagrid? Or how to
    fix this so it works?

    tia,
    Sue
  • Jeffrey Tan[MSFT]

    #2
    RE: Datagrid disappearing - client side coding


    Hi Sue,

    Thanks for posting in this group.
    I think there are several unclear place in your statement.
    You want: the table objects auto-fill with corresponding values from the
    dataset row in the datagrid without making a roundtrip to the server in the
    client button_click event.
    But actually, dataset is an object of server side, how can you get the
    server side dataset value in client button_click event without roundtrip to
    server?
    Also, datagrid's itemdatabound event is also the server side event.

    I think you need explain your solution more clear to us, so that we can
    help you well.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.

    Comment

    • Guest's Avatar

      #3
      RE: Datagrid disappearing - client side coding

      Hi - sorry for the confusion - I was brain dead by the
      time I posted this. Hopefully this will make more sense
      (code below).

      I have an .aspx page containing a datagrid (DG) and a
      table below (DetailTable). The datagrid is populated
      from a dataset created from a SQLServer database. There
      are several hidden fields in the datagrid in
      addition to the fields displayed. When the user clicks
      the "select" button, client side script grabs
      all the fields from the datarow and populates the
      corresponding fields in the detail table below the
      datagrid. The users are at a remote site on the far side
      of a very slow LAN line and I am trying to
      avoid as many round-trips to the server as I can because
      of this.

      If I leave the "select" button visible in the datagrid,
      and the user clicks it, the detail table below
      is quickly updated with the datagrid row's info. I would
      like to hide the select button (need more screen
      real estate), and allow the user to click anywhere in a
      row and have the detail table below update as
      it does when the select button is clicked. I've adapted
      code from an example in MSDN to do this,
      but when I click on a datagrid row, the detail table
      doesn't update, and the datagrid drops out of the
      HTML page leaving only the detail table. It's this problem
      I'm trying to understand and fix.

      Does this help? Any ideas or suggestions?

      tia,
      Sue

      in code-behind page

      Private Sub Page_Load(ByVal sender As System.Object, ByVal
      e As System.EventArg s) Handles MyBase.Load
      If Not IsPostBack Then
      Me.cn.Connectio nString =
      ConfigurationSe ttings.AppSetti ngs("Connection String")
      DA = New SqlClient.SqlDa taAdapter("sele ct * from
      applicationview order by name", cn)
      Me.DS.DataSetNa me = "DS"
      Me.DA.Fill(Me.D S)
      cn.close
      ' dg is the datagrid object
      dg.databind()
      Call ClientScript(se nder, e)
      Else
      Page.DataBind()
      End If
      End Sub


      Private Sub ClientScript(By Val sender As Object, ByVal e
      As EventArgs)
      Me.ClientScript String = "<script language=VBScri pt>"
      & vbCrLf _
      & " sub FillDetailTable (AppID, CaseNo, CaseType,
      MyName, MyDate, MyStatus, Verifier, EvaluatedVerifi ed,
      Recommendation, FeeRecommendati on,
      ContributionRec ommendation,
      ContributionAmo untRecommendati on, HearingRequeste d,
      HearingDecision , FeeOrdered, ContributionOrd ered,
      ContributionAmo untOrdered, Adjudication) " & vbCrLf _
      & " document.all(" & Chr(34) & "DTTableHea der" & Chr
      (34) & ").innertex t = AppID " & vbCrLf _
      ...<snip>...
      & " end sub " & vbCrLf & "<" _
      & "/" _
      & "script>"

      If (Not IsClientScriptB lockRegistered
      ("FillDetailTab le")) Then
      RegisterClientS criptBlock("Fil lDetailTable",
      ClientScriptStr ing)
      End If
      End Sub

      Private Sub DG_ItemDataBoun d(ByVal source As Object, ByVal
      e As System.Web.UI.W ebControls.Data GridItemEventAr gs)
      Handles DG.ItemDataBoun d
      If e.Item.ItemType = ListItemType.It em Or
      e.Item.ItemType = ListItemType.Al ternatingItem Then

      Dim b As HtmlControls.Ht mlInputButton
      b = CType(e.Item.Ce lls(0).Controls (1),
      HtmlControls.Ht mlInputButton)

      b.Attributes.Ad d("onclick", "FillDetailTabl e('" _
      & GetTableHeader( Trim(e.Item.Cel ls(1).Text))
      & "','" _
      & GetTextBox(Trim (e.Item.Cells(2 ).Text)) & "','" _
      & GetDropDownInde x("CaseType", Trim(e.Item.Cel ls
      (3).Text)) & "','" _
      <snip>
      e.Item.Cells(1) .Attributes("on click") =
      Page.GetPostBac kClientHyperlin k(b, "onclick")
      e.Item.Cells(2) .Attributes("on click") =
      Page.GetPostBac kClientHyperlin k(b, "onclick")
      e.Item.Cells(3) .Attributes("on click") =
      Page.GetPostBac kClientHyperlin k(b, "onclick")
      e.Item.Cells(4) .Attributes("on click") =
      Page.GetPostBac kClientHyperlin k(b, "onclick")
      <snip>
      End If
      End Sub

      on .aspx page

      <%@ Page Language="vb" AutoEventWireup ="false"
      trace="True" Codebehind="def ault.aspx.vb"
      Inherits="indig entverification .indigentverifi cation._defaul
      t"%>
      <snip>
      <HTML>
      <snip>
      <form id="ThisForm" runat="server">
      <asp:datagrid id="DG" runat="server">
      <Columns>
      <asp:TemplateCo lumn>
      <ItemTemplate >
      <INPUT id="SelectButto n" runat="server"
      type="button" value="Select" NAME="SelectBut ton">
      </ItemTemplate>
      </asp:TemplateCol umn>
      <asp:boundcolum n HeaderText="App ID"
      SortExpression= "App ID" DataField="AppI D"
      ReadOnly="True" />
      <asp:BoundColum n Headertext="Cas e No"
      SortExpression= "CaseNo" DataField="Case No"
      ReadOnly="True" />
      <snip>
      <asp:boundcolum n
      DataField="Cont ributionAmountO rdered" Visible="False" />
      <asp:BoundColum n DataField="Ajud ication"
      Visible="False" />
      </Columns>
      </asp:datagrid>

      <table id="DetailTable " runat="server">
      <tr>
      <td colspan="6" align="center"
      bgcolor="Midnig htBlue"><asp:La bel ID="DTTableHead er"
      runat="server" /></td>
      </tr>
      <tr>
      <td width="12%" class="xxsmall" >Case No:</td>
      <td><asp:textbo x id="DTCaseNoTex tBox"
      Runat="server" /></td>
      <td width="12%" class="xxsmall" >Case Type:</td>
      <td><asp:dropdo wnlist id="DTCaseTypeD ropDown"
      Runat="Server" /></td>
      <td width="12%" class="xxSmall" >Name:</td>
      <td><asp:textbo x id="DTNameTextB ox"
      runat="server" /></td>
      </tr>
      <tr>
      <td class="xxsmall" >Date:</td>
      <td><asp:textbo x id="DTDateTextB ox"
      Runat="server" /></td>
      <td class="xxsmall" >Status:</td>
      <td><asp:dropdo wnlist id="DTStatusDro pDown"
      Runat="server" /></td>
      <td class="xxsmall" >Verifier:</td>
      <td><asp:dropdo wnlist id="DTVerifierD ropDown"
      Runat="server" /></td>
      </tr>
      <tr>
      <snip>
      <td align="center" colSpan="3"><as p:button
      id="DTSaveButto n" Runat="server" CssClass="Butto n" /></td>
      </tr>
      </table>
      </form>
      </body>
      </HTML>

      Comment

      • Jeffrey Tan[MSFT]

        #4
        RE: Datagrid disappearing - client side coding


        Hi,

        Thanks for your feedback.
        Based on your statement, you have succeeded get this done in select
        button's client side click event.
        In your code, I see that you register datagrid row's onclick event with
        onclick method(Client side). I think first, you should check whether your
        registered client side onclick method is called when clicking the datagrid
        row.
        If your datagrid row click can trigger the client side onclick method, I
        think you can succeed invoke the same code as select button's to fill the
        table.

        Hope this helps,
        Best regards,
        Jeffrey Tan
        Microsoft Online Partner Support
        Get Secure! - www.microsoft.com/security
        This posting is provided "as is" with no warranties and confers no rights.

        Comment

        • Jeffrey Tan[MSFT]

          #5
          RE: Datagrid disappearing - client side coding


          Hi,

          Thanks for your feedback.
          Based on your statement, you have succeeded get this done in select
          button's client side click event.
          In your code, I see that you register datagrid row's onclick event with
          onclick method(Client side). I think first, you should check whether your
          registered client side onclick method is called when clicking the datagrid
          row.
          If your datagrid row click can trigger the client side onclick method, I
          think you can succeed invoke the same code as select button's to fill the
          table.

          Hope this helps,
          Best regards,
          Jeffrey Tan
          Microsoft Online Partner Support
          Get Secure! - www.microsoft.com/security
          This posting is provided "as is" with no warranties and confers no rights.

          Comment

          • Sue

            #6
            RE: Datagrid disappearing - client side coding

            check whether your[color=blue]
            >registered client side onclick method is called when[/color]
            clicking the datagrid[color=blue]
            >row.
            >If your datagrid row click can trigger the client side[/color]
            onclick method, I[color=blue]
            >think you can succeed invoke the same code as select[/color]
            button's to fill the[color=blue]
            >table.[/color]

            The onclick method fires just fine when clicking the
            Select button. The onclick method isn't called when
            clicking anywhere else in the datarow. And, of course,
            there's no way to step through client-side script (is
            there?) to see what's happening, or not happening. Any
            suggestions on where to look for what's missing?

            tia,
            Sue

            Comment

            • Jeffrey Tan[MSFT]

              #7
              RE: Datagrid disappearing - client side coding


              Hi Sue,

              You can debug the client side script through Microsoft Script debugger, the
              article below tells you how to debug client side script:
              Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.


              In your application, you associate the select button's click event with
              datagrid row's click event through:
              e.Item.Cells(1) .Attributes("on click") =
              Page.GetPostBac kClientHyperlin k(b, "onclick")
              e.Item.Cells(2) .Attributes("on click") =
              Page.GetPostBac kClientHyperlin k(b, "onclick")
              e.Item.Cells(3) .Attributes("on click") =
              Page.GetPostBac kClientHyperlin k(b, "onclick")
              e.Item.Cells(4) .Attributes("on click") =
              Page.GetPostBac kClientHyperlin k(b, "onclick")
              I think you'd better check if the return of
              Page.GetPostBac kClientHyperlin k(b, "onclick") is the correct client script.

              Hope this helps,

              Best regards,
              Jeffrey Tan
              Microsoft Online Partner Support
              Get Secure! - www.microsoft.com/security
              This posting is provided "as is" with no warranties and confers no rights.

              Comment

              • Sue

                #8
                RE: Datagrid disappearing - client side coding

                >You can debug the client side script through Microsoft
                Script debugger, the

                Ok, script debugger leads me through several validator
                scripts which "die" at: function anonymous()
                Validator.OnCha nge() end function, at which point I get
                dumped back on my web page sans the datagrid. I abandoned
                trying to get "click anywhere on row" to work and now this
                is happening when I click on my select button (which has
                now been changed to a linkbutton to virtually duplicate
                the MSDN article example). Not knowing the underpinings of
                the system supplied functions used in validations, why and
                what "anonymous( )" is supposed to do is a mystery to me.
                Any suggestions now?

                Sue

                Comment

                • Jeffrey Tan[MSFT]

                  #9
                  RE: Datagrid disappearing - client side coding


                  Hi Sue,

                  Based on my understanding, I think during your client script trace, you
                  find there are "automated" client validation code generated( function
                  anonymous() Validator.OnCha nge() end function).

                  It seems that Asp.net will generate client validation script code for your
                  onchange event.

                  Using a custom validation control is generally the safest approach. Add a
                  custom validation control which is not linked to any controlView the page
                  in HTML view and make sure that this custom validation control is LAST.
                  Then it will be the last control added the array of validation controls and
                  will be the last one to be evaluated.

                  This may workaround your problem.

                  Best regards,
                  Jeffrey Tan
                  Microsoft Online Partner Support
                  Get Secure! - www.microsoft.com/security
                  This posting is provided "as is" with no warranties and confers no rights.

                  Comment

                  Working...