Solved

linkbutton not firing and sort not firing

Posted on 2011-09-27
27
504 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
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

 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Glad to help.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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 video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

13 Experts available now in Live!

Get 1:1 Help Now