pop up page , when a link button is clicked - c#

<td colspan ="2" style="width: 64px">
<div style="float:left; padding-left:9px;">
<asp:LinkButton ID="lnkremoveloc" runat="server"
OnClick="lnkremoveloc_Click" CssClass="linkclass"
style="cursor:pointer" Font-Underline="True"
Font-Bold="true" Font-Size="12px">
Remove Location
</asp:LinkButton>
</div>
</td>
This is the link button from where i get a popup when clicked.
The popup page is like below. But when i click this link, the same page gets refreshed and i loose Save and Cancel button instead of opening a popup. Can someone help me out. I have no idea where i am doing wrong. Thanks a lot...
<%# Page Language="C#" AutoEventWireup="true" CodeFile="DisableLocation.aspx.cs" Inherits="DisableLocation" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%--<html xmlns="http://www.w3.org/1999/xhtml" >--%>
<script language ="javascript" type="text/javascript" >
function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no,
status=no, menubar=no,scrollbars=no, resizable=no, copyhistory=no, width='+w+',
height='+h+', top='+top+', left='+left);
}
</script language ="javascript" type="text/javascript">
<html>
<head runat="server">
<title>Disable Location | DealTown.com</title>
</head>
<body>
<form id="form1" runat="server">
<div style="display: block; background: url(images/reusable_blue_bg.jpg) repeat-x 0 -15px;border-left: #88b9c7 1px solid; border-bottom:#88b9c7 1px solid; border-top:#88b9c7 1px solid; border-right: #88b9c7 1px solid; padding: 0px 2px; height: 236px; min-height: 236px; height: auto; margin-left: auto; margin-right: auto;">
<table align="center" style="width: 554px; border-top-style: none; border-right-style: none;
border-left-style: none; border-bottom-style: none" id="TABLE1">
<tr >
<td align="center" colspan="5" style="font-weight:normal;font-size:18px;margin: 0px;font-family: Arial;color: #1e7c9b;" >Disable Location</td>
</tr>
<asp:GridView ID="diableloc" runat="server" AutoGenerateColumns="False"
DataKeyNames="LocationName" DataSourceID="getGridMerchantLocationData"
AllowPaging="True" EnableViewState="False">
<Columns>
<asp:BoundField DataField="chkbox" HeaderText="Select"
SortExpression="Selection" />
<asp:BoundField DataField="locname" HeaderText="Location Name"
ReadOnly="True" SortExpression="Locnames" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ProductsDataSource" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetLocations" TypeName="string">
</asp:ObjectDataSource>
</table>
<tr>
<td style="width: 44px; height: 63px">
</td>
<td style="width: 127px; height: 63px">
</td>
<td align="left" colspan="2" style="height: 63px; width: 196px;">
<asp:ImageButton ID="btnDisable" runat="server" ImageUrl="~/images/save.gif" OnClick="btnDisable_Click"
ValidationGroup="group1" />
<asp:ImageButton ID="btnCancel" runat="server" ImageUrl="~/images/cancel.gif" OnClick="btnCancel_Click" /></td>
<td colspan="1" style="width: 92px; height: 63px">
</td>
</tr>
</div>
</form>
</body>
</html>

Sounds like the page is posting back. Did you try AutoPostBack="false"? Not sure you need a LinkButton here. Can you just use a anchor tag with onclick instead to invoke the popup?
Do you have code that needs to execute on the server side when the LinkButton is clicked? If you need both you can use the OnClientClick property to have both. It has been a while, but I think you can make it so the server code won't execute if the value returned from the client side code in onclientclick returns false.
I don't see how your current LinkButton shows the popup.

Instead of OnClick use OnClientClick="lnkremoveloc_Click" where lnkremoveloc_Click is JavaScript function (somthing like PopupCenter you already have) that opens popup window.

Set the onclientclick instead of onclick. And while rendering(page load) itself set the onclientclick as "PopupCenter('url','title',....);return false;"
The url, title, width, etc can be set on load. The last part "return false" will annul the effect of click. Thus it prevents post back.
Note: If you want something to be processed at server side, its better not to set the onclientclick and use
Response.write("<script>PopupCenter('url','title',....);</script>");
I hope that helps.
This is my first post :)

Related

Layout messes up when moved to stylesheet

I am a new one to ASP.NET and currently learning from the book "Beginning ASP.NET with Visual Studio 2015" by William Penberthy. In the chapter 7 about layout with master pages I created a custom master page WebForms with stylesheet RentMyWrox and moved the inline style for various controls of the page ManagedItems.aspx to RentMyWrox.css. This cause the layout to mess up.
When I switched back to default master page and added the inline style to default Site.css stylesheet the layout was displayed correctly. I downloaded the source code for the book and it has the same issue. Could anyone explain, what is the problem?
My custom master page WebForms.Master
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="WebForms.master.cs"
Inherits="RentMyWrox.WebForms" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link href="Content/RentMyWrox.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div id="header">
</div>
<div id="nav">
Navigation content here
</div>
<div id="section">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="footer">
Footer content here
</div>
</form>
</body>
</html>
Stylesheet for custom master page RentMyWrox.css
body {
font-family: verdana;
}
#header {
background-color:#C40D42;
color:white;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:750px;
float:left;
padding:10px;
}
#footer {
background-color:#C40D42;
color:white;
clear:both;
text-align:center;
padding:5px;
}
.dataentry input{
width: 250px;
margin-left: 20px;
margin-top: 15px;
}
.dataentry textarea{
width: 250px;
margin-left: 20px;
margin-top: 15px;
}
.dataentry label{
width: 75px;
margin-left: 20px;
margin-top: 15px;
}
#fuPicture {
margin-top: -20px;
margin-left: 120px;
}
Page ManagedItems.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/WebForms.Master" AutoEventWireup="true" CodeBehind="ManageItem.aspx.cs" Inherits="RentMyWrox.Admin.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
<div class="dataentry">
<asp:Label ID="Label1" runat="server" Text="Name"
AssociatedControlID="tbName"></asp:Label>
<asp:TextBox ID="tbName" runat="server"></asp:TextBox>
</div>
<div class="dataentry">
<asp:Label ID="Label2" runat="server" Text="Description"
AssociatedControlID="tbDescription"></asp:Label>
<asp:TextBox ID="tbDescription" runat="server"
TextMode="MultiLine" Rows="5"></asp:TextBox>
</div>
<div class="dataentry">
<asp:Label ID="Label3" runat="server" Text="Cost"
AssociatedControlID="tbCost"></asp:Label>
<asp:TextBox ID="tbCost" runat="server"></asp:TextBox>
</div>
<div class="dataentry">
<asp:Label runat="server" Text="Item Number" AssociatedControlID="tbItemNumber"/>
<asp:TextBox runat="server" ID="tbItemNumber" /> </div> <div class="dataentry">
<asp:Label runat="server" Text="Picture" AssociatedControlID="fuPicture" />
<asp:FileUpload ID="fuPicture" ClientIDMode="Static" runat="server" />
</div>
<div class="dataentry">
<asp:Label runat="server" Text="Acquired Date" AssociatedControlID="tbAcquiredDate"/>
<asp:TextBox runat="server" ID="tbAcquiredDate"/>
</div>
<asp:Button Text="Save Item" runat="server" OnClick="SaveItem_Click" />
</div>
</asp:Content>
This is how it should look according to the book
This is how it actually looks like
The source code can be downloaded at http://media.wiley.com/product_ancillary/27/11190774/DOWNLOAD/RentMyWrox_Chapter7_CSharp..zip
Is the code attached/linked the "before" or "after" modification code?
My recommendation is to use the tools of your browser to check if the CSS file was actually loaded. In Chrome, you can press F12 and then click on the "Sources" tab. This will show you what is loaded down the left, I'm guessing your CSS file is not there.
If that's the case, it might be your reference in your master file.
Currently you have it as:
But that link is not a valid link from your manageitem.aspx page which is inside the 'Admin' folder.
Instead, try "~/Content/RentMyWrox.css" - this should map the proper path from the root of your application, rather than relative to whichever child page is loading the master.

How to Scroll start with bottom when page is loaded

Hi I am doing a social network service using asp.net/c#, I have little problems with message sending.
when i am starting to send message scroll display like this. when i press send message it shows old message first and scroll is top, but i want newer message it mean's when i page loaded page should be showed new messages first
my aspx codes
<div style=" overflow-y:auto; height:368px; margin-top: -50px; border-top-style: groove; border-right-style: groove; border-left-style: groove; width: 602px; margin-left: 0px;" >
<asp:Repeater runat="server" ID="Repeater1" >
<ItemTemplate>
<div style="border-top: thin none #BBCEB3; border-bottom: thin none #BBCEB3; padding: 10px; width: 548px; margin-top: -10px; right: 10px; left: 10px; border-left-width: thin; margin-left: 15px; background-color: #fffff0; border-left-color: #BBCEB3; border-right-color: #BBCEB3; border-top-style: groove; border-bottom-style: groove;">
<br />
<div style="width: 58px; height: 40px">
<asp:Image ID="Image2" runat="server" Height="59px" ImageAlign="Top" ImageUrl='<%#Eval("SProfilePic") %> ' Width="55px" />
</div>
<div style="width: 307px; margin-left: 65px; margin-top: -60px">
<asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Names="Arial" ForeColor="#000066"><%#Eval("SenderName") %> </asp:Label>
</div>
<div id="status" style=" width: 461px; margin-left: 78px; margin-top: 11px;"> <asp:Label ID="Label7" runat="server" Font-Italic="False" ForeColor="Black" Font-Size="Medium"><%#Eval("Messages") %> </asp:Label>
</div>
<div style="margin-left: 400px; background-color: #C0C0C0;">
<asp:Label ID="Label11" runat="server" Text="" Font-Size="Small"><%#Eval("Time") %> </asp:Label>
</div>
</div>
</ItemTemplate>
Put server controller there for example this:
<asp:Button ID="BtnOutside" runat="server" Text="Random" style="margin-left:-999px;" />
And then use
Page.SetFocus(Me.BtnOutside.ClientID);
To get focus to that button which is not visible to the client because of the negative margin. This should push the scroll bar to the bottom.
Put this in your code wherever you want to Focus on -- You can use this
multilple times in the same code set just change the "ID"
<asp:Button ID="FocusBottom" runat="server" Text="Random" style="margin-left:-999px;"
In the event(button click whatever) put in this.
Page.SetFocus(FocusBottom);
Change the (#######) to "ID" you want to call

File upload control with text box data for inserting in SQL server 2008 using C#

Presently, I am using file upload control for uploading files on SQL server through ASP.NET (using C#) successfully. Now I am trying to make as page like this
<body>
<form id="form1" runat="server">
<p style="font-family: Tahoma; font-weight: 700; font-size: medium; color: #0000CC">
Performance Feedback From Zonal Railways<p style="font-family: Tahoma; font-weight: 700; font-size: small; color: #990000">
Performance feedback of :
<asp:TextBox ID="equipment" runat="server" ></asp:TextBox>
<p style="font-family: Tahoma; font-weight: 700; font-size: small; color: #990000">
Uploaded by :
<asp:TextBox ID="uploadedby" runat="server" ></asp:TextBox>
<p class="style1">
<strong>Letter Date : <asp:TextBox ID="Letterdt" runat="server" ></asp:TextBox>
</strong></p>
<div>
<span class="style1"><strong>Select File to Upload :</strong></span>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload File" />
<br />
<asp:Label ID="lblMessage" runat="server" Text="" Font-Names = "Arial"></asp:Label>
</div>
</form>
<p>
<span class="style2"><strong>Back</strong></span>
<span class="style3"><strong>Home</strong></span></p>
</body>
Please suggest any readymade example for meet the requirment or any code.
Here's a link where you can learn how to upload files to SQL Server Database
http://www.aspsnippets.com/Articles/Upload-and-Download-files-from-SQL-Server-Database-in-ASPNet.aspx

how can i make fixed tree view in asp.net

I have treeview in asp website when click linked node it redirect the whole page the treeview not remain to the page. but what i want only to change the the main page the tree view must remain in all page like windows explorer. I'm using asp.net website please help me how can i do that?
This is my treevew.
Home
page1
page2
page3
page4
Create a Master page that have tree view within the table as following
<table border="0" cellspacing="0" cellpadding="0" id="content-container" style="width: 1016px; height: 407px;">
<tbody>
<tr>
<td id="content-left" style="width: 200px; height: 424px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid; border-bottom-color: buttonface; border-top-color: buttonface; border-right-color: buttonface; border-left-color: buttonface;">
<!--
LEFT COLUMN
-->
<br />
<asp:Panel ID="Panel1" runat="server" Height="455px" Width="220px">
<asp:TreeView ID="tvNodes" runat="server" Height="448px" Width="215px" ShowLines="True">
</asp:TreeView>
</asp:Panel>
</td>
<td id="content" style="width: 736px; height: 424px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-bottom-color: buttonface; border-top-color: buttonface; border-right-color: buttonface; ">
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server" >
</asp:contentplaceholder>
</td>
</tr>
</tbody>
</table>
And load the page to the ContentPlaceHolder1 on node click event.

Hidden field value in update panel not updating correctly

I'm working on employee web application project, in my application i used the 2 update panels,hidden fields and buttons. actually what I'm doing is while clicking button i need to get next employee info and save it this info. and here whenever I'll click on button which in update panel2, get employee info and I'll keep this employee id into hidden field which in update panel1 and while debugging hidden field value shows correct employee id but saving time its having old value. for this I'm facing lot problem please help me.
Thank you
Here is my code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="border-left: 1px solid #CDCDCD; border-right: 1px solid #CDCDCD; background-color: #E9E9E9">
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true"
AsyncPostBackTimeout="36000" />
<div>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="60000">
</asp:Timer>
</div>
<div align="left" style="width: 715px; background: #E9E9E9;">
<div style="margin: 0px 30px 0px 45px; line-height: 140%; border-bottom: 1px solid #E0E2E0;
padding: 10px 0px 15px 0px">
<asp:UpdatePanel ID="upNextChapter" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table width="100%">
<tr>
<td align="right">
<asp:HiddenField ID="hfEmpId" runat="server" Value="0" />
** Employee Info **
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="imgbtnNext" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
<div align="right" style="padding-right: 30px;">
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ImageButton ID="imgbtnNext" runat="server" OnClick="imgbtnNext_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
<div align="center">
</div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Code behind:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void imgbtnNext_Click(object sender, EventArgs e)
{
//Get Employee Info & store it in Hidden field value=Employee Id
//** Saving Employee Info using Hidden filed value **
}
}
I did a similar test on my machine, I really can't see why HiddenField is not updated. Its most likely your "Get Employee Info" is the root cause.
Also I want to correct your code a bit.
Your first UpdatePanel is doing unnecessary task, the tag UpdateMode="Conditional" is no need.
Also
<Triggers>
<asp:AsyncPostBackTrigger ControlID="imgbtnNext" EventName="Click" />
</Triggers>
this tag has no effect to anything because the button is not in the current UpdatePanel. By default everything in UpdatePanel is AsyncPostBackTrigger anyway, unless you have something to post back you can add asp:PostBackTrigger.

Categories