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

Discussion in 'Software' started by ead_no1, Oct 21, 2006.

  1. ead_no1

    ead_no1

    Joined:
    Oct 21, 2006
    Messages:
    1
    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???
     
    ead_no1, Oct 21, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nitinnikam

    login control in vs2005

    nitinnikam, Oct 30, 2006, in forum: Software
    Replies:
    0
    Views:
    742
    nitinnikam
    Oct 30, 2006
  2. Anthony LaMark

    vs2005 64-bit platformsdk issue

    Anthony LaMark, Mar 23, 2006, in forum: Windows 64bit
    Replies:
    2
    Views:
    749
    Anthony LaMark
    Mar 23, 2006
  3. Sergey Kashyrin

    VS2005 x64 VC++ codegen BUG

    Sergey Kashyrin, Mar 29, 2006, in forum: Windows 64bit
    Replies:
    4
    Views:
    495
    Jochen Kalmbach [MVP]
    Mar 29, 2006
  4. =?Utf-8?B?VmVjdG9ycng3?=

    Publishing VS2005 websites to Windows 2003R2 64bit OS

    =?Utf-8?B?VmVjdG9ycng3?=, Oct 2, 2007, in forum: Windows 64bit
    Replies:
    0
    Views:
    427
    =?Utf-8?B?VmVjdG9ycng3?=
    Oct 2, 2007
  5. Ahmed
    Replies:
    1
    Views:
    286
    Joseph Bittman MVP MCSD
    Nov 13, 2005
Loading...

Share This Page