Required field validator preventing panel to display - c#

I am using 2 link buttons (Coordinator and Staff) which on_Click action displays corresponding panels asking for login/signup/forgotpassword. If the user select signup/forgotpassword a popup windows is popped (using ModalPopupExtender) asking for information. Everything worked fine unless and until I used required field validator within the panel which pops up when the user click on signup/forgotpassword. If I use required field validator my page run fine and when I click on any of the link button (Coordinator/Staff) nothing happens.
This is aspx code :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type = "text/css">
.modalBackground
{
background-color: gray;
}
.modalPopup
{
background-color: white;
border-width: 3px;
border-style: solid;
border-color: black;
padding-top: 10px;
padding-left: 10px;
width: 300px;
height: 140px;
}
.panel
{
background : gray;
padding : 10px;
}
div ul ul
{
display: none;
}
div ul li:hover > ul
{
display: block;
}
div ul li ul:hover > ul
{
display: block;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="XX-Large" Text="Automated Examination System"></asp:Label><br /> <br /><br />
<asp:Panel ID = "MainPanel" runat = "server" Height="181px" Width="275px">
<ul>
<li style="margin-left: 33px; width: 169px;"> <asp:LinkButton ID = "LinkAdmin" runat = "server" onclick="LinkAdmin_Click">Coordinator</asp:LinkButton></li>
<li style="width: 172px; margin-left: 33px"> <asp:LinkButton ID="LinkStaff" runat="server" onclick="LinkStaff_Click">Staff</asp:LinkButton></li>
<li style="margin-left: 33px"> <asp:LinkButton ID = "LinkStudent" runat = "server">Student</asp:LinkButton>
<ul>
<li><asp:LinkButton ID = "LinkButton1" runat = "server">Fresh Registration</asp:LinkButton></li>
<li><asp:LinkButton ID = "LinkButton2" runat = "server">Re Registration</asp:LinkButton></li>
</ul>
</li>
</ul>
</asp:Panel>
<asp:Panel ID="InfoPanel" runat="server" style="left: 290px; top: 104px; position: absolute; height: 375px; width: 611px"><br /><br /><br />
<asp:Label ID="Label2" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="The Automated Examination system will allow post graduation student and under graduation students to register their respective courses for their respective semester. "></asp:Label>
<asp:Label ID="Label3" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="Once the registration process is completed for a student the system sends information to the controller of examination."></asp:Label><br />
<asp:Label ID="Label4" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="Each staff will be able to enter the CIE1 and CIE2 marks based on the privileges provided by coordinator of that respective department. "></asp:Label><br />
<asp:Label ID="Label5" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="Once the staff enters marks for CIE1/CIE2, they won’t be allowed to make changes later on. "></asp:Label><br />
<asp:Label ID="Label6" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="After submitting the marks, the staff will be given with print out of the entered marks for further reference. "></asp:Label><br />
<asp:Label ID="Label7" runat="server" Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Size="Medium" Text="At the end of a semester each student SGPA is calculated and the controller take a back up copy of grade cards and result sheet of all the students. "></asp:Label><br />
<asp:Label ID="Label9" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="Since student grades are sensitive information certain measures are taken to prevent unauthorized access. "></asp:Label><br />
<asp:Label ID="Label8" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="The system also generate the transcript of student which contains all semester marks, Course Title in that particular semester, SGPA of each semester and overall CGPA of that student. "></asp:Label>
</asp:Panel>
<asp:Panel ID="AdminLogin" runat="server" style= "left: 906px; top: 105px; position: absolute; " Visible="False" Width="430px"><br/>
<asp:Label ID="Label10" runat="server" Text="Coordinator Login"></asp:Label><br /><br />
<asp:Label ID="Label11" runat="server" Text="Select Department : "></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" ValidationGroup="AdminLogin"></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminReq1" runat="server" ControlToValidate="DropDownList1" ErrorMessage="Department is blank" ForeColor="Red" ValidationGroup="AdminLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label12" runat="server" Text="Select Branch : "></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" ValidationGroup="AdminLogin"></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminReq2" runat="server" ControlToValidate="DropDownList2" ErrorMessage="Branch is blank" ForeColor="Red" ValidationGroup="AdminLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label13" runat="server" Text="Username : "></asp:Label>
<asp:TextBox ID="AdminTxt1" runat="server" ValidationGroup="AdminLogin" style="height: 22px"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminReq3" runat="server" ControlToValidate="AdminTxt1" ErrorMessage="Username is blank" ForeColor="Red" ValidationGroup="AdminLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label14" runat="server" Text="Password : "></asp:Label>
<asp:TextBox ID="AdminTxt2" runat="server" TextMode="Password" ValidationGroup="AdminLogin"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminReq4" runat="server" ControlToValidate="AdminTxt2" ErrorMessage="Password is blank" ForeColor="Red" ValidationGroup="AdminLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="AdminLog" runat="server" Text="Login" Width="80px" ValidationGroup="AdminLogin" />
<asp:Button ID="AdminSignUp" runat="server" Text="New Coordinator" Width="110px"/>
<asp:Button ID="AdminForPwd" runat="server" Text="Forgot Password" />
</asp:Panel>
<asp:Panel ID="StaffLogin" runat="server" style="left: 906px; top: 105px; position: absolute;" Visible="False" Width="430px"><br />
<asp:Label ID="Label15" runat="server" Text="Staff Login"></asp:Label><br /><br />
<asp:Label ID="Label16" runat="server" Text="Username : "></asp:Label>
<asp:TextBox ID="StaffTxt1" runat="server" Width="127px" ValidationGroup="StaffLogin"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffReq1" runat="server" ControlToValidate=" StaffTxt1" ErrorMessage="Username is blank" ForeColor="Red" ValidationGroup="StaffLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label17" runat="server" Text="Password : "></asp:Label>
<asp:TextBox ID="StaffTxt2" runat="server" TextMode="Password" ValidationGroup="StaffLogin"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffReq2" runat="server" ControlToValidate=" StaffTxt2" ErrorMessage="Password is blank" ForeColor="Red" ValidationGroup="StaffLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="StaffLog" runat="server" Text="Login" Width="80px" ValidationGroup="StaffLogin" />
<asp:Button ID="StaffSignUp" runat="server" Text="New Staff" Width="82px"/>
<asp:Button ID="StaffForPwd" runat="server" Text="Forgot Password" Width="110px" />
</asp:Panel>
<asp:Panel ID="StaffSP" CssClass="modalPopup" style="display: none" runat="server">
<asp:Label ID="Label18" runat="server" Text="Staff Sign Up" Font-Size="XX-Large"></asp:Label><br /><br />
<asp:Label ID="Label19" runat="server" Text="Enter Course Code : "></asp:Label>
<asp:TextBox ID="StaffSPTxt1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffSPReq1" runat="server" ErrorMessage="Course Code is BLANK" ForeColor="Red" ControlToValidate="StaffSPTxt1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label20" runat="server" Text="Enter Password : "></asp:Label>
<asp:TextBox ID="StaffSPTxt2" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffSPReq2" runat="server" ErrorMessage="Password is BLANK" ForeColor="Red" ControlToValidate="StaffSPTxt2"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label21" runat="server" Text="Retype Password : "></asp:Label>
<asp:TextBox ID="StaffSPTxt3" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="StaffSPCom1" runat="server" ErrorMessage="Password Mismatch" ForeColor="Red" ControlToCompare="StaffSPTxt2" ControlToValidate="StaffSPTxt3"></asp:CompareValidator><br /><br />
<asp:Label ID="Label22" runat="server" Text="Enter Password Hint : "></asp:Label>
<asp:TextBox ID="StaffSPTxt4" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffSPReq3" runat="server" ErrorMessage="Password Hint is BLANK" ForeColor="Red" ControlToValidate="StaffSPTxt4"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="Button3" runat="server" Text="Sign Up" />
<asp:Button ID="Button4" runat="server" Text="Cancel" />
</asp:Panel>
<asp:Panel ID="StaffFP" CssClass="modalPopup" style="display: none" runat="server">
<asp:Label ID="Label23" runat="server" Text="Staff Forgot Password" Font-Size="XX-Large"></asp:Label><br /><br />
<asp:Label ID="Label24" runat="server" Text="Enter Username : "></asp:Label>
<asp:TextBox ID="StaffFPTxt1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffFPReq1" runat="server" ErrorMessage="Username is BLANK" ForeColor="Red" ControlToValidate="StaffFPTxt1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label25" runat="server" Text="Enter Password Hint : "></asp:Label>
<asp:TextBox ID="StaffFPTxt2" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffFPReq2" runat="server" ErrorMessage="Hint is BLANK" ForeColor="Red" ControlToValidate="StaffFPTxt2"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="Button5" runat="server" Text="GetPassword" />
<asp:Button ID="Button6" runat="server" Text="Cancel" />
</asp:Panel>
<asp:Panel ID="AdminSP" CssClass="modalPopup" style="display: none" runat="server">
<asp:Label ID="Label26" runat="server" Text="Coordinator Sign Up" Font-Size="XX-Large"></asp:Label><br /><br />
<asp:Label ID="Label27" runat="server" Text="Select Department : "></asp:Label>
<asp:DropDownList ID="AdminSPDrp1" runat="server" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminSPReq1" runat="server" ErrorMessage="Department is BLANK" ForeColor="Red" ControlToValidate="AdminSPDrp1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label28" runat="server" Text="Select Branch : "></asp:Label>
<asp:DropDownList ID="AdminSPDrp2" runat="server" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminSPReq2" runat="server" ErrorMessage="Branch is BLANK" ForeColor="Red" ControlToValidate="AdminSPDrp2"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label29" runat="server" Text="Enter Username : "></asp:Label>
<asp:TextBox ID="AdminSPTxt1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminSPReq3" runat="server" ErrorMessage="Username is BLANK" ForeColor="Red" ControlToValidate="AdminSPTxt1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label30" runat="server" Text="Enter Password : "></asp:Label>
<asp:TextBox ID="AdminSPTxt2" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminSPReq4" runat="server" ErrorMessage="Password is BLANK" ForeColor="Red" ControlToValidate="AdminSPTxt2"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label31" runat="server" Text="Retype Password : "></asp:Label>
<asp:TextBox ID="AdminSPTxt3" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="AdminSPCom1" runat="server" ControlToValidate = "AdminSPTxt3" ControlToCompare = "AdminSPTxt2" ErrorMessage="Password Mismatch" ForeColor="Red"></asp:CompareValidator><br /><br />
<asp:Label ID="Label32" runat="server" Text="Enter Password Hint : "></asp:Label>
<asp:TextBox ID="AdminSPTxt4" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminSPReq5" runat="server" ErrorMessage="Hint is BLANK" ForeColor="Red" ControlToValidate="AdminSPTxt4"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="Button7" runat="server" Text="Sign Up" />
<asp:Button ID="Button8" runat="server" Text="Cancel" />
</asp:Panel>
<asp:Panel ID="AdminFP" CssClass="modalPopup" style="display: none" runat="server">
<asp:Label ID="Label33" runat="server" Text="Coordinator Forgot Password" Font-Size="XX-Large"></asp:Label><br /><br />
<asp:Label ID="Label34" runat="server" Text="Select Department : "></asp:Label>
<asp:DropDownList ID="AdminFPDrp1" runat="server" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminFPReq1" runat="server" ErrorMessage="Department is BLANK" ForeColor="Red" ControlToValidate="AdminFPDrp1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label35" runat="server" Text="Select Branch : "></asp:Label>
<asp:DropDownList ID="AdminFPDrp2" runat="server" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminFPReq2" runat="server" ErrorMessage="Branch is BLANK" ForeColor="Red" ControlToValidate="AdminFPDrp2"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label36" runat="server" Text="Enter Username : "></asp:Label>
<asp:TextBox ID="AdminFPTxt1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminFPReq3" runat="server" ErrorMessage="Username is BLANK" ForeColor="Red" ControlToValidate="AdminFPTxt1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label37" runat="server" Text="Enter Password Hint : "></asp:Label>
<asp:TextBox ID="AdminFPTxt2" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminFPReq4" runat="server" ErrorMessage="Hint is BLANK" ForeColor="Red" ControlToValidate="AdminFPTxt2"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="Button9" runat="server" Text="Sign Up" />
<asp:Button ID="Button10" runat="server" Text="Cancel" />
</asp:Panel>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ModalPopupExtender ID="ModalPopupExtender1" BackgroundCssClass="modalBackground" PopupControlID = "StaffSP" CancelControlID = "Button4" TargetControlID = "StaffSignUp" runat="server"></asp:ModalPopupExtender>
<asp:ModalPopupExtender ID="ModalPopupExtender2" BackgroundCssClass="modalBackground" PopupControlID = "StaffFP" CancelControlID = "Button6" TargetControlID = "StaffForPwd" runat="server"></asp:ModalPopupExtender>
<asp:ModalPopupExtender ID="ModalPopupExtender3" BackgroundCssClass="modalBackground" PopupControlID = "AdminSP" CancelControlID = "Button8" TargetControlID = "AdminSignUp" runat="server"></asp:ModalPopupExtender>
<asp:ModalPopupExtender ID="ModalPopupExtender4" BackgroundCssClass="modalBackground" PopupControlID = "AdminFP" CancelControlID = "Button10" TargetControlID = "AdminForPwd" runat="server"></asp:ModalPopupExtender>
</div>
</form>
</body>
</html>
This is code behind page :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterFinal : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkAdmin_Click(object sender, EventArgs e)
{
AdminLogin.Visible = true;
StaffLogin.Visible = false;
}
protected void LinkStaff_Click(object sender, EventArgs e)
{
AdminLogin.Visible = false;
StaffLogin.Visible = true;
}
}

Related

Onclick event does not response in Update panel

I have a modal inside an update panel which give information of student when click on argument in a grid view.
In my modal I have also 3 textbox in which the value need to be save when click in save button.
It is not triggering the save button.
Here is my code:
<div class="modal fade" id="studinfo" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Student Info</h4>
<button type="button" class="close"
data-dismiss="modal">
×</button>
</div>
<div class="modal-body">
<asp:UpdatePanel ID="updModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<div class="card h-100">
<div class="card-body">
<ul class="list-group list-group-flush">
<asp:TextBox ID="txtId" Visible="false" runat="server"></asp:TextBox>
<asp:Panel ID="typepannel" CssClass="list-group-item" runat="server">
<asp:Label ID="lbltype" runat="server"
Font-Bold="true" Text="Candidate Type: "></asp:Label>
<asp:Label ID="type" runat="server"
Text=''>
</asp:Label>
</asp:Panel>
<asp:Panel ID="colpanel" CssClass="list-group-item" runat="server">
<asp:Label ID="lblCol" runat="server"
Font-Bold="true" Text="College Attend: "></asp:Label>
<asp:Label ID="college" runat="server"
Text=''>
</asp:Label>
</asp:Panel>
<div class="list-group-item">
<asp:Label ID="lblName" runat="server"
Font-Bold="true" Text="Name: "></asp:Label>
<asp:Label ID="Name" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblNic" runat="server"
Font-Bold="true" Text="Nic: "></asp:Label>
<asp:Label ID="Nic" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblAge" runat="server"
Font-Bold="true" Text="Age: "></asp:Label>
<asp:Label ID="Age" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblAdress" runat="server"
Font-Bold="true" Text="Address: "></asp:Label>
<asp:Label ID="Address" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblacad" runat="server"
Font-Bold="true" Text="Academy: "></asp:Label>
<asp:Label ID="Academy" runat="server"
Text=''>
</asp:Label>
</div>
<h6 class="mt-3 mb-3">Parent in Charge</h6>
<div class="list-group-item">
<asp:Label ID="lblParent" runat="server"
Font-Bold="true" Text="Parent Name: "></asp:Label>
<asp:Label ID="parentName" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblNumber" runat="server"
Font-Bold="true" Text="Parent Contact Number: "></asp:Label>
<asp:Label ID="Number" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblEmail" runat="server"
Font-Bold="true" Text="Parent Email Address: "></asp:Label>
<asp:Label ID="Email" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblResult" runat="server"
Font-Bold="true" Text="Result: "></asp:Label>
<asp:DropDownList ID="ddlResult"
CssClass="select form-control"
runat="server">
</asp:DropDownList>
</div>
<div class="list-group-item">
<asp:Label ID="lblMarks" runat="server" Font-Bold="true" Text="Marks: "></asp:Label>
<asp:TextBox runat="server" ID="txtMarks"
CssClass="form-control form-control-lg" />
<asp:RequiredFieldValidator ID="rfvMarks" runat="server"
Display="Dynamic" ForeColor="Red"
ControlToValidate="txtMarks"
SetFocusOnError="true"
ErrorMessage="Marks is Mandatory">
</asp:RequiredFieldValidator>
<asp:CompareValidator ID="cmpVMarks" runat="server"
ControlToValidate="txtMarks"
Operator="DataTypeCheck"
Type="Double"
SetFocusOnError="true"
Display="Dynamic"
Text="Incorect data type"
ForeColor="Red"
ErrorMessage="Invalid">
</asp:CompareValidator>
<asp:RegularExpressionValidator ID="revPhone"
runat="server"
ControlToValidate="txtMarks"
SetFocusOnError="true"
Display="Dynamic"
ForeColor="Red"
ValidationExpression="^\d\d+(\.[1-9])?$"
ErrorMessage="Invalid">
</asp:RegularExpressionValidator>
</div>
<div class="list-group-item">
<asp:Label ID="lblpurcentage" runat="server"
Font-Bold="true" Text="Purcentage : "></asp:Label>
<asp:TextBox runat="server" ID="txtpur"
CssClass="form-control form-control-lg" />
<asp:RequiredFieldValidator
ID="rfvpur" runat="server"
Display="Dynamic" ForeColor="Red"
ControlToValidate="txtpur"
SetFocusOnError="true"
ErrorMessage="Purcentage is Mandatory">
</asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvpur" runat="server"
ControlToValidate="txtpur"
Operator="DataTypeCheck"
Type="Double"
SetFocusOnError="true"
Display="Dynamic"
Text="Incorect data type"
ForeColor="Red"
ErrorMessage="Invalid">
</asp:CompareValidator>
</div>
</ul>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnSave" OnClick="btnSave_Click"
CssClass="btn btn-success btn-block" runat="server" Text="Save" />
</div>
</div>
To make this data appear in modal I used updModal.Update(); in the button where I use to call the modal.
Here is my code behind of save button:
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
string id = txtId.Text;
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update tblStudent set stud_result=#res,stud_purcentage=#pur,stud_totalMarks=#marks where stud_Id=#id";
cmd.Parameters.AddWithValue("#id", id);
cmd.Parameters.AddWithValue("#res", ddlResult.SelectedValue);
cmd.Parameters.AddWithValue("#pur", txtpur.Text.Trim());
cmd.Parameters.AddWithValue("#marks", txtMarks.Text.Trim());
con.Open();
cmd.Connection = con;
updModal.Update();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, GetType(), "LaunchServerSide",
"$(function () { showUErrorModal(); });", true);
}
finally
{
con.Close();
}
}
When I have try to put the button inside the update panel it freeze the app when I triger the button.
Can someone please please help me with that? Thank you in advance.

OnChanged even't isn't firing (AJAX raiting control) inside a datalist

I'm using the latest ajax toolkit version. I've tried to put the rating control in a datalist, but the OnChanged event for some reason isn't firing.
That's the normal ASPX.NET page:
<asp:DataList ID="DataListEpisodes" runat="server" Style="position: relative; bottom: 330px;" Visible="False" RepeatColumns="1" OnItemDataBound="DataListEpisodes_ItemDataBound" DataKeyField="EpisodeID" OnItemCommand="DataListEpisodes_ItemCommand">
<ItemTemplate>
<table>
<tr>
<td>
<td>
<asp:Image ID="ImageEpisodeImage" class="EpisodeImage" runat="server" ImageUrl='<%# Eval("EpisodeImage", "https://image.tmdb.org/t/p/original{0}") %>' />
</td>
</td>
<td>
<asp:Label ID="LabelEpisodeNumber" runat="server" Style="font-family: Gotham Ultra; font-size: 25px; font-weight: bold;"
Text='<%# Eval("SeasonNumber", "Season {0}") + ", " + Eval ("EpisodeNumber", "Episode {0}") %>'></asp:Label>
<br />
<asp:Label ID="LabelEpisodeName" Style="font-family: Proxima Nova Semibold; font-size: 20px; font-weight: bold;" runat="server" Text='<%# Bind("EpisodeName") %>'></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" class="LabelOverview" Text='<%# Bind("EpisodeOverview") %>' TextMode="MultiLine"></asp:TextBox>
<br />
<asp:Button ID="ButtonAddEpisode" class="ButtonAddEpisode" runat="server" Text="Add Episode To Watch History" CommandName="AddEpisode" />
<asp:Button ID="ButtonRemoveEpisode" class="ButtonAddEpisode" runat="server" Text="Remove Episode From Watch History" CommandName="RemoveEpisode" />
<br />
<asp:Button ID="ButtonWatchListAdd" class="ButtonEpisodeWatchList" runat="server" Text="Add Episode To Future Watch List" CommandName="AddWatchList" />
**<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<ajaxToolkit:Rating ID="Rating1" OnChanged="OnRatingChanged" style="position: relative;right: 301px;top: 16px;" AutoPostBack="true" runat="server"
StarCssClass="Star" EmptyStarCssClass="Star"
FilledStarCssClass="FilledStar" WaitingStarCssClass="Star">
</ajaxToolkit:Rating>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Rating1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>**
</tr>
</table>
<br />
<br />
<br />
<br />
</ItemTemplate>
</asp:DataList>
and that's the codebehind:
protected void OnRatingChanged(object sender, AjaxControlToolkit.RatingEventArgs e)
{
int rowIndex = ((sender as AjaxControlToolkit.Rating).NamingContainer as DataListItem).ItemIndex;
int RatingChosed = Rating1.CurrentRating;
int EpisodeID = Convert.ToInt32(DataListEpisodes.DataKeys[rowIndex].ToString());
}
Thank you if someone can help me :D

Change Gridview column widths dynamically in edit mode

I have a gridview that can have 1 or 2 controls displayed in 1 column when in edit mode depending on the selection of a dropdown in another column. One control is a textbox the other a label. I have the textbox first and the label beside the textbox after it. My problem is when the textbox and label are showing, the label's text extends into the next column. I would like the column width to be as wide as the controls displayed.
How can I do this?
This is my markup for the grid:
<div id="DeviceGridWrapper">
<asp:TextBox ID="RecipientID" runat="server" Visible="false"> </asp:TextBox>
<asp:GridView ID="DeviceInfoGridView" runat="server"
AutoGenerateColumns="False" Caption="Device Information"
CaptionAlign="Top" CssClass="grid" RowStyle-Wrap="true"
HorizontalAlign="Left" ShowFooter="True" PageSize="5"
ShowHeaderWhenEmpty="False"
OnRowCancelingEdit="DeviceInfoGridView_RowCancelingEdit"
OnRowDataBound="DeviceInfoGridView_RowDataBound"
OnRowDeleting="DeviceInfoGridView_RowDeleting"
OnRowEditing="DeviceInfoGridView_RowEditing"
OnRowUpdating="DeviceInfoGridView_RowUpdating" AllowPaging="True"
ondatabound="DeviceInfoGridView_DataBound"
onrowcommand="DeviceInfoGridView_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Device ID">
<ItemTemplate>
<asp:Label ID="digvLblDeviceID" runat="server" Text='<%# Bind("DeviceID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Device" ItemStyle-Wrap="false">
<ItemTemplate>
<asp:Label ID="digvLblDeviceName" runat="server" Text='<%# Bind("DeviceName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="digvEditDeviceName" runat="server" Visible="false" Text='<%# Bind("DeviceName") %>'></asp:Label>
<asp:DropDownList ID="digvDDListDeviceName" runat="server" ClientIDMode="Static"
data-placeholder="Choose device…" class="chosen-single"></asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLDeviceNameEdit" runat="server"
ControlToValidate="digvDDListDeviceName" ValidationGroup="EditDeviceValidation"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="digvDDListDeviceNameInsert" runat="server" ClientIDMode="Static"
data-placeholder="Choose device…" class="chosen-single">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLDeviceNameInsert" runat="server" InitialValue="0"
ControlToValidate="digvDDListDeviceNameInsert" ValidationGroup="InsertDeviceValidation"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Service Provider">
<ItemTemplate>
<asp:Label ID="digvLblServiceName" runat="server" Text='<%# Bind("ServiceName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="digvEditServiceName" runat="server" Visible="false" Text='<%# Bind("ServiceName") %>'></asp:Label>
<asp:DropDownList ID="digvDDListServiceName" runat="server" ClientIDMode="Static"
OnSelectedIndexChanged="DeviceInfoGridView_SelectedIndexChanged_EditServiceName" AutoPostBack="true" EnableViewState="true"
data-placeholder="Choose service…" class="chosen-single"></asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLServiceNameEdit" runat="server"
ControlToValidate="digvDDListServiceName" ValidationGroup="EditDeviceValidation"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="digvDDListServiceNameInsert" runat="server" ClientIDMode="Static" Enabled="false"
data-placeholder="Choose service…" class="chosen-single">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLServiceNameInsert" runat="server" InitialValue="0"
ControlToValidate="digvDDListServiceNameInsert" ValidationGroup="InsertDeviceValidation"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<asp:Label ID="digvLblAddress" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="digvTxtBoxAddress" runat="server" Text='<%# Bind("Address") %>' Width="50%" ClientIDMode="Static"></asp:TextBox>
<asp:Label ID="digvEditAddressExt" runat="server" Visible="false" Text='<%# Bind("ServiceExtension") %>' Width="40%"
ClientIDMode="Static"></asp:Label>
<asp:RequiredFieldValidator ID="ReqValueAddressEdit" runat="server"
ControlToValidate="digvTxtBoxAddress" ValidationGroup="EditDeviceValidation"
ErrorMessage="Required field." CssClass="message-error">
</asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValAddressEdit" runat="server" ControlToValidate="digvTxtBoxAddress" CssClass="message-error"
ErrorMessage="*" ClientValidationFunction="ValidateAddressEdit" EnableClientScript="true"
ValidationGroup="EditDeviceValidation" ></asp:CustomValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="digvTxtBoxAddressInsert" runat="server" ClientIDMode="Static"></asp:TextBox>
<asp:RequiredFieldValidator ID="ReqValueAddressInsert" runat="server"
ControlToValidate="digvTxtBoxAddressInsert" ValidationGroup="InsertDeviceValidation"
ErrorMessage="Required field." CssClass="message-error">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Active">
<ItemTemplate>
<asp:Label ID="digvLblActive" runat="server" Text='<%# (Boolean.Parse(Eval("Active").ToString())) ? "Yes" : "No" %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="digvDDListActive" runat="server" Text='<%# (Boolean.Parse(Eval("Active").ToString())) ? "Yes" : "No" %>'>
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="digvDDListActiveInsert" runat="server">
<asp:ListItem Selected="True">Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ShowHeader="False" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="digvEditButton" runat="server" CausesValidation="True" CommandName="Edit"
Text="Edit" CssClass="gridActionbutton" ValidationGroup="EditDeviceValidation">
</asp:Button>
<asp:Button ID="digvDeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete" CssClass="gridActionbutton" OnClientClick="return confirm('Are you sure you want to delete this Device Information?')" >
</asp:Button>
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="digvUpdateButton" runat="server" CausesValidation="True" ValidationGroup="EditDeviceValidation" CommandName="Update"
Text="Update" CssClass="gridActionbutton"></asp:Button>
<asp:Button ID="uigvCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel" CssClass="gridActionbutton"></asp:Button>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="digvAddButton" runat="server" CommandName="Add" Text="Add Device" Width="90%" CausesValidation="true"
CssClass="gridActionbutton" ValidationGroup="InsertDeviceValidation">
</asp:Button>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<tr>
<th>Device ID</th>
<th>Device</th>
<th>Service Provider</th>
<th>Address</th>
<th>Active</th>
<th>Action</th>
</tr>
<tr>
<td colspan="7" style="text-align:center;">
No Devices were found for you. Devices can be added by clicking the 'Add Device' Button.
</td>
</tr>
<tr>
<td></td>
<td>
<asp:DropDownList ID="digvDDListDeviceNameInsert" runat="server" ClientIDMode="Static"
data-placeholder="Choose device…" class="chosen-single">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLDeviceNameEmpty" runat="server" InitialValue="0"
ControlToValidate="digvDDListDeviceNameInsert" ValidationGroup="InsertDeviceValidationEmpty"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</td>
<td>
<asp:DropDownList ID="digvDDListServiceNameInsert" runat="server" ClientIDMode="Static" Enabled="false"
data-placeholder="Choose service…" class="chosen-single">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLServiceNameEmpty" runat="server" InitialValue="0"
ControlToValidate="digvDDListServiceNameInsert" ValidationGroup="InsertDeviceValidationEmpty"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</td>
<td>
<asp:TextBox ID="digvTxtBoxAddressInsert" runat="server" ClientIDMode="Static"></asp:TextBox>
<asp:RequiredFieldValidator ID="ReqValueAddressEmpty" runat="server"
ControlToValidate="digvTxtBoxAddressInsert" ValidationGroup="InsertDeviceValidationEmpty"
ErrorMessage="Required field." CssClass="message-error">
</asp:RequiredFieldValidator>
</td>
<td>
<asp:DropDownList ID="digvDDListActiveInsert" runat="server">
<asp:ListItem Selected="True">Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:Button ID="digvAddButtonEmpty" runat="server" CommandName="Add" Text="Add Device" Width="90%" CausesValidation="true"
CssClass="gridActionbutton" ValidationGroup="InsertDeviceValidationEmpty">
</asp:Button>
</td>
</tr>
</EmptyDataTemplate>
</asp:GridView>
</div>
This is my current styling of the grid:
.grid
{background-color: #fff;
border: solid 2px #000;
border-collapse:collapse;
color: #FFF; overflow:auto
}
.grid td {
padding-left: 5px;
color: #000;
font-size: medium;
}
.grid th {
color: #000;
background: #99C3BB;
font-size: medium;
font-weight: bold;
}
.grid caption {
color: #000;
text-align:center;
font-weight:bold;
font-size:1.2em;
padding: 2px;
background-color: #99C3BB;
border: 2px solid black;
}
.grid table tr td {
color: #000;
font-size: small;
padding: 5px;
}
#DeviceGridWrapper
{
height: 250px;
width: 100%;
padding-bottom: 10px;
}
The column that is the problem is the 'Address' column. When only the textbox shows the width is set to '90%' programmatically. When the textbox and label are shown, the textbox is set to '50%' and the label is '40%'. They are side-by-side which is what I want. I need the Address column to widen to accomodate both of the controls so that the label does not extend into the next column.
Is there a way to set the Address column to a width that accomodates both controls?
Thanks.
Try using <EditRowStyle> element to the GridView::
<asp:GridView ID="GridView1" runat="server">
<EditRowStyle BackColor="Red" Width="100%" />
</asp:GridView>

multiple forms run at server make visible to client asp.net

i have made registeration form, forgot password and login form in a single aspx page . I am using css to style the whole form. I am using 3 form tags. Here is code:
ASMX
<form id="form1" runat="server" visible="true">
<ul>
<li>
<asp:TextBox ID="email" runat="server" TextMode="email" placeholder="Email" OnTextChanged="email_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="email" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*Requied</asp:RequiredFieldValidator>
</li>
<li>
<asp:TextBox ID="password" runat="server" TextMode="Password" placeholder="Password" OnTextChanged="password_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="password" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*Requied</asp:RequiredFieldValidator>
</li>
<li>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</li>
<li>
<asp:Label ID="Invalid" runat="server" Text="Invalid Username or Password" Visible="False" ></asp:Label>
<asp:Label ID="Try" runat="server" Text="You can't try again ,Register Your Self" Visible="False"></asp:Label>
</li>
</ul>
</form>
<form runat="server" id="form2" visible="false">
<ul>
<li>
<asp:TextBox ID="username" runat="server" MaxLength="15" placeholder="UserName" OnTextChanged="username_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="username" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input user name</asp:RequiredFieldValidator>
<asp:Label ID="userchk" runat="server" ForeColor="Red"></asp:Label>
</li>
<li>
<asp:TextBox ID="EmailR" runat="server" placeholder="Email (must be valid)" OnTextChanged="EmailR_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="EmailR" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input email</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="EmailR" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="RegularExpressionValidator" ForeColor="Red">Input Valid Email</asp:RegularExpressionValidator>
</li>
<li>
<asp:TextBox ID="FirstName" runat="server" placeholder="FirstName" MaxLength="15" OnTextChanged="FirstName_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="FirstName" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input first name</asp:RequiredFieldValidator>
<asp:Label ID="chkemail" runat="server" ForeColor="Red"></asp:Label>
</li>
<li>
<asp:TextBox ID="LastName" runat="server" placeholder="Lastname" MaxLength="15" OnTextChanged="TextBox3_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="LastName" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input Last name</asp:RequiredFieldValidator>
</li>
<li>
<asp:TextBox ID="Pass" runat="server" placeholder="Password" TextMode="Password" MaxLength="15" OnTextChanged="Pass_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="Pass" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input password</asp:RequiredFieldValidator>
</li>
<li>
<asp:TextBox ID="Cpass" runat="server" placeholder="Confirm Password" TextMode="Password" MaxLength="15" OnTextChanged="Cpass_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="Cpass" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Enter the Confirm Password </asp:RequiredFieldValidator>
</ul>
</form>
<form runat="server" visible="false" id="form3">
<ul>
<li>
<asp:TextBox ID="SendEmail" runat="server" TextMode="Email" placeholder="Enter Email" OnTextChanged="SendEmail_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="SendEmail" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*Requied</asp:RequiredFieldValidator>
</li>
<li>
<asp:Button runat="server" text="Send email" OnClick="SendMail_Click" CssClass="button" Visible="true" CausesValidation="False"/>
</li>
<li>
<asp:Label ID="ml" runat="server" Text="Email sended Sucessfully" Visible="False"></asp:Label>
<asp:Label ID="ml0" runat="server" Text="Email Didn't Match " Visible="False"></asp:Label>
</li>
</ul>
</form>
I used following Js in toglling categories:
JS
<script>
$(document).ready(function () {
$("#list1").click(function () {
$("#form1").fadeIn("slow");
$("#form2").css("display", "none");
$("#form3").css("display", "none");
});
$("#list2").click(function () {
$("#form2").fadeIn("slow");
$("#form2").css("visible", "true");
$("#form1").css("display", "none");
$("#form3").css("display", "none");
});
$("#list3").click(function () {
$("#form3").fadeIn("slow");
$("#form3").css("visible", "true");
$("#form2").css("display", "none");
$("#form1").css("display", "none");
});
});
</script>
and here is my css FORMS
I have to use multiple forms in any case .. can anyone help please??

Updatepage | Why does my image field in db get overwritten with null value when I update?

I'm new to coding, so sorry if some of my jargon is wrong.
I'm trying to make an update page that will update database values. All other fields update fine, however whenever I attempt to update the database without an image upload, it will replace the current field value with a null value. Any help would be appreciated to remedy this issue. Exact code would be excellent, as I said before I'm new to coding, especially asp.net and C# so some terms are new to me.
Below is my code behind file, I imagine this is the cause of my problem.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class admin_updatenews : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void displayedit_ItemUpdated(object sender, ListViewUpdatedEventArgs e)
{
info.Text = "Item Updated";
FileUpload fileupdate = displayedit.EditItem.FindControl("imageupdate") as FileUpload;
Label recordid = displayedit.EditItem.FindControl("idlabel1") as Label;
Int32 id = Convert.ToInt32(recordid.Text);
if (fileupdate.HasFile)
{
String fupload = fileupdate.FileName;
Random r = new Random();
int rInt = r.Next(0, 10000);
String imgpath = "../images/" + rInt + fupload;
fileupdate.SaveAs(Server.MapPath(imgpath));
String newimage = rInt + fupload;
string newsconnection = WebConfigurationManager.ConnectionStrings["newsconnection"].ConnectionString;
SqlConnection myConnection = new SqlConnection(newsconnection);
//myConnection.ConnectionString is now set to connectionString.
myConnection.Open();
String query = "UPDATE News SET postimage ='" + newimage + "', Image ='" + newimage + "' WHERE id='" + id + "'";
SqlCommand myCommand = new SqlCommand(query, myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
protected void displayedit_ItemEditing(object sender, ListViewEditEventArgs e)
{
info.Text = "I am editing";
}
protected void displayedit_ItemCanceling(object sender, ListViewCancelEventArgs e)
{
info.Text = "Not Updating";
}
}
This is the front end code in case that is required
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Copy of updatenews.aspx.cs" Inherits="admin_updatenews" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="../css/responsive.css" rel='stylesheet' type='text/css' />
<link href="../css/gui.css" rel='stylesheet' type='text/css' />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="newseditrows" runat="server"
ConnectionString='<%$ ConnectionStrings:newsconnection %>'
SelectCommand="SELECT News.id, News.headline, News.Image, News.paragraph, Sportslist.sportname, News.Sport, News.date, News.lead, News.authorID, Sportslist.id, News.postheadline, News.postimage, News.postparagraph, News.postsport, News.postdate, News.postlead, News.postauthorid
FROM News
INNER JOIN Sportslist ON News.Sport = Sportslist.id
ORDER BY News.id DESC"
UpdateCommand="UPDATE [News] SET [headline]=#headline, [Image]=#Image, [paragraph]=#paragraph, [Sport]=#sport, [date]=#date, [lead]=#lead, [authorid]=#authorid, [postheadline]=#headline, [postimage]=#Image, [postparagraph]=#paragraph, [postsport]=#sport, [postdate]=#date, [postlead]=#lead, [postauthorid]=#authorid WHERE [id]=#id">
<UpdateParameters>
<asp:Parameter Name="headline" Type="String" />
<asp:Parameter Name="Image" Type="String" />
<asp:Parameter Name="paragraph" Type="String" />
<asp:Parameter Name="Sport" Type="Int32" />
<asp:Parameter Name="date" Type="DateTime" />
<asp:Parameter Name="lead" Type="String" />
<asp:Parameter Name="authorid" Type="Int32" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sportlist" runat="server"
ConnectionString='<%$ ConnectionStrings:newsconnection %>'
SelectCommand="SELECT [id], [sportname] FROM [Sportslist]">
</asp:SqlDataSource>
<asp:Label ID="info" runat="server" Text="Not Updating"></asp:Label>
<br />
<asp:ListView ID="displayedit" runat="server"
DataSourceID="newseditrows"
DataKeyNames="id"
OnItemUpdated="displayedit_ItemUpdated"
OnItemEditing="displayedit_ItemEditing"
OnItemCanceling="displayedit_ItemCanceling">
<AlternatingItemTemplate>
<span style="">id:
<asp:Label Text='<%# Eval("id") %>' runat="server" ID="idLabel" /><br />
headline:
<asp:Label Text='<%# Eval("headline") %>' runat="server" ID="headlineLabel" /><br />
Image:
<asp:Image ID="ImageLabel" runat="server" ImageURL='<%# "../images/" + Eval("Image") %>' Width="100px" />
<br />
paragraph:
<asp:Label Text='<%# Eval("paragraph") %>' runat="server" ID="paragraphLabel" /><br />
Sport:
<asp:Label Text='<%# Eval("sportname") %>' runat="server" ID="SportLabel" /><br />
date:
<asp:Label Text='<%# Eval("date") %>' runat="server" ID="dateLabel" /><br />
lead:
<asp:Label Text='<%# Eval("lead") %>' runat="server" ID="leadLabel" /><br />
authorID:
<asp:Label Text='<%# Eval("authorID") %>' runat="server" ID="authorIDLabel" /><br />
<asp:Button runat="server" CommandName="Edit" Text="Edit" ID="EditButton" />
<br />
<br />
</span>
</AlternatingItemTemplate>
<EditItemTemplate>
<span style="">id:
<asp:Label Text='<%# Eval("id") %>' runat="server" ID="idLabel1" /><br />
headline:
<asp:TextBox Text='<%# Bind("headline") %>' runat="server" ID="headlineTextBox" /><br />
Image:
<asp:Image ID="ImageTextBox1" runat="server" ImageUrl='<%# "../images/" + Eval("Image") %>' Width="100px"/>
<asp:FileUpload ID="imageupdate" runat="server" />
<br />
paragraph:
<asp:TextBox Text='<%# Bind("paragraph") %>' runat="server" ID="paragraphTextBox" /><br />
Sport:
<%--<asp:TextBox Text='<%# Bind("Sport") %>' runat="server" ID="SportTextBox" />--%>
<asp:DropDownList ID="SportsDropdown" runat="server" SelectedValue='<%# Bind("Sport") %>'>
<asp:ListItem Value="1">Football</asp:ListItem>
<asp:ListItem Value="2">Rugby</asp:ListItem>
<asp:ListItem Value="3">Basketball</asp:ListItem>
<asp:ListItem Value="4">Motorsport</asp:ListItem>
<asp:ListItem Value="5">NFL</asp:ListItem>
<asp:ListItem Value="6">Cricket</asp:ListItem>
<asp:ListItem Value="7">Tennis</asp:ListItem>
<asp:ListItem Value="8">Golf</asp:ListItem>
<asp:ListItem Value="9">Other</asp:ListItem>
</asp:DropDownList>
<br />
lead:
<asp:TextBox Text='<%# Bind("lead") %>' runat="server" ID="leadTextBox" /><br />
<asp:Button runat="server" CommandName="Update" Text="Update" ID="UpdateButton" /><asp:Button runat="server" CommandName="Cancel" Text="Cancel" ID="CancelButton" /><br />
<br />
</span>
</EditItemTemplate>
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<InsertItemTemplate>
<span style="">headline:
<asp:TextBox Text='<%# Bind("headline") %>' runat="server" ID="headlineTextBox" /><br />
Image:
<asp:TextBox Text='<%# Bind("Image") %>' runat="server" ID="ImageTextBox" /><br />
paragraph:
<asp:TextBox Text='<%# Bind("paragraph") %>' runat="server" ID="paragraphTextBox" /><br />
Sport:
<asp:TextBox Text='<%# Bind("Sport") %>' runat="server" ID="SportTextBox" /><br />
date:
<asp:TextBox Text='<%# Bind("date") %>' runat="server" ID="dateTextBox" /><br />
lead:
<asp:TextBox Text='<%# Bind("lead") %>' runat="server" ID="leadTextBox" /><br />
authorID:
<asp:TextBox Text='<%# Bind("authorID") %>' runat="server" ID="authorIDTextBox" /><br />
<asp:Button runat="server" CommandName="Insert" Text="Insert" ID="InsertButton" /><asp:Button runat="server" CommandName="Cancel" Text="Clear" ID="CancelButton" /><br />
<br />
</span>
</InsertItemTemplate>
<ItemTemplate>
<span style="">id:
<asp:Label Text='<%# Eval("id") %>' runat="server" ID="idLabel" /><br />
headline:
<asp:Label Text='<%# Eval("headline") %>' runat="server" ID="headlineLabel" /><br />
Image:
<asp:Image ID="ImageLabel" runat="server" ImageURL='<%# "../images/" + Eval("Image") %>' Width="100px" />
<br />
paragraph:
<asp:Label Text='<%# Eval("paragraph") %>' runat="server" ID="paragraphLabel" /><br />
Sport:
<asp:Label Text='<%# Eval("sportname") %>' runat="server" ID="SportLabel" /><br />
date:
<asp:Label Text='<%# Eval("date") %>' runat="server" ID="dateLabel" /><br />
lead:
<asp:Label Text='<%# Eval("lead") %>' runat="server" ID="leadLabel" /><br />
authorID:
<asp:Label Text='<%# Eval("authorID") %>' runat="server" ID="authorIDLabel" /><br />
<asp:Button runat="server" CommandName="Edit" Text="Edit" ID="EditButton" />
<br />
<br />
</span>
</ItemTemplate>
<LayoutTemplate>
<div runat="server" id="itemPlaceholderContainer" style=""><span runat="server" id="itemPlaceholder" /></div>
<div style="">
<asp:DataPager runat="server" ID="DataPager1">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False"></asp:NextPreviousPagerField>
<asp:NumericPagerField></asp:NumericPagerField>
<asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False"></asp:NextPreviousPagerField>
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
<SelectedItemTemplate>
<span style="">id:
<asp:Label Text='<%# Eval("id") %>' runat="server" ID="idLabel" /><br />
headline:
<asp:Label Text='<%# Eval("headline") %>' runat="server" ID="headlineLabel" /><br />
Image:
<asp:Label Text='<%# Eval("Image") %>' runat="server" ID="ImageLabel" /><br />
paragraph:
<asp:Label Text='<%# Eval("paragraph") %>' runat="server" ID="paragraphLabel" /><br />
Sport:
<asp:Label Text='<%# Eval("Sport") %>' runat="server" ID="SportLabel" /><br />
date:
<asp:Label Text='<%# Eval("date") %>' runat="server" ID="dateLabel" /><br />
lead:
<asp:Label Text='<%# Eval("lead") %>' runat="server" ID="leadLabel" /><br />
authorID:
<asp:Label Text='<%# Eval("authorID") %>' runat="server" ID="authorIDLabel" /><br />
<asp:Button runat="server" CommandName="Edit" Text="Edit" ID="EditButton" />
<br />
<br />
</span>
</SelectedItemTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
Here is example of the update statement using ur query.
UPDATE News
SET postimage = ISNULL(YourNewValue, postimage), Image = ISNULL(YourNewValue, Image)
WHERE id = YourID
EDIT :
try adding following in your datasource updateCommand. if this doesn't solve than try stepping through to see where this is adding null.
UpdateCommand="UPDATE [News] SET [headline]=#headline, [Image]= ISNULL(#Image, [Image]), [paragraph]=#paragraph, [Sport]=#sport, [date]=#date, [lead]=#lead, [authorid]=#authorid, [postheadline]=#headline, [postimage]=#Image, [postparagraph]=#paragraph, [postsport]=#sport, [postdate]=#date, [postlead]=#lead, [postauthorid]=#authorid WHERE [id]=#id">

Categories

Resources