Current location: Hot Scripts Forums » Programming Languages » ASP.NET » datagrid linkbutton won't fire Postback randomly


datagrid linkbutton won't fire Postback randomly

Reply
  #1 (permalink)  
Old 05-23-05, 03:43 PM
bsinclair bsinclair is offline
New Member
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
datagrid linkbutton won't fire Postback randomly

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?

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>

I can't imagine this being the issue. Nearly identical (name changes only difference) code executes in a parallel page without ever having an issue.

I'm new to the forum world. Any help is much appreciated.

Thanks
Reply With Quote
  #2 (permalink)  
Old 05-24-05, 08:32 AM
bsinclair bsinclair is offline
New Member
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Additional Code

I figured I should probably include the click event handler and the javascript...

The code for the click event is:

Private Sub dgSchwabMFLineItems_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dgSchwabMFLineItems.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(dgSchwabMFLineItems.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 = 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 = tempnum;
}
</script>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 01:01 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.