Click here to Skip to main content
13,000,022 members (48,817 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I am fairly new to ASP .Net and I encountered an issue where after I fire my dropdownlist onchange JavaScript, my linkbutton is no longer doing its server side code. I am wondering what happened because my Submit button is working except for the link button. I have tried changing it to a Button but it is still not working.

The link button is tasked to add another row in the gridview.

Thanks for the help.

Posted 26-Feb-12 15:27pm
Varun Sareen 26-Feb-12 23:01pm
Please post some code
SAKryukov 26-Feb-12 23:11pm
"No longer doing its server side code" is not informative. How about code sample and proper explanation of the problem?
JimAce 27-Feb-12 19:50pm
Heres the code..

The grid view is inside the update panel...

The grid view contains the following
1. Remove Line
2. Add Line to grid

The issue is... I have the ID dropdown1 included with the OTHER option. When Other is selected a JavaScript will show and prompt will ask for an input. Everything works well but after this action any button inside the grid view is no longer working... which means the Add row(lnkbtnAddNewRow) and remove row(lnkbtnRemoveRow) no longer fires. I am stuck.

I tried another approach by removing it from the update panel. Everything works well including the OTHER button but once I hit the Add Row or Remove Row it returns a long exception about required validator.


Thank you.

<head runat="server">
<form id="form1" runat="server">
<script language="javascript" type="text/javascript">
function BtnOnClick_Submit() {
if (Page_ClientValidate('vgSubmitForm')) {
return confirm("Are you sure you want submit this form?");
else {
alert("Marked in red asterisks (*) are required. \nOtherwise, please 'Remove' the entry.");
function promptDesignation(select) {
if (select.value != "Other") return;
var answer = prompt("Please enter new designation", "");
if (!answer) {
select.selectedIndex = select.options.length - 13;
var newOption = document.createElement("option");
newOption.text = answer;
newOption.value = answer;
select.insertBefore(newOption, select.lastChild);
select.selectedIndex = select.options.length - 1;

</script><pre lang="xml"><link href="/css/ceapstylesheet.css" rel="stylesheet" type="text/css" />

<div style="margin: 0 auto; width:850px;">
<div style="text-align: left"><br />
<h5 align="center">FORM</h5><br /><br />
<p><h3>Registration No. <asp:Label ID="lblRegNo" runat="server" /></h3></p>
<hr />
<table class="con-reg">
<th width="12%">Region</th>
<td width="88%"><b>: <asp:Label ID="lblRegion" runat="server" /></b></td>
<th>Name of School</th>
<td><b>: <asp:Label ID="lblNameOfSchool" runat="server" /></b></td>
<asp:Label ID="lblDiocese" runat="server" />
<td><b>: <asp:Label ID="lblAddress" runat="server" /></b></td>
<hr />
<br />
<ul><strong style="color:#ff0000;">Note:</strong>
<li style="list-style-position:inside;">You can change the name of the students even after registering.</li>
<li style="list-style-position:inside;"><b>Five (5) minute walk</b> between Venue.</li>
<br />
<asp:UpdatePanel ID="upAttendees" runat="server" Visible="true">
<asp:Gridview ID="Gridview1" runat="server" ShowFooter="true" GridLines="None"
Tejas_Vaishnav 27-Feb-12 23:26pm
while calling your javascript function at the end of your function based on your logic you need to return true or false, if your function return true means it will valid so it will go for server side scripting or if it will return false then it will not go for serve side scripting...

make this changes and test it will work or not...
Tejas_Vaishnav 27-Feb-12 23:28pm
and also one more thing while you provide your code at that time not copy paste whole page code in side this questions but make some sense to paste necessary code.. and also provide some comment where or on which line you face any error...
JimAce 27-Feb-12 23:32pm
Thanks I will check
JimAce 27-Feb-12 23:48pm
This the line for my dropdownlist
<asp:DropDownList ID="dropdown1" AutoPostBack="false" onchange="promptDesignation(this)" runat="server" Width="250px" > - the onchange works as it calls javascript

These are the functions not working inside the update template after I fire the javascript (after selecting "Other" from dropdown1)

1 Remove:
<asp:LinkButton ID="lnkbtnRemoveRow" runat="server" Font-Size="10px" OnClick="lnkbtnRemoveRow_Click">Remove

2 Add Row:
<asp:LinkButton ID="lnkbtnAddNewRow" runat="server" Text="Add Another Attendee" Font-Size="11px" OnClick="lnkbtnAddNewRow_Click"/>

Does update panel has something to do with it?

Thanks for the help.

Let me know if this helps. Thanks a lot.
Here's the code. I removed the elements not needed.


<br />
<asp:UpdatePanel ID="upAttendees" runat="server" Visible="true">
<asp:Gridview ID="Gridview1" runat="server" ShowFooter="true" GridLines="None"
AutoGenerateColumns="false" OnRowCreated="Gridview1_RowCreated"
BorderStyle="None" Width="100%" >
<asp:BoundField DataField="RowNumber" HeaderText=" " ItemStyle-VerticalAlign="Top" ItemStyle-Font-Bold="true" ItemStyle-Font-Size="Large" ItemStyle-ForeColor="#3687D6" />
<asp:TemplateField ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Top">
<table class="con-attendee">
<th width="50%">Designation:</th>
<asp:DropDownList ID="dropdown1" AutoPostBack="false" onchange="promptDesignation(this)" runat="server" Width="250px" >
<asp:ListItem Text=" - Select Position - " Value=""/>
<asp:ListItem Text="Position1" Value="Position1"/>
<asp:ListItem Text="Other" Value="Other"/>


<asp:LinkButton ID="lnkbtnAddNewRow" runat="server" Text="Add Another Attendee" Font-Size="11px" OnClick="lnkbtnAddNewRow_Click"/>

<asp:LinkButton ID="lnkbtnRemoveRow" runat="server" Font-Size="10px" OnClick="lnkbtnRemoveRow_Click">Remove

<div style="margin: 10px 0;">
<asp:UpdateProgress ID="uprogAttendees" runat="server" AssociatedUpdatePanelID="upAttendees">


<div class="con-sign">
<asp:Button ID="btnSubmitForm" runat="server" Text="Submit" Font-Bold="true" ForeColor="White" BorderColor="#0167CB" BackColor="#3687D6" ValidationGroup="vgSubmitForm" OnClientClick="return BtnOnClick_Submit();" Width="100px" OnClick="btnSubmit_Click" /></p>

<br /><br />

Dean Oliver 28-Feb-12 8:56am
Please post your code in the question not as a comment and reference the line in which the problem is ocuring. thanks.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Not Working
Nelek 9-Nov-12 3:54am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170624.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100