Solved

JQuery onclient click and DIV

Posted on 2010-11-27
9
539 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now