Check Box an Posting back?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpmel
    New Member
    • Oct 2007
    • 69

    Check Box an Posting back?

    Hi guys,

    It's been a along time. Hope someone can help me.
    I am using VS 2005 and language C#
    I have some fields on a form
    1) an 'AccountNo" drop down list and an "ALL" check box next to it
    2)a "descriptio n" text box
    3)A find button

    The results of the search is handled by a stored procedure and shown on a gridview on another page.

    If the All check box is checked then i disabled the drop down list and the text box because that menas that the user wants to search for all Accounts and therefore doesnt need to fill in the AccountNo or description. This is done via Autopostback on the All checkbox control and the checkchanged event. This works fine.

    My problem is that when the page initially loads for the first time and the user presses the check box and then presses the find button, no results are displayed. However, if they go back into the form and search on something else, say a particular AccountNo and presses find button it works fine. Then if they go back and check the ALLcheck box and press find button it works......Why doesnt it work the very first time.

    I have no code in my Page_Load method of either of my 2 pages.
    I am thinking it has something to do with posting back....can someone please help me?
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    Please check in your code at the place where are you calling the stored procedure to display the results of Find query to test that if procedure is getting called or not for the first time. How are you telling the procedure that you want to search for All Accounts? If it using parameters to the procedure please check that correct parameters are send to the procedure or not.
    You can post code details to get more help.

    Originally posted by phpmel
    Hi guys,

    It's been a along time. Hope someone can help me.
    I am using VS 2005 and language C#
    I have some fields on a form
    1) an 'AccountNo" drop down list and an "ALL" check box next to it
    2)a "descriptio n" text box
    3)A find button

    The results of the search is handled by a stored procedure and shown on a gridview on another page.

    If the All check box is checked then i disabled the drop down list and the text box because that menas that the user wants to search for all Accounts and therefore doesnt need to fill in the AccountNo or description. This is done via Autopostback on the All checkbox control and the checkchanged event. This works fine.

    My problem is that when the page initially loads for the first time and the user presses the check box and then presses the find button, no results are displayed. However, if they go back into the form and search on something else, say a particular AccountNo and presses find button it works fine. Then if they go back and check the ALLcheck box and press find button it works......Why doesnt it work the very first time.

    I have no code in my Page_Load method of either of my 2 pages.
    I am thinking it has something to do with posting back....can someone please help me?

    Comment

    • phpmel
      New Member
      • Oct 2007
      • 69

      #3
      [code=c#]
      protected void findButton_Clic k(object sender, EventArgs e)
      {
      if (allCheckBox.Ch ecked == false)
      {
      if (ddlAccountNo.S electedIndex == 0)
      Session["AccountNo"] = 0;
      else
      Session["AccountNo"] = ddlAccountNo.Se lectedValue;

      if (descriptionTex tBox.Text.Trim( ) == "")
      Session["descriptio n"] = "0";
      else
      Session["descriptio n"] = descriptionText Box.Text.Trim() ;

      if (JobNoCheckBox. Checked == false)
      Session["jobno"] = 0;
      else
      Session["jobno"] = 1;
      Session["all"] = 0;

      }
      else
      Session["all"]= 1;//all check box wass selected

      Response.Redire ct("AItest_Find Result.aspx");
      }[/code]


      Stored Procedure is

      Code:
      CREATE PROCEDURE dbo.FindAccount
      	
      	(
      	@AccountNo int,
      	@description varchar(100),
      	@jobno bit,
      	@all bit
      	)
      	
      AS
      	IF (@all = 1)
      		BEGIN
      			SELECT accountID AS aID,
      				   accountNo AS [Account No.],
      				   description AS [Description],
      				   JobNo AS [Job No.]
      				   
      			FROM AccountInterfaceTest
      			
      		END
      	ELSE
      		BEGIN
      			declare @varAcc varchar(6)
      			if( @AccountNo = 0 )
      				set @varAcc='%'
      			else
      				set @varAcc=@AccountNo
      			
      			declare @varDesc varchar(100)
      			if( @description = '0')
      				set @varDesc = '%'
      			else
      				set @varDesc = '%' +@description+ '%'
      			
      			declare @varJob varchar(7)
      			if( @jobno = 0)
      				set @varJob = '%'
      			else
      				set @varJob = '1'
      			
      			IF @varDesc = '%'
      				BEGIN
      					SELECT accountID AS aID,
      						   accountNo AS [Account No.],
      						   description AS [Description],
      						   JobNo AS [Job No.]
      					
      					FROM AccountInterfaceTest
      					
      					WHERE (accountNo LIKE @varAcc) AND
      						  (JobNo LIKE @varJob)
      						  
      				END
      			ELSE
      				BEGIN
      					SELECT accountID AS aID,
      						   accountNo AS [Account No.],
      						   description AS [Description],
      						   JobNo AS [Job No.]
      						   
      					FROM AccountInterfaceTest
      					
      					WHERE (accountNo LIKE @varAcc) AND
      						  (description LIKE @varDesc)AND
      						  (JobNo LIKE @varJob)
      				END
      		END
      RETURN
      I am not sure how to check the stored procedure parameter values.

      Comment

      • shweta123
        Recognized Expert Contributor
        • Nov 2006
        • 692

        #4
        Hi,

        Are you calling the stored procedure depending on the value of session variable Session("All")? Please check its value in the page AItest_FindResu lt.aspx. If its value is Null, your stored procedure will not get called because of which you will not see any results after clicking on the Find button.

        Originally posted by phpmel
        [code: c#]
        protected void findButton_Clic k(object sender, EventArgs e)
        {
        if (allCheckBox.Ch ecked == false)
        {
        if (ddlAccountNo.S electedIndex == 0)
        Session["AccountNo"] = 0;
        else
        Session["AccountNo"] = ddlAccountNo.Se lectedValue;

        if (descriptionTex tBox.Text.Trim( ) == "")
        Session["descriptio n"] = "0";
        else
        Session["descriptio n"] = descriptionText Box.Text.Trim() ;

        if (JobNoCheckBox. Checked == false)
        Session["jobno"] = 0;
        else
        Session["jobno"] = 1;
        Session["all"] = 0;

        }
        else
        Session["all"]= 1;//all check box wass selected

        Response.Redire ct("AItest_Find Result.aspx");
        }


        Stored Procedure is

        [code]
        CREATE PROCEDURE dbo.FindAccount

        (
        @AccountNo int,
        @description varchar(100),
        @jobno bit,
        @all bit
        )

        AS
        IF (@all = 1)
        BEGIN
        SELECT accountID AS aID,
        accountNo AS [Account No.],
        description AS [Description],
        JobNo AS [Job No.]

        FROM AccountInterfac eTest

        END
        ELSE
        BEGIN
        declare @varAcc varchar(6)
        if( @AccountNo = 0 )
        set @varAcc='%'
        else
        set @varAcc=@Accoun tNo

        declare @varDesc varchar(100)
        if( @description = '0')
        set @varDesc = '%'
        else
        set @varDesc = '%' +@description+ '%'

        declare @varJob varchar(7)
        if( @jobno = 0)
        set @varJob = '%'
        else
        set @varJob = '1'

        IF @varDesc = '%'
        BEGIN
        SELECT accountID AS aID,
        accountNo AS [Account No.],
        description AS [Description],
        JobNo AS [Job No.]

        FROM AccountInterfac eTest

        WHERE (accountNo LIKE @varAcc) AND
        (JobNo LIKE @varJob)

        END
        ELSE
        BEGIN
        SELECT accountID AS aID,
        accountNo AS [Account No.],
        description AS [Description],
        JobNo AS [Job No.]

        FROM AccountInterfac eTest

        WHERE (accountNo LIKE @varAcc) AND
        (description LIKE @varDesc)AND
        (JobNo LIKE @varJob)
        END
        END
        RETURN
        [code]
        I am not sure how to check the stored procedure parameter values.

        Comment

        • kenobewan
          Recognized Expert Specialist
          • Dec 2006
          • 4871

          #5
          Originally posted by phpmel
          I have no code in my Page_Load method of either of my 2 pages.
          I am thinking it has something to do with posting back....can someone please help me?
          If you have no code in your Page_Load, then it won't load initially. Clicking the button triggers the function which loads the data. HTH.

          Comment

          Working...