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.
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
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>
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??
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">