Solved

JQuery onclient click and DIV

Posted on 2010-11-27
9
544 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JQuery DataTable Time Sort 14 45
How to send a javascript array via AJAX (jquery)? 3 42
How does this modal gets closed? 6 41
Error just appeared 3 23
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

738 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