[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Link button requires two clicks to refresh page

Posted on 2013-02-05
5
Medium Priority
?
860 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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