Solved

Link button requires two clicks to refresh page

Posted on 2013-02-05
5
821 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
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 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

19 Experts available now in Live!

Get 1:1 Help Now