Datagrid disappearing - client side coding

  • Thread starter Thread starter Sue
  • Start date Start date
S

Sue

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.GetPostBackClientHyperlink, 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
 
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.
 
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.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Me.cn.ConnectionString =
ConfigurationSettings.AppSettings("ConnectionString")
DA = New SqlClient.SqlDataAdapter("select * from
applicationview order by name", cn)
Me.DS.DataSetName = "DS"
Me.DA.Fill(Me.DS)
cn.close
' dg is the datagrid object
dg.databind()
Call ClientScript(sender, e)
Else
Page.DataBind()
End If
End Sub


Private Sub ClientScript(ByVal sender As Object, ByVal e
As EventArgs)
Me.ClientScriptString = "<script language=VBScript>"
& vbCrLf _
& " sub FillDetailTable(AppID, CaseNo, CaseType,
MyName, MyDate, MyStatus, Verifier, EvaluatedVerified,
Recommendation, FeeRecommendation,
ContributionRecommendation,
ContributionAmountRecommendation, HearingRequested,
HearingDecision, FeeOrdered, ContributionOrdered,
ContributionAmountOrdered, Adjudication) " & vbCrLf _
& " document.all(" & Chr(34) & "DTTableHeader" & Chr
(34) & ").innertext = AppID " & vbCrLf _
...<snip>...
& " end sub " & vbCrLf & "<" _
& "/" _
& "script>"

If (Not IsClientScriptBlockRegistered
("FillDetailTable")) Then
RegisterClientScriptBlock("FillDetailTable",
ClientScriptString)
End If
End Sub

Private Sub DG_ItemDataBound(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataGridItemEventArgs)
Handles DG.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or
e.Item.ItemType = ListItemType.AlternatingItem Then

Dim b As HtmlControls.HtmlInputButton
b = CType(e.Item.Cells(0).Controls(1),
HtmlControls.HtmlInputButton)

b.Attributes.Add("onclick", "FillDetailTable('" _
& GetTableHeader(Trim(e.Item.Cells(1).Text))
& "','" _
& GetTextBox(Trim(e.Item.Cells(2).Text)) & "','" _
& GetDropDownIndex("CaseType", Trim(e.Item.Cells
(3).Text)) & "','" _
<snip>
e.Item.Cells(1).Attributes("onclick") =
Page.GetPostBackClientHyperlink(b, "onclick")
e.Item.Cells(2).Attributes("onclick") =
Page.GetPostBackClientHyperlink(b, "onclick")
e.Item.Cells(3).Attributes("onclick") =
Page.GetPostBackClientHyperlink(b, "onclick")
e.Item.Cells(4).Attributes("onclick") =
Page.GetPostBackClientHyperlink(b, "onclick")
<snip>
End If
End Sub

on .aspx page

<%@ Page Language="vb" AutoEventWireup="false"
trace="True" Codebehind="default.aspx.vb"
Inherits="indigentverification.indigentverification._defaul
t"%>
<snip>
<HTML>
<snip>
<form id="ThisForm" runat="server">
<asp:datagrid id="DG" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<INPUT id="SelectButton" runat="server"
type="button" value="Select" NAME="SelectButton">
</ItemTemplate>
</asp:TemplateColumn>
<asp:boundcolumn HeaderText="App ID"
SortExpression="App ID" DataField="AppID"
ReadOnly="True" />
<asp:BoundColumn Headertext="Case No"
SortExpression="CaseNo" DataField="CaseNo"
ReadOnly="True" />
<snip>
<asp:boundcolumn
DataField="ContributionAmountOrdered" Visible="False" />
<asp:BoundColumn DataField="Ajudication"
Visible="False" />
</Columns>
</asp:datagrid>

<table id="DetailTable" runat="server">
<tr>
<td colspan="6" align="center"
bgcolor="MidnightBlue"><asp:Label ID="DTTableHeader"
runat="server" /></td>
</tr>
<tr>
<td width="12%" class="xxsmall">Case No:</td>
<td><asp:textbox id="DTCaseNoTextBox"
Runat="server" /></td>
<td width="12%" class="xxsmall">Case Type:</td>
<td><asp:dropdownlist id="DTCaseTypeDropDown"
Runat="Server" /></td>
<td width="12%" class="xxSmall">Name:</td>
<td><asp:textbox id="DTNameTextBox"
runat="server" /></td>
</tr>
<tr>
<td class="xxsmall">Date:</td>
<td><asp:textbox id="DTDateTextBox"
Runat="server" /></td>
<td class="xxsmall">Status:</td>
<td><asp:dropdownlist id="DTStatusDropDown"
Runat="server" /></td>
<td class="xxsmall">Verifier:</td>
<td><asp:dropdownlist id="DTVerifierDropDown"
Runat="server" /></td>
</tr>
<tr>
<snip>
<td align="center" colSpan="3"><asp:button
id="DTSaveButton" Runat="server" CssClass="Button" /></td>
</tr>
</table>
</form>
</body>
</HTML>
 
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.
 
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.

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
 
Hi Sue,

You can debug the client side script through Microsoft Script debugger, the
article below tells you how to debug client side script:
http://support.microsoft.com/?id=317699

In your application, you associate the select button's click event with
datagrid row's click event through:
e.Item.Cells(1).Attributes("onclick") =
Page.GetPostBackClientHyperlink(b, "onclick")
e.Item.Cells(2).Attributes("onclick") =
Page.GetPostBackClientHyperlink(b, "onclick")
e.Item.Cells(3).Attributes("onclick") =
Page.GetPostBackClientHyperlink(b, "onclick")
e.Item.Cells(4).Attributes("onclick") =
Page.GetPostBackClientHyperlink(b, "onclick")
I think you'd better check if the return of
Page.GetPostBackClientHyperlink(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.
 
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.OnChange() 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
 
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.OnChange() 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.
 
Back
Top