Solved

JQuery onclient click and DIV

Posted on 2010-11-27
9
541 Views
Last Modified: 2012-05-10
I am working with .net 4.0 and created gridview and formview on the same page now on the JQuery DOM Ready I am writing code that to Formview DIV to display none and it working fine and FormView DIV is not Dispplay
<style type="text/css">  
   .displayNone  
   {  
     display:none;  
   }  
     
   .displayDIV  
   {  
     display:inline;  
   }  
 </style>

Open in new window


DOM Ready Code
 $("#FormView").hide();
 $("#GridView").show();



 <script type="text/javascript">
      function rmvClass() {
        $("#FormView").show();

        $("#GridView").hide();
      }
    </script>

Open in new window


and on grid row bound  I am binding onclient click event like this
 If e.Row.RowType = DataControlRowType.DataRow Then
      Dim requester As HelpDesk.RequesterRow = CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, HelpDesk.RequesterRow)
      Dim companyAPI As New CompanyBLL
      Dim companies As HelpDesk.CompanyDataTable = companyAPI.GetCompanyByCompanyID(requester.CompanyID)

      If companies.Rows.Count > 0 Then
        Dim company As HelpDesk.CompanyRow = companies(0)
        Dim lblCompanyName As LinkButton = e.Row.FindControl("lblCompanyName")
        lblCompanyName.Text = company.Name
        lblCompanyName.OnClientClick = "rmvClass()"
        lblCompanyName.PostBackUrl = String.Format("?id={0}&m=E", requester.RequesterID.ToString())
      End If

    End If

Open in new window


But thing is that when I click on the gridview link FormView DIV is coming and it will go away and GridView DIV is not getting hide. Can somebody help to show this problem.

0
Comment
Question by:milindsaraswala
  • 5
  • 4
9 Comments
 
LVL 16

Expert Comment

by:BurnieP
ID: 34222096
I think you need to remove the display:hide and display:inline from your CssClass. I think this is the reason why they are not working properly.  So try it without setting your Formview and Gridview do displayNone and displayDIV and see if you get better results.

(Remove theses classes from FormView and GridView).
<style type="text/css">  
   .displayNone  
   {  
     display:none;  
   }  
     
   .displayDIV  
   {  
     display:inline;  
   }  
 </style>
0
 
LVL 5

Author Comment

by:milindsaraswala
ID: 34222299
I removed CSS as per your suggestion but it is happening like FormView is coming and after few sec it will hide  

I also remove two line
 
$("#FormView").hide();
 $("#GridView").show();

Open in new window


But the grid is not getting hide also
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 34222348
When the user click on your link button, do you want a postback or not?

Because if you want to postback, then your page will be refreshed with the initial values again.

To prevent a postback when you click on the link button, you will need to add return false after you call your rmvClass.

So in your server side code, you will need to modify that line :

lblCompanyName.OnClientClick = "rmvClass(); return false;"
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 5

Author Comment

by:milindsaraswala
ID: 34222409
Yes I was thinking that Page is getting refresh this happing. When i put return false gridview is getting hide. But formview is not coming due QueryString is not Posting, and as I have kept formview select command by id which is posting on QueryString

So can u suggest me some solution for this.
0
 
LVL 16

Accepted Solution

by:
BurnieP earned 500 total points
ID: 34222474
Hmmm, I would suggest you this solution.

Remove the return false, and even the OnClientClilck from your LinkButton.  Let it postback.  Also, add a ScriptManager on your page.

In your postback event, add this line :

ScriptManager.RegisterStartupScript(Page, this.GetType(), "ClosePopup", "<script>rmvClass();</script>", false);

It will tell the brower to execute your rmvClass() function when your page reload, and it should show/hide accordingly.
0
 
LVL 5

Author Comment

by:milindsaraswala
ID: 34222534
I add following code in Page load Event but it is same

If Page.IsPostBack Then
      ScriptManager.RegisterStartupScript(Page, Me.GetType(), "ClosePopup", "<script>rmvClass();</script>", False)
    End If
0
 
LVL 5

Author Comment

by:milindsaraswala
ID: 34222568
Sorry Boss it is working. I forget to remove dom ready code. thank you it working
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 34222582
Hi milindsaraswala,

I am glad that my solution helped you, one thing though, you accepted your own comment as the solution :).

It would be nice if you could set the solution to one of my comment so points can be given.

Thank you,

Burnie
0
 
LVL 5

Author Comment

by:milindsaraswala
ID: 34222592
Ho Sorry for that I will change that
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now