0

In my company want to modify one ASp.net Project,

<asp:DropDownList ID="drdIssuer" runat="server" CssClass="txtfield" AutoPostBack="True" OnSelectedIndexChanged="drdIssuer_SelectedIndexChanged" onchange="showvalues();">
                    <asp:ListItem>Val1</asp:ListItem>
                    <asp:ListItem>Val1</asp:ListItem>
                    <asp:ListItem>Val1</asp:ListItem>
                    <asp:ListItem>Val1</asp:ListItem>

                </asp:DropDownList>

This is html asp code,And JAvascript like this,

 <script type="text/javascript">
       function showvalues()
       {
           alert('Yes');
       }
       </script>

When I change dropdown listing I want to work showvalues() function how do i do it,Can you guys help me....

Selvan Kumar
  • 35
  • 1
  • 4

2 Answers2

0

You can register a html event for the select element that is rendered by the asp:dropdown.

drdIssuer.Attributes["onchange"] = "showvalues();";
XPD
  • 1,121
  • 1
  • 13
  • 26
0

1.You are getting that error because, you have might not added the namespace

using System.Data.SqlClient;
  1. Also as mentioned by you in the comment that you are getting the error as

I got the error Server Error in '/' Application

For that you may go for a detailed solution mentioned at Geeks blogs.

And also have a look at here As, it is not a major issue and as per the information provided by you, the above solution should work.

Your whole code-behind for the drdIssuer_SelectedIndexChanged should look like this

using System.Data.SqlClient; //namespace


protected void drdIssuer_SelectedIndexChanged(object sender, EventArgs e) 
 { 
     SqlParameter[] param = new SqlParameter[1];
     if (drdIssuer.SelectedValue == "Val1")
     {
         Response.Write(@"<script langauge='text/javascript'>alert('...Alert Goes here...');</script>");
     }
 }

Also if you remove the onChange function from the values. Your Response.Write will also work for Val1

<asp:DropDownList ID="drdIssuer" runat="server" OnSelectedIndexChanged="drdIssuer_SelectedIndexChanged"
        CssClass="txtfield" AutoPostBack="True">
        <asp:ListItem>Val1</asp:ListItem>
        <asp:ListItem>Val2</asp:ListItem>
        <asp:ListItem>Val3</asp:ListItem>
        <asp:ListItem>Val4</asp:ListItem>
    </asp:DropDownList>

Hope that helps.

Community
  • 1
  • 1
Nad
  • 4,605
  • 11
  • 71
  • 160