Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

linkbutton not firing and sort not firing

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
thamilto0410
Asked:
thamilto0410
  • 14
  • 12
1 Solution
 
jagssiduralaCommented:
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
 
guru_samiCommented:
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
 
thamilto0410Author Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
guru_samiCommented:
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
 
thamilto0410Author Commented:
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
 
guru_samiCommented:
Can you post code your code .aspx and code-behind? May be looking at it rings a bell.
0
 
thamilto0410Author Commented:
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
 
guru_samiCommented:
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
 
thamilto0410Author Commented:
guru_sami: I know what to do with the codebehind but how do I incorporate the snippet into the page?
0
 
guru_samiCommented:
Add the first code-block as you would put a regular javascript/jquery code.
OR
I am not understanding your confusion.
0
 
thamilto0410Author Commented:
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
 
guru_samiCommented:
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
 
thamilto0410Author Commented:
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
 
guru_samiCommented:
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
 
thamilto0410Author Commented:
Okay then one more question.  Does it have to be a linkbutton or can it be just a button?
0
 
guru_samiCommented:
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
 
thamilto0410Author Commented:
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
 
guru_samiCommented:
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
 
thamilto0410Author Commented:
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
 
guru_samiCommented:
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
 
thamilto0410Author Commented:
That is GREAT it is working but I am getting 'this._postBackSettings.async' is null or not an object.
0
 
thamilto0410Author Commented:
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
 
thamilto0410Author Commented:
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
 
guru_samiCommented:
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
 
thamilto0410Author Commented:
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
 
thamilto0410Author Commented:
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
 
guru_samiCommented:
Glad to help.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 14
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now