Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > doesn't doPostBack,is it a vs2005 bug ???

Reply
Thread Tools

doesn't doPostBack,is it a vs2005 bug ???

 
 
ead_no1 ead_no1 is offline
Junior Member
Join Date: Oct 2006
Posts: 2
 
      10-21-2006
Hi all...
I've been messing around with the __doPostBack for a while - under asp.net 2.0
what I have is a gridview that whenever a line is pressed it postback with
a few functions that all run well before the postback.
when I had a control that asp.net compiler enter an automatic __dopostback I can't seem to hijack it - it just doesn't send the right data - it always
seems to go to asp's function last...

code :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<style type="text/css">
.normalrow
{
background-color:#ffffff;
}

.selectedrow
{
background-color:#ff0022;
}
</style>
<script language="javascript" type="text/javascript">
var gridViewCtlId = '<%=ctlGridView.ClientID%>';
var gridViewCtl = null;
var curSelRow = null;





function getGridViewControl()
{
if (null == gridViewCtl)
{
gridViewCtl = document.getElementById(gridViewCtlId);
}
}

var __oldDoPostBack = null
function onGridViewRowSelected(rowIdx)
{

__oldDoPostBack = __doPostBack; var selRow = getSelectedRow(rowIdx);
if (curSelRow != null)
{
curSelRow.style.backgroundColor = '#ffffff';
}

if (null != selRow)
{
curSelRow = selRow;
curSelRow.style.backgroundColor = '#ff0022';
}
// __doPostBack = AlwaysFireBeforeFormSubmit(gridViewCtl,rowIdx,__ol dDoPostBack);
return __oldDoPostBack(gridViewCtl,rowIdx);
}

function AlwaysFireBeforeFormSubmit (eventTarget, eventArgument,postback) {
// var __oldDoPostBack = __doPostBack;
return postback (eventTarget, eventArgument);

}


function getSelectedRow(rowIdx)
{
getGridViewControl();
if (null != gridViewCtl)
{
return gridViewCtl.rows[rowIdx];
}
return null;
}
</script>
<script language="javascript" type="text/javascript">
function __doPostBack(eventTarget, eventArgument) {
if (theForm.onsubmit == null || theForm.onsubmit()) {
var theform = document.form1;
theform.__EVENTTARGET.value = eventTarget;
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
}

</script>
</head>

<body>
<form id="form1" runat="server">
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<div>
<asp:GridView ID="ctlGridView" runat="server" OnRowCreated="OnRowCreated">
<selectedrowstyle backcolor="#FFFFC0" />
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
<asp:GridView ID="GridView1" runat="server" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display." ForeColor="Black" GridLines="None">
<FooterStyle BackColor="Tan" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:YekevConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:YekevConnectionString1.ProviderN ame %>" SelectCommand="SELECT * FROM [Stock_General]">
</asp:SqlDataSource>
&nbsp;
</div>
</form>
</body>
</html>


The codebehind :

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page
{
private DataSet m_dsProducts;
private Int32 m_iRowIdx;

protected void Page_Load(object sender, EventArgs e)
{
getProducts();
if (!IsPostBack)
{
bindGridView();
}
else
{
object obTarget = this.Request.Form["__EVENTTARGET"];
object obArg = this.Request.Form["__EVENTARGUMENT"];
if (null != obArg)
{
// int rowIdx = Int32.Parse(obArg.ToString());
// OnRowSelected(rowIdx);
}
}
}

#region GridView Methods
#region Data Binding
private void bindGridView()
{
ctlGridView.DataSource = m_dsProducts;
ctlGridView.DataBind();
}
#endregion

#region Event Handlers
protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "onGridViewRowSelected('" + m_iRowIdx.ToString() + "')");
}
m_iRowIdx++;
}

protected void OnRowSelected(Int32 iRowIdx)
{

}
#endregion
#endregion

#region Data Methods
private void getProducts()
{
if (!IsPostBack)
{
m_dsProducts = new DataSet();
SqlDataAdapter adpter=new SqlDataAdapter();
SqlConnection con=new SqlConnection();
con.ConnectionString=SqlDataSource1.ConnectionStri ng;
SqlCommand cmd = new SqlCommand(SqlDataSource1.SelectCommand.ToString() , con);
adpter.SelectCommand = cmd;
adpter.Fill(m_dsProducts, "Stock_General");
Session["_Products_Set_"] = m_dsProducts;
}
else
{
m_dsProducts = Session["_Products_Set_"] as DataSet;
}
}
#endregion
protected void Button1_Click(object sender, EventArgs e)
{

}
}


must of the code can be disregarded - the problem occurs
in the Page_load (When to postback happens)
the EVENTTARGET & EVENTARGU don't get the right values...
what Can I DO???
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
Bug in VS2005 Beta 2? John ASP .Net 4 07-21-2006 06:52 PM
VS2005 - DefaultValuesNeeded - bug? Adding default values in DataGridView dbuchanan ASP .Net 7 05-23-2006 05:09 PM
bug in vs2005 for asp .net 2.0 ? Carlos ASP .Net 3 11-19-2005 01:42 PM
VS2005 Report Viewer bug Chris Botha ASP .Net 3 11-07-2005 11:31 PM



Advertisments