?
Solved

Link button requires two clicks to refresh page

Posted on 2013-02-05
5
Medium Priority
?
852 Views
Last Modified: 2013-02-06
I have an update panel.  Inside the panel there is a gridview.  The gridview has several rows and each row has a dropdown list and a link button.  

The link button hides the current panel and shows another panel based on what the user selected in the drop down.  

I am trying to trap when the user does not select anything in the drop down list and pop an alert.  

The alert message code from the code behind:
 Protected Sub gvcadence_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvcadence.RowCommand

If e.CommandName = "Change" Then
  If ddlCadence.SelectedIndex = -1 Then
    str.Append("<script type=""text/javascript"" language=""javascript"">" & vbCr)
    str.Append("" & vbCr)
    str.Append("alert(You Must Select A Cadence Name.);" & vbCr)
    str.Append("" & vbCr)
    str.Append("" & vbCr)
    str.Append("</script>" & vbCr)
    ScriptManager.RegisterClientScriptBlock(Me, Me.gvcadence.GetType(), Guid.NewGuid().ToString(), str.ToString, False)
  End if
End if         

Open in new window

This what the UI looks like
 <asp:updatepanel id="upSubCategories" runat="server"  >
 <contenttemplate>
<asp:gridview id=gvcadence runat="server" AutoGenerateColumns="false" OnRowEditing="gvcadence_RowEditing" >
// other controls have been omitted
<asp:LinkButton ID="btnChangeCadence"  Text="Change"  runat="server" CommandName="Change" onClick="btnChangeCadence_Click" >
</asp:LInkButton>
</asp:gridview>
</contenttemplate>
</asp:undatepanel>

Open in new window

This is the codebehind for the onClick Event
Protected Sub btnChangeCadence_Click(sender As Object, e As System.EventArgs) Handles btnChangeCadence.Click
            Me.upHeader.Visible = False
            Me.upSubCategories.Visible = False

            Me.lnkEdit.Visible = True
            Me.lnkClose.Visible = True
            BindCadenceGrid()
            Me.upChgPanel.Visible = True

Open in new window

When I don't select anything from the drop down then I get an alert, but when I select something in the dropdown list, then I have to click on the button twice in order for the next panel to become visible.  

I can't figure out what is making me have to click twice.  

Can someone take a look.  Much appreciated.
0
Comment
Question by:sherbug1015
[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 Comments
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38858593
Hi,

In the first place, it's better to validate DropDownList at client side than on server side -
http://roopeshreddy.wordpress.com/2012/06/09/asp-net-sever-controls-validation-using-javascript-jquery/

Hope it helps u...
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 38858922
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 38858926
Change your rowcommand sub to following and remove the click handler of linkbutton


Protected Sub gvcadence_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvcadence.RowCommand

If e.CommandName = "Change" Then
                      If ddlCadence.SelectedIndex = -1 Then
                          str.Append("<script type=""text/javascript"" language=""javascript"">" & vbCr)
                          str.Append("" & vbCr)
                          str.Append("alert(You Must Select A Cadence Name.);" & vbCr)
                          str.Append("" & vbCr)
                          str.Append("" & vbCr)
                          str.Append("</script>" & vbCr)
                          ScriptManager.RegisterClientScriptBlock(Me, Me.gvcadence.GetType(), Guid.NewGuid().ToString(), str.ToString, False)
            Else
                          Me.upHeader.Visible = False
                          Me.upSubCategories.Visible = False

                          Me.lnkEdit.Visible = True
                          Me.lnkClose.Visible = True
                          BindCadenceGrid()
                          Me.upChgPanel.Visible = True
            End if
End if         
End Sub

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38859158
You do need quotes in the script but why the extreme formatting of the script?

str.Append("<script type=""text/javascript"">alert('You Must Select A Cadence Name.');</script>" & vbCr)

is a lot easier to read
0
 

Author Closing Comment

by:sherbug1015
ID: 38860888
I think this did the trick.  Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

777 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