Click to See Complete Forum and Search --> : datagrid linkbutton will not fire Postback at random times
bsinclair
May 19th, 2005, 04:11 PM
I have a simple linkbutton in a datagrid that works 99.99% of the time. At random times (4 times in the past year) with non-specific data records, a javascript error appears within a simply formatCurrency function and the Postback from the Linkbutton no longer fires. A view source reveals completely valid javascript, matching exactly what is there when the problem does not appear. Does .NET interfer with custom written Javascript, and if so, how can I possibly troubleshoot this?
bsinclair
May 23rd, 2005, 04:26 PM
Here is the code that is having this "random" issue
This is what is in the .ascx file:
<asp:DataGrid id="dgSchwabMFLineItems" Runat="server" Width="100%" ShowHeader="True" GridLines="Horizontal" AutoGenerateColumns="False">
<HeaderStyle CssClass="dgHeaderLeft"></HeaderStyle>
<ItemStyle cssclass="dgCell"></ItemStyle>
<AlternatingItemStyle cssclass="dgAltCell"></AlternatingItemStyle>
<Columns>
<asp:TemplateColumn HeaderText="Lots" HeaderStyle-CssClass="dgHeaderCenter">
<ItemStyle CssClass="lot" HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="lbtnMFdgLots" Runat="server" CssClass="lot" CausesValidation="False" CommandName="Lots" text='<%# Container.DataItem("Lots")%>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Created Date" HeaderStyle-CssClass="dgHeaderLeft">
<ItemStyle cssclass="dgCellLeft"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblMFdgCreateDate" Runat="server" text='<%# FormatDate(Container.DataItem("CreateDate"))%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
cmiskow
May 23rd, 2005, 05:17 PM
Might help to see the code from the formatCurrency function and the code you use to handle the click event.
bsinclair
May 24th, 2005, 09:21 AM
Thanks for the response...
The code for the click event is:
Private Sub dgSCHWMFLineItems_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgSCHWMFLineItems.ItemCommand
Try
If e.CommandName = "Lots" Then
Dim intLineItemID As Integer
Dim lbl As Label
Dim lblN As Label
lbl = e.Item.FindControl("lblMFdgSymbol")
lblN = e.Item.FindControl("lblMFdgSymbolName")
intLineItemID = CInt(dgSCHWMFLineItems.DataKeys(e.Item.ItemIndex).ToString)
Dim strPage As String = "ReferenceLots.aspx?IID=" & intLineItemID & "&LotType=Ref&SymbolCode=" & lbl.Text & "&WSID=" & clsWS.WorksheetID & "&SName=" & lblN.Text
Dim strWinParams As String = "'height=300,width=700,left=50,top=50,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no'"
Response.Write(Library.Common.OpenPopUp(strPage, strWinParams))
End If
Catch exErr As Exception
ShowErrorMessage(exErr)
End Try
End Sub
Javascript included with the page:
<script language="javascript" type="text/javascript">
function formatCurrency(element)
{
var wd
wd="wholenumber"
var tempnum
var x
// Get the value from the element.
var tempnum=element.value
// Remove formatting.
tempnum = tempnum.replace(",", "")
tempnum = tempnum.replace(",", "")
tempnum = tempnum.replace(",", "")
// validate tempnum
if ( isNaN(tempnum) )
{
alert("Please enter a valid number.");
element.value = ""
element.focus()
return;
}
// Check for decimal point in the value
for (i=0;i<tempnum.length;i++)
{
if (tempnum.charAt(i)==".")
{
wd="decimal"
x=tempnum.length-i
break
}
else
{
x=0
}
}
// Convert int to string.
tempnum = tempnum + '';
// commas
if (tempnum.length < 3+x)
{
// no commas needed.
//element.value = prefix + tempnum; TIM COMMENT OUT
element.value = tempnum;
return
}
else
{
// Add commas
for (i=3+x; i<tempnum.length;i=i+4)
{
before = tempnum
after = tempnum
before = before.substring(0, tempnum.length - i)
after = after.substring(tempnum.length - i, tempnum.length)
tempnum = before + "," + after
}
}
//element.value = prefix + tempnum; TIM COMMENT OUT
element.value = tempnum;
}
</script>
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.