Solved

linkbutton not firing and sort not firing

Posted on 2011-09-27
27
508 Views
Last Modified: 2012-08-13
I am asking if anyone has encountered something similar to this and if so they could elaborate on details.  I am troubleshooting and just don't know where to look.  Application is vb.net with oracle backend.  Up until yesterday the linkbutton that would remove a record was working and the custom sort I have on the grid was working.  All of my pages are using gridviews and yesterday those 2 events were firing and today they are not.  The only change I made last night was I set a defaultbutton on an element in a usercontrol and the usercontrol sits with each of these grids in a contentpage.  No other changes at all.  I even took the defaultbutton back out to no avail.  This development is fairly new to me.  I 've been at it only a couple of months.  What I need from the experts is how do I go about tracing where the problem is at when the event appears to fire and the page reloads but the sort and delete in the event does not fire.
Thanks.
0
Comment
Question by:thamilto0410
  • 14
  • 12
27 Comments
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36712103
Are you putting any html data in any of the server controls?

for ex: <asp:hiddenfield ='hdnDesc'> .............
 
hdnDesc.Value = '<p>This is my description</p>'

check this by viewing rendered html(will get from by viewsource from the browser)
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 36712108
Set breakpoints and see if there's something in the code that you missed. Check the flow.
It is kind of hard to say without debugging.

One thing I would like to point you out is DefaultButton feature won't work on LinkButton in FireFox.
There are some solutions out there for that but they didn't work for me and so I had to explicitly call __doPostBack upon the Enter click.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36712257
jagssidurala:  The only html controls on the page are the ones in the usercontrol that is the menu system.
guru_sami: I put break points in and not only is there no error message but the page posts back and even though I clear the columns before I rebind after the delete procedure is called as the grids are built dynamically now (and keep in mind there have been no changes to this page for 2 weeks and this just started yesterday) the grid does not clear it just reloads and shows twice in the page.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 41

Expert Comment

by:guru_sami
ID: 36713320
Grid shows twice? So you are adding the grid via code-behind?
If it was working and there were no other changes, I am not exactly sure what might be happening.
If your code -linked to source control you might want to make sure there were no other accidental changes outside of your knowledge.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36713518
guru_sami:  Yes grid is being populated from codebehind and not in aspx file.  It and the rowcommand were working yesterday.  The rowcommand and the custom sort now do not work.  I will continue to research and if I have to rebuild.  If you have any ideas as to how I can trace back to the problem please assist.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 36713588
Can you post code your code .aspx and code-behind? May be looking at it rings a bell.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36750413
guru_sami:  I figured out the problem but and fixed but I still need to trap for enter which is how this question got started.  Could you tell me how you did this: I had to explicitly call __doPostBack upon the Enter click.  With an example of doing this in a usercontrol and I will grant you points as that is what started all this.  Thanks.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 36815740
Here is the code snippet. Uses a bit of jQuery to accomplish this:

$('#<%=txtSearch.ClientID %>').keypress(function(e){
                if(e.keyCode==13 && $.browser!='msie'){
                   if(Page_ClientValidate('<%=btnSubmit.ValidationGroup%>')){
                        <%=this.PostBackSnippet %>
                    }
                }
});

Open in new window


In code-behind I have:

public string PostBackSnippet = String.Empty; //global variable

protected void Page_Load(object sender, EventArgs e)
{
    PostBackSnippet = Page.ClientScript.GetPostBackEventReference(btnSubmit, string.Empty);
}

Open in new window


This is mainly to work with FF(non-ie) browsers because DefaultButton with LinkButton works fine in IE.
This - click - is what I tried first but didn't workout well for me.

Hope this will help.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36818527
guru_sami: I know what to do with the codebehind but how do I incorporate the snippet into the page?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 36818621
Add the first code-block as you would put a regular javascript/jquery code.
OR
I am not understanding your confusion.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36818691
I have this :
<script type="text/javascript" >
          $('#<%=txtCaseID.ClientID %>').keypress(function(e) {
              if (e.keyCode == 13 && $.browser == 'msie') {
                  if (Page_ClientValidate('<%=btnSearch%>')) {
                      <%=this.PostBackSnippet %>;
                                  }
              }
          });

</script>
in the bottom of my usercontrol page  and I have the codebehind in the codebehind file for the usercontrol and I am getting expression expected on the <%=  before this?  I have not used jquery before so I am doing something wrong.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 36818741
Which version of VS and asp.net are you using? And also FF?
And before I throw some other solutions to you, can you tell me issue you faced when you try setting default button?
And one thing I forgot to mention is I used asp.net Panel to set DefaultButton and not the form.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36818777
I think I am just so new to .net development I might be doing the defaultbutton wrong.  I had tried the above example you have with the click.  I am trying it again because I am thinking it was my fault I did not get it working the first time.  Version of visual studio is 2008.  And I work in a controlled environment that only uses IE on an intranet.  I still will be awarding you points as I GREATLY APPRECIATE your continued input.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 36818825
If it is just IE then something like this is enough and no need of the javascript code or anything.

<asp:Panel ID="Panel1" runat="server" DefaultButton="btnSubmit">
    <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
    <asp:LinkButton ID="btnSubmit" runat="server" onclick="btnSubmit_Click">LinkButton</asp:LinkButton>
    <br />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Panel>

Open in new window


It is FF that doesn't like this. To my surprise a test page I created with VS 2010, worked. So I will also need to try out and see.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36818878
Okay then one more question.  Does it have to be a linkbutton or can it be just a button?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 36818894
It can be any button.

If it is a Regular Button or ImageButton there are no issues whatsoever when you use DefaultButton with Panel as in my last codesnippet.

The problem arises only with LinkButton + FireFox + Panel/DefaultButton.

So if you are not using LinkButton you are all set to use the codsnippet in my last comment.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36890714
guru_sami:

I have this in my usercontrol :   <asp:Panel ID="Panel1" runat="server" DefaultButton="btnSearch">
     <input type="text" id="txtCaseID" runat="server" name="txtCaseID" size="15" maxlength="15"  />
 <asp:Button ID="btnSearch" runat="server" BorderStyle="Outset" BorderColor="LightGray" Text="GO" CssClass="smallfrmelements" />
 </asp:Panel>

this in the codebehind on page load :     btnSearch.Attributes.Add("onClick", "doSearch();")

Which calls the javascript function does a little validation and does a location.replace on the url but I am still doing something wrong as the defaultbutton fires but the page just posts back to itself.  What am I missing?
   
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 36892453
OnClick won't work in that case and you should be using OnClientClick in the markup .

<asp:Button ID="btnSearch" runat="server" BorderStyle="Outset" BorderColor="LightGray" Text="GO" CssClass="smallfrmelements" onclientclick="doSearch()" />

So you don't want postback at all? Because if so then again the whole scenario changes.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36892808
No I do not want postback.  My usercontrol is the menu system where they have links and can enter a case id and click go or hit enter when then do either I want to validate that there is a case number in the input and then forward them onto another page.  So am I using the defaultbutton incorrectly?
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 36893046
In that case use html button instead of asp.net button like in this example:

 <input type="text" id="txtCaseID" runat="server" name="txtCaseID" size="15" maxlength="15"  />
<input id="btnSearch" type="button" value="Go" onclick="doSearch" />

<script type="text/javascript">
    $(function () {
        $("#txtCaseID").keypress(function (e) {
            if (e.keyCode == 13) {
                //Enter pressed do something
                doSearch();
            }
        });
    });
    function doSearch() {
        alert('do search');
    }
</script>

Open in new window


Add the reference to jQuery to the head of your page:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>

Open in new window


And no need of the Panel. The javascript code will take care of enter.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36893532
That is GREAT it is working but I am getting 'this._postBackSettings.async' is null or not an object.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36893626
NEVER MIND.  It only happened one time so maybe I had something wrong. I am going to test for a few more minutes and then award you the points.  THANK YOU SO MUCH!!
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36893674
I am not home free yet.  The function fires but I I still get the this._postbackSettings.async is null or not an object.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 36893804
So it is something outside of the above code that is causing. A quick search for the error shows it's related to UpdatePanel.

So may be you might want to share some code or even start a new question to get more attention from other experts who might know more about that error.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 36895102
guru_sami:  I have this in the user control and after doing research this evening some suggested that to remove the postbacksettings error I needed to add enablepartialrendering="false".  It did get rid of the error but the page will fire alerts in the script but the page does not forward.  I have put the script below.  Any more advice would be greatly appreciated.

<asp:ScriptManager  EnablePartialRendering="false" ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/js/functions.js" />
<asp:ScriptReference Path="~/js/jquery-1.6.4.min.js" />
</Scripts>
</asp:ScriptManager>

<li>
    <a href="javascript:doSearch();" title="foia number" style="width:110px;">Search By File  ID:</a></li>
<li><input type="text" id="txtCaseID" name="txtCaseID" size="15" maxlength="15" />
    <input id="btnSearch" type="submit" value="GO" onclick="doSearch();" />
 </li>

function doSearch() {

    var fField = document.getElementById("txtCaseID");
      var caseid = document.getElementById("txtCaseID").value;
      
      alert("am here")
      if(fField.value == "")
      {
        alert("case ID field cannot be blank");
        fField.focus();
        return false;
      }
      if (isNumeric(fField.value) == false) {
       alert("case ID field is a numeric field and a nonnumeric was found.  Please correct.");
       fField.focus();
       return false;
       }
       if (location.href.indexOf("wpu") > -1) {
           //alert("we are here");
           window.location.replace("../getFA.aspx?caseid=" + escape(caseid));
       }
       else if (location.href.indexOf("reports") > -1) {
           //alert("we are here");
           window.location.replace("../getFA.aspx?caseid=" + escape(caseid));
       }
       else {
           //     alert("we are on the last one.");
           window.location.replace("getFA.aspx?caseid=" + escape(caseid));
       }
}
0
 
LVL 1

Author Closing Comment

by:thamilto0410
ID: 36900697
guru_sami:  Forget my last questions.  I figured it out and it is working successfully now.  THANK YOU so much for your patience and your help.  In addtion your experience taught me something new.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 36903944
Glad to help.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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