delayed rediraction asp.net - c#

so I have a login page and I'm trying to have it say "the user doesn't exist" and have it redirect you to the signup page immediately after showing this message, but my current code simply redirects you without displaying the message.
sorry if the message is unclear, its the first time i ever write anything in here:)
ulogin.html page:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="ulogin.aspx.cs" Inherits="User_ulogin" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style5 {
position: absolute;
top: 62px;
left: 53px;
z-index: 1;
}
.auto-style6 {
position: absolute;
top: 140px;
left: 56px;
z-index: 1;
}
.auto-style7 {
position: absolute;
top: 67px;
left: 279px;
z-index: 1;
width: 289px;
}
.auto-style8 {
position: absolute;
top: 141px;
left: 304px;
z-index: 1;
width: 295px;
}
.auto-style9 {
position: absolute;
top: 207px;
left: 219px;
z-index: 1;
}
.auto-style11 {
position: absolute;
top: 277px;
left: 10px;
z-index: 1;
width: 256px;
}
.auto-style12 {
position: absolute;
top: 16px;
left: 244px;
z-index: 1;
}
</style>
</head>
<body style="z-index: 1; width: 1490px; height: 16px; position: absolute; top: 0px; left: 0px">
<form id="form1" runat="server">
<div style="width: 1400px; margin: 0 auto;">
<asp:Label ID="Label2" runat="server" CssClass="auto-style5" Text="username:" Font-Size="18pt" Font-Bold="True"></asp:Label>
<asp:Label ID="Label3" runat="server" CssClass="auto-style6" Text="password:" Font-Size="18pt" Font-Bold="True"></asp:Label>
<asp:TextBox ID="txtuser" runat="server" CssClass="auto-style7" BorderColor="Black" OnTextChanged="txtuser_TextChanged"></asp:TextBox>
<asp:TextBox ID="txtpass" runat="server" CssClass="auto-style8" BorderColor="Black" OnTextChanged="txtpass_TextChanged"></asp:TextBox>
<asp:Button ID="Button1" runat="server" CssClass="auto-style9" OnClick="Button1_Click" Text="connect now" BackColor="Azure" Font-Size="16pt" BorderColor="Black" />
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="auto-style11" Font-Size="14pt" Font-Underline="True">lost your password? reset it now</asp:HyperLink>
**<asp:Label ID="lblsucc" runat="server" style="z-index: 1; left: 746px; top: 97px; position: absolute" Text="user dont exist" Visible="False"></asp:Label>**
<asp:Label ID="Label4" runat="server" CssClass="auto-style12" Font-Size="XX-Large" Text="Sign Now"></asp:Label>
</div>
</form>
</body>
</html>
ulogin.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class User_ulogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblsucc.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
users user = new users();
admin adn = new admin(txtuser.Text, txtpass.Text);
user.User_Name = txtuser.Text;
user.Pass = txtpass.Text;
if (user.login(user))
{
Session["user"] = txtuser.Text;
Response.Redirect("homepage.aspx");
}
else
{
lblsucc.Visible = true;
}
if(user.ifexist(user))
Response.Redirect("uregister.aspx");
}
protected void txtuser_TextChanged(object sender, EventArgs e)
{
}
protected void txtpass_TextChanged(object sender, EventArgs e)
{
}
protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
{
Response.Redirect("homepage.aspx");
}
}
'''
the relevant classes codes:
''' public bool login(users us)
{
DataSet dsUser = new DataSet();
string stuser = "SELECT tblUsers.User_Name, tblUsers.User_Password FROM tblUsers WHERE(((tblUsers.User_Password) = '" + us.user_Name + "')AND((tblUsers.User_Password) = '" + us.Pass + "')); ";
dsUser = sql.chkData(stuser);
if (dsUser.Tables[0].Rows.Count > 0)
{
return true;
}
else return false;
}'''
'''public bool ifexist(users user)
{
bool chk = false;
DataSet dsUser = new DataSet();
string stuser = "SELECT tblUsers.User_Name FROM tblUsers WHERE(((tblUsers.User_Name) ='" + user.User_Name + "'));";
dsUser = sql.chkData(stuser);
if (dsUser.Tables[0].Rows.Count > 0)
chk = true;
return chk;
}'''

Related

Gembox Document HTML to PDF doesn't show the text vertically

While converting from HTML to PDF, I noticed that Gembox Document doesn't recognize the "REPRINT" strings as a vertical.
The following is the HTML code:
<html>
<head>
<style>
.main-container {
text-align: center;
}
.code {
font-size: 25px;
font-weight: bold;
letter-spacing: 1px;
}
.mrg-btm {
margin-bottom: 8px;
}
.name-and-code {
font-size: 24px;
font-weight: bold;
letter-spacing: 3px;
}
.font-bold {
font-weight: bold;
}
.table-class {
width: 100%;
font-size: 14px;
}
td {
width: 50%;
}
.line-left {
text-align: left;
}
.line-right {
text-align: right;
}
.scadenza {
font-size: 24px;
font-weight: bold;
letter-spacing: 3px;
}
.data-scadenza {
font-size: 24px;
font-weight: bold;
letter-spacing: 2px;
}
.materiali {
font-size: 24px;
font-weight: bold;
text-align: left;
letter-spacing: 5px;
}
.last-codes {
font-size: 10px;
text-align: left;
}
.mrg-btm-two {
margin-bottom: 64px;
}
.mrg-btm-three {
margin-bottom: 16px;
}
.mrg-btm-four {
margin-bottom: 20px;
}
.mrg-side-left {
margin-left: 2px;
}
.main-table {
width: 100%;
}
.reprint-td {
width: 5%;
writing-mode: vertical-lr;
text-align: center;
letter-spacing: 4px;
font-size: 18px;
font-weight: bold;
}
.main-td {
width: 90%;
}
.reprint-div {
display: inline-block;
height: 100%;
}
</style>
</head>
<body>
<table class="main-table">
<tr>
<td class="reprint-td">
<div class="reprint-div">REPRINT</div>
</td>
<td class="main-td">
<div class="main-container">
<div class="code mrg-btm">
<label>__LABEL1__</label>
</div>
<div class="name-and-code mrg-btm-four">
<label>__LABEL2__ __LABEL3__</label>
</div>
<div class="mrg-btm-four">
<img alt='Barcode Generator TEC-IT' src='https://barcode.tec-it.com/barcode.ashx?data=BARCODE_NUMBER&code=Code39'/>
</div>
<div class="mrg-btm-three">
<table class="table-class">
<tr>
<td class="line-left">SQA_TEXT</td>
<td class="font-bold line-right">METER</td>
</tr>
<tr>
<td class="line-left">GOMSET</td>
<td class="line-right">FIRST_DATA</td>
</tr>
</table>
</div>
<div class="scadenza mrg-btm">
<label>EXPIRE_TEXT</label>
</div>
<div class="data-scadenza mrg-btm">
<label>EXPIRE_DATA</label>
</div>
<div class="materiali mrg-btm">
<label>MATERIALS_TEXT</label>
</div>
<div class="last-codes mrg-btm-two">
<label class="mrg-side-left">RC_NUMBER AFTER_RC</label>
</div>
<div class="last-codes mrg-btm">
<label class="mrg-side-left">SB_CODE STR_CODE SECOND_DATA</label>
</div>
<div class="last-codes">
<label class="mrg-side-left">C_CODE_NUMBER RC_NUMBER AFTER_RC</label>
</div>
</div>
</td>
<td class="reprint-td">
<div class="reprint-div">REPRINT</div>
</td>
</tr>
</table>
</body>
</html>
The following is the result of the HTML code (it is ok):
enter image description here
The following are the C# methods of our interest:
private void convertHtmlToPdf(string filenameHtml)
{
showMessage("Operation in progress...");
string realHtml = replaceIntoTemplate(File.ReadAllText(filenameHtml));
File.WriteAllText(path + htmlFilenameReplaced, realHtml);
GemBox.Document.ComponentInfo.SetLicense(licenseGemboxDocument);
DocumentModel document = DocumentModel.Load(path + htmlFilenameReplaced);
document.DefaultCharacterFormat.FontName = "Verdana";
GemBox.Document.Section section = document.Sections[0];
PageSetup pageSetup = section.PageSetup;
pageSetup.PageWidth = 383.62;
pageSetup.PageHeight = 576.95;
PageMargins pageMargins = pageSetup.PageMargins;
pageMargins.Top = pageMargins.Bottom = 96;
pageMargins.Left = pageMargins.Right = 48;
document.Save(path + pdfFilename);
showMessage("Successfully conversion HTML to PDF");
}
private string replaceIntoTemplate(string templateHtml)
{
string newTemplateHtml = templateHtml;
newTemplateHtml = newTemplateHtml.Replace("__LABEL1__", label1.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("__LABEL2__", label2.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("__LABEL3__", label3.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("BARCODE_NUMBER", barcode.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("SQA_TEXT", sqa.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("METER", meter.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("GOMSET", gomset.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("FIRST_DATA", firstData.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("EXPIRE_TEXT", expireText.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("EXPIRE_DATA", expireData.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("MATERIALS_TEXT", materials.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("RC_NUMBER", rcNumber.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("AFTER_RC", numberAfterRc.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("SB_CODE", sbCode.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("STR_CODE", strCode.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("SECOND_DATA", secondData.Replace(" ", " "));
newTemplateHtml = newTemplateHtml.Replace("C_CODE_NUMBER", cCode.Replace(" ", " "));
return newTemplateHtml;
}
The result of the conversion from HTML to PDF is the following (with the "REPRINT" strings not vertically):
enter image description here
What can I change in the convertHtmlToPdf C# method for obtained the "REPRINT" strings vertically?
Try using this latest bugfix version:
https://www.gemboxsoftware.com/document/nightlybuilds/GBD35v1134.zip
Or this latest NuGet package:
Install-Package GemBox.Document -Version 35.0.1134-hotfix
The writing-mode CSS property in table cells should now be supported.

HTML select element firing an onclick event in C#

In my Visual Studio project (ASP.NET Web Forms), I have a <select> in the HTML file:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="clientes.aspx.cs" Inherits="Leo.clientes" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="topnav">
Dashboard
<a class="active" href="/clientes">Clientes</a>
Despesas
</div>
<div style="padding-left:16px">
<label for="cars">Cliente:</label>
<select name="listaClientes" id="listaClientes" onserverchange="escolherCliente" runat="server">
</select>
</div>
</form>
</body>
</html>
In my cs file, I have a function called escolherCliente. This function is called by using the onserverchange event above.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
namespace Leo
{
public partial class clientes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string mycon = "server = localhost; Uid = Leo; password = password; persistsecurityinfo = True; database = db; SslMode = none";
MySqlConnection con = new MySqlConnection(mycon);
MySqlCommand cmd = null;
try
{
cmd = new MySqlCommand("select nome from cliente;", con);
con.Open();
MySqlDataReader leitor = cmd.ExecuteReader();
while(leitor.Read())
{
listaClientes.Items.Add(new ListItem(leitor.GetString(0)));
}
con.Close();
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "')</script>");
con.Close();
}
}
protected void escolherCliente(object sender, EventArgs e)
{
Response.Write("<script>alert('fdasfdsfsdfasfsafds')</script>");
}
}
}
The problem is that the function is not getting called. I change the selected <option> in the <select>, and nothing happens.
I already tried using onchange instead of onserverchange, and it also didn't work.
What should I do?

pdf objects won't display in IE but will in Chrome

I am at my wits end.
The following code displays a pdf to the user based on a query string and pulls the pdf from a file server. It works great in google chrome. However, I need this to work in IE as well.
When I use IE, it just shows a blank space where the pdf should be. Below is my aspx and C# file. Both browsers have adobe reader addons installed.
FRONT END:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="JobBookViewer.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Job Book Viewer</title>
<style type="text/css">
#form1 {
font-weight: 700;
width: 118px;
height: 217px;
margin-top: 15px;
}
</style>
<script type="text/javascript">
function SetPDFwindow()
{
var varclientscreenwidth = screen.width;
var varclientscreenheight = screen.height;
}
</script>
</head>
<body onload="SetPDFwindow()">
<form id="form1" runat="server">
<div style="width: 203px; z-index: 1; left: 7px; top: 4px; position: relative; height: 34px; right: 811px;">
<asp:Button ID="ButtonAbout" runat="server" BackColor="#B0F1FF" style="z-index: 1; left: 873px; top: 1px; position: absolute" Text="About" OnClick="ButtonAbout_Click" Visible="false" />
<asp:ListBox ID="ListBox1" runat="server" style="z-index: 1; left: 735px; top: 41px; position: absolute; width: 206px; height: 447px;" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" AutoPostBack =" true"></asp:ListBox>
</div>
<div id="chromecheck" runat="server" visible="false">
Chrome
</div>
<div id="iecheck" runat="server" visible="false">
We have detected that you are not using Chrome. If the program is not working, please switch to Chrome
</div>
<object data="data:application/pdf;base64
, <%= this.file %>" type="application/pdf"
style="z-index: 1; left: -3px; top: 1px; height: 210%; width: 612%; margin-top: 1px;" id="myPDF"></object>
<p>
</p>
</form>
</body>
</html>
CODE BEHIND:
using System;
using System.Web.UI.WebControls;
using System.IO;
using System.Drawing;
namespace JobBookViewer
{
public partial class WebForm1 : System.Web.UI.Page
{
public String file;
public String id;
protected void Page_Load(object sender, EventArgs e)
{
System.Web.HttpBrowserCapabilities browser;
browser = Request.Browser;
if (browser.Browser.ToLower().Equals("chrome"))
{
chromecheck.Visible = true;
}
else
{
iecheck.Visible = true;
}
if (!IsPostBack)
{
// myPDF.Style.Add("width", (Convert.ToInt32(clientScreenWidth.Value)-200).ToString());
file = fnFilePDFName(#"\\spfs1\stone\Long Term Share\db_objects\JobBookViewer\select_mold.pdf");
try
{
if (!String.IsNullOrEmpty(Page.Request.QueryString["MoldID"])) // if the string is not null
{
id = (Page.Request.QueryString["MoldID"]);
ListBox1.Items.Clear();
System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(#"\\spfs1\stone\mold_books\" + id.ToString());
System.IO.FileInfo[] Files = dinfo.GetFiles("*.pdf");
foreach (System.IO.FileInfo file in Files)
{
ListBox1.Items.Add(file.Name);
}
}
}
catch { }
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
file = fnFilePDFName(#"\\spfs1\stone\mold_books\" + Page.Request.QueryString["MoldID"] + #"\" + ListBox1.SelectedValue);
}
private string ModifyQueryStringValue(string p_Name, string p_NewValue)
{
var nameValues = System.Web.HttpUtility.ParseQueryString(Request.QueryString.ToString());
nameValues.Set(p_Name, p_NewValue);
string url = Request.Url.AbsolutePath;
string updatedQueryString = "?" + nameValues.ToString();
return url + updatedQueryString;
}
public string fnFilePDFName(string path)
{
string sfileContent;
Byte[] bytes = File.ReadAllBytes(path);
sfileContent = Convert.ToBase64String(bytes);
return sfileContent;
}
}
}

Dynamic grid on ASP.NET

I here to seek an advice ,what is the best approach.
here is the scenario.
I am building my project ASP.NET (C#)
I need to add an dynamic drop down box based on that two other text box related to drop down.
for example :
I have a button called "ADD LANDSCAPE", every time this triggered, i have to create an dynamic drop down "ddlLandscap" and two text boxes so the user can enter landscape value for each text box.
Can you guys please advise what's the best approach
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="CS1.aspx.cs" Inherits="workout.CS1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="../jquery/jquery-ui.css" rel="stylesheet" />
<script src="../jquery/jquery-1.12.0.js"></script>
<script src="../jquery/jquery-ui.js"></script>
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}
.table {
border: 1px solid #ccc;
border-collapse: collapse;
}
.table th {
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
.table th, .table td {
padding: 5px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvCustomers1" CssClass="table" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Slno" ItemStyle-Width="50px" ItemStyle-CssClass="Slno">
<ItemTemplate>
<%# Eval("Slno") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" ItemStyle-Width="150px" ItemStyle-CssClass="Name">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country" ItemStyle-Width="150px" ItemStyle-CssClass="Country">
<ItemTemplate>
<%# Eval("Country")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Option">
<ItemTemplate>
<asp:Button ID="lnkDelete" runat="server" Text="Delete" OnClientClick="Confirmationbox(this);" />
<asp:Button ID="btn_update" runat="server" Text="Update" OnClientClick="updateable(this);" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button ID="btnNewUser" runat="server" Text="Add" OnClientClick="return false;" />
<asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Submit" OnClientClick="formatData()" />
<br />
<div id="dialog-form" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 150px">Name:<br />
<asp:TextBox ID="txtName" runat="server" Width="140" Text="" />
</td>
<td style="width: 150px">Country:<br />
<asp:TextBox ID="txtCountry" runat="server" Width="140" Text="" />
</td>
</tr>
</table>
</div>
<div id="dialog-form-edit" title="Edit user">
<p class="validateTips">All form fields are required.</p>
<asp:HiddenField ID="hdslno" runat="server" Value="" />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 150px">Name:<br />
<asp:TextBox ID="TextBox1" runat="server" Width="140" Text="" />
</td>
<td style="width: 150px">Country:<br />
<asp:TextBox ID="TextBox2" runat="server" Width="140" Text="" />
</td>
</tr>
</table>
</div>
<br />
<script type="text/javascript">
var dialog,editDialog;
function formatData() {
var formatdata = "";
$( '#gvCustomers1 tr:gt(0)' ).each( function () {
$( this ).find( 'td' ).each( function () {
if ( $( this ).hasClass( "Slno" ) || $( this ).hasClass( "Name" ) || $( this ).hasClass( "Country" ) ) {
formatdata += $( this ).html() + "|";
}
} );
formatdata += ",";
} );
alert( formatdata );
return false;
}
$(function () {
dialog = $("#dialog-form").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Create an account": AddRow,
Cancel: function () {
dialog.dialog("close");
}
},
close: function () {
$("#txtName").val("");
},
open: function () {
var nr = $('#dialog-form').data('param');
if (nr) {
$("#txtName").val(nr);
} else {
$("#txtName").val("");
}
}
});
editDialog = $("#dialog-form-edit").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Create an account": UpdateRow,
Cancel: function () {
editDialog.dialog("close");
}
},
close: function () {
$("#txtName").val("");
},
open: function () {
var nr = $('#dialog-form-edit').data('param');
console.log(nr);
$( "#hdslno" ).val( nr.slno );
$("#TextBox1").val(nr.name);
$("#TextBox2").val(nr.country);
}
});
});
$("#btnNewUser").button().on("click", function () {
dialog.dialog("open");
});
function Confirmationbox(obj) {
if (confirm("Do you want to delete this Customer?")) {
var row = $(obj).closest("tr");
row.remove();
}
return true;
}
function updateable(obj) {
var row = $(obj).closest("tr");
var slno = $(row).find("td").eq(0).html();
var name = $(row).find("td").eq(1).html();
var country = $(row).find("td").eq(2).html();
try {
var json = {
slno: slno,
name: name,
country: country
};
editDialog.data('param', json).dialog("open");
event.preventDefault();
} catch (e) {
alert(e);
}
return false;
}
function UpdateRow() {
var slno = $( "#hdslno" ).val();
var m_Name = $( "#TextBox1" ).val();
var m_Country = $( "#TextBox2" ).val();
var row = null;
$( '#gvCustomers1 tr:gt(0)' ).each( function () {
$( this ).find( 'td' ).each( function () {
if ( $( this ).hasClass( "Slno" ) && $( this ).html() == slno ) {
row = $( this ).closest( "tr" );
}
} )
} );
if ( row ) {
$( row ).find( "td" ).eq( 1 ).html( m_Name );
$( row ).find( "td" ).eq( 2 ).html( m_Country );
}
editDialog.dialog( "close" );
return false;
}
function AddRow() {
//Reference the GridView.
var gridView = document.getElementById("<%=gvCustomers1.ClientID %>");
//Reference the TBODY tag.
var tbody = gridView.getElementsByTagName("tbody")[0];
//Reference the first row.
var row = tbody.getElementsByTagName("tr")[1];
//Check if row is dummy, if yes then remove.
if (row.getElementsByTagName("td")[0].innerHTML.replace(/\s/g, '') == "") {
tbody.removeChild(row);
}
//Clone the reference first row.
row = row.cloneNode(true);
var legnth = gridView.rows.length;
SetValue1(row, 0, "Slno", legnth);
//Add the Name value to first cell.
var txtName = document.getElementById("<%=txtName.ClientID %>");
SetValue(row, 1, "name", txtName);
//Add the Country value to second cell.
var txtCountry = document.getElementById("<%=txtCountry.ClientID %>");
SetValue(row, 2, "country", txtCountry);
//Add the row to the GridView.
tbody.appendChild(row);
dialog.dialog("close");
return false;
}
function SetValue(row, index, name, textbox) {
row.cells[index].innerHTML = textbox.value;
textbox.value = "";
}
function SetValue1(row, index, name,leng) {
row.cells[index].innerHTML = leng;
}
</script>
<asp:HiddenField ID="hdTableValues" runat="server" Value="" />
</form>
</body>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace workout
{
public partial class CS1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
DataTable dt = new DataTable();
string query = "SELECT '' Slno, Name, Country FROM dd_Detils";
string constr = "Data Source=localhost;Initial Catalog=DataBase;User ID=sa;Password=globalfocus";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.SelectCommand = cmd;
sda.Fill(dt);
}
}
}
if (dt.Rows.Count == 0)
{
//If no records then add a dummy row.
dt.Rows.Add();
}
gvCustomers1.DataSource = dt;
gvCustomers1.DataBind();
}
protected void Submit(object sender, EventArgs e)
{
int cnt = gvCustomers1.Rows.Count;
if (!string.IsNullOrEmpty(Request.Form["name"]) && !string.IsNullOrEmpty(Request.Form["country"]))
{
//Fetch the Hidden Field values from the Request.Form collection.
string[] names = Request.Form["name"].Split(',');
string[] countries = Request.Form["country"].Split(',');
//Loop through the values and insert into database table.
for (int i = 0; i < names.Length; i++)
{
string constr = "Data Source=localhost;Initial Catalog=Database;User ID=sa;Password=globalfocus";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO dd_Detils VALUES(#Name, #Country)"))
{
cmd.Parameters.AddWithValue("#Name", names[i]);
cmd.Parameters.AddWithValue("#Country", countries[i]);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
//Refresh the page to load GridView with records from database table.
Response.Redirect(Request.Url.AbsoluteUri);
}
}
}
}

PagedDataSource not paging

i have serched all over the web and didnt find anything like what i am doing or any solution to my problam.
i have an xsd file that connects to mdb and i want to show 10 resukts at a time and to have the ability to page throw all the results,for now the status is that i get 62 results per page and when i am trying to go to the next page i dont recive any results.
what is wrong in my code
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs"
Inherits="FaceBookSearchN.MainPage" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%--<%# Register Src="~/ResultsControl.ascx" TagPrefix="Results" TagName="ResultsControl" %>--%>
<!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">
<head runat="server">
<style type="text/css">
.accordionHeader
{
border: 1px solid blue;
color: White;
background-color: #5078B3;
font-family: Arial,Sans-Serif;
font-size: 12px;
font-weight: bold;
padding: 5px;
margin-top: 5px;
cursor: pointer;
}
.accordionHeader a, .accordionHeaderSelected a
{
color: #ffffff;
background: none;
text-decoration: none;
}
.accordionHeader a:hover, .accordionHeaderSelected a:hover
{
background: none;
text-decoration: underline;
}
.accordionHeaderSelected
{
border: 1px solid #2f4f4f;
color: White;
background-color: #5078B3;
font-family: Arial, Sans-Serif;
font-size: 12px;
font-weight: bold;
padding: 5px;
cursor: pointer;
}
.accordionContent
{
background-color: White;
border: 1px solid,#2f4f4f;
border-top: none;
padding: 5px;
padding-top: 10px;
}
</style>
<title></title>
</head>
<body dir="rtl">
<form id="form1" runat="server">
<div>
<table width="520px">
<tr>
<td>
<table width="100%">
<tr>
<td>
<asp:Label runat="server" Text="תחום" ID="lblProffesion"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:DropDownList runat="server" ID="ddlProffesion" DataTextField="profession_name"
DataValueField="profession_id" OnSelectedIndexChanged="ddlProffesion_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList>
</td>
</tr>
</table>
</td>
<td>
<table width="100%">
<tr>
<td>
<asp:Label runat="server" Text="אזור" ID="lblArea"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:DropDownList runat="server" ID="ddlArea" DataValueField="id_area" DataTextField="name_area"
AutoPostBack="true">
</asp:DropDownList>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%">
<tr>
<td>
<asp:Label runat="server" Text="תפקיד" ID="lblSubProffesion"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:DropDownList runat="server" ID="ddlSubProffesion" DataValueField="tat_pofession_id"
DataTextField="tat_pofession_name" AutoPostBack="true">
</asp:DropDownList>
</td>
</tr>
</table>
</td>
<td>
<table width="100%">
<tr>
<td>
<asp:Label runat="server" Text="אזור כתיבה חופשי" ID="lblFreetext"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtFreetext"></asp:TextBox>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button runat="server" Text="חיפוש" ID="btnSearch" OnClick="btnSearch_Click" />
</td>
</tr>
</table>
<div style="width: 520px">
<table width="520px" id="tblHeader" runat="server" style="background-color: #5078B3;
height: 25px">
<tr>
<td>
<asp:Label runat="server" ID="lblJobNum" Text="מס' משרה"></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblJobName" Text="שם משרה"></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblJobArea" Text="אזור עבודה"></asp:Label>
</td>
</tr>
</table>
<asp:Accordion ID="Accordion1" runat="server" AutoSize="None" FramesPerSecond="40" SelectedIndex="0" TransitionDuration="100"
FadeTransitions="true" RequireOpenedPane="true" SuppressHeaderPostbacks="true"
ContentCssClass="accordionContent" HeaderCssClass="accordionHeader" HeaderSelectedCssClass="accordionHeaderSelected">
</asp:Accordion>
<asp:Label ID="lblCurrentPage" runat="server"></asp:Label>
<asp:Button ID="btnPrev" runat="server" Text=" << " />
<asp:Button ID="btnNext" runat="server" Text=" >> " />
</div>
</div>
<asp:ToolkitScriptManager ID="Toolkitscriptmanager1" runat="server">
</asp:ToolkitScriptManager>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;
namespace FaceBookSearchN
{
public partial class MainPage : System.Web.UI.Page
{
private DataConnectionTableAdapters.table_professionTableAdapter adapterProf;
private DataConnectionTableAdapters.table_profession_tatTableAdapter adapterSubProf;
private DataConnectionTableAdapters.table_areaTableAdapter adapterArea;
private DataConnectionTableAdapters.ordersTableAdapter adapterOrdersNoParams;
private DataConnectionTableAdapters.ordersWithParamsTableAdapter adapterOrdersWithParams;
private DataConnection.table_professionDataTable profDT;
private DataConnection.table_profession_tatDataTable SubProfDT;
private DataConnection.table_areaDataTable areaDT;
private DataConnection.ordersDataTable ordersNoParamsDT;
private DataConnection.ordersWithParamsDataTable ordersWithParamsDT;
PagedDataSource pds;
public int CurrentPage
{
get
{
object o = this.ViewState["CurrentPage"];
if (o == null)
return 0;
else
return (int)o;
}
set
{
this.ViewState["CurrentPage"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
OnLoad();
}
}
protected void OnLoad()
{
tblHeader.Visible = false;
profDT = new DataConnection.table_professionDataTable();
adapterProf = new DataConnectionTableAdapters.table_professionTableAdapter();
areaDT = new DataConnection.table_areaDataTable();
adapterArea = new DataConnectionTableAdapters.table_areaTableAdapter();
adapterProf.Fill(profDT);
adapterArea.Fill(areaDT);
//adapter.Fill(SubProfDT);
ddlProffesion.DataSource = profDT;
ddlProffesion.DataBind();
ddlProffesion.Items.Insert(0,new ListItem("בחר מקצוע", "0"));
ddlArea.DataSource = areaDT;
ddlArea.DataBind();
ddlArea.Items.Insert(0, new ListItem("בחר אזור", "0"));
ddlSubProffesion.Items.Insert(0, new ListItem("בחר תת מקצוע", "0"));
}
protected void ddlProffesion_SelectedIndexChanged(object sender, EventArgs e)
{
SubProfDT = new DataConnection.table_profession_tatDataTable();
adapterSubProf = new DataConnectionTableAdapters.table_profession_tatTableAdapter();
adapterSubProf.GetDataByID(int.Parse(ddlProffesion.SelectedValue));
SubProfDT = adapterSubProf.GetDataByID(int.Parse(ddlProffesion.SelectedValue));
ddlSubProffesion.DataSource = SubProfDT;
ddlSubProffesion.DataBind();
//ddlSubProffesion.Items.Insert(0, new ListItem("בחר תת מקצוע", "0"));
}
protected void btnSearch_Click(object sender, EventArgs e)
{
tblHeader.Visible = true;
if (int.Parse(ddlProffesion.SelectedValue) == 0 && int.Parse(ddlArea.SelectedValue) == 0)
{
ordersNoParamsDT = new DataConnection.ordersDataTable();
adapterOrdersNoParams = new DataConnectionTableAdapters.ordersTableAdapter();
adapterOrdersNoParams.FillOrdersNoParams(ordersNoParamsDT);
DataTable dt = new DataTable();
dt = ordersNoParamsDT;
pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 10;
pds.CurrentPageIndex = CurrentPage;
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " " + "of" + " " + pds.PageCount.ToString();
btnPrev.Enabled = !pds.IsFirstPage;
btnNext.Enabled = !pds.IsLastPage;
ViewState["totalpages"] = pds.PageCount;
for (int i = 0; i < pds.PageCount; i++)
{
FileUpload fu = new FileUpload();
Button btnSubmit = new Button();
btnSubmit.Text = "שלח קורות חיים";
AjaxControlToolkit.AccordionPane pn;
pn = new AjaxControlToolkit.AccordionPane();
pn.ID = "pane" + i;
Label lblTitle = new Label();
Label lblJobName = new Label();
Label lblDesc = new Label();
lblTitle.Text = dt.Rows[i]["order_id"].ToString();
lblJobName.Text = dt.Rows[i]["description"].ToString();
//lblDesc.Text = dt.Rows[i]["description"].ToString();
//Accordion1.DataSource = pds;
//Accordion1.DataBind();
pn.HeaderContainer.Controls.Add(lblTitle);
pn.HeaderContainer.Controls.Add(lblJobName);
HtmlTable tableDesc = new HtmlTable();
HtmlTableRow row;
HtmlTableCell cell;
cell = new HtmlTableCell();
row = new HtmlTableRow();
cell.InnerHtml = dt.Rows[i]["notes"].ToString();
row.Cells.Add(cell);
tableDesc.Rows.Add(row);
fu.Width = Unit.Percentage(100.00);
pn.ContentContainer.Controls.Add(lblDesc);
pn.ContentContainer.Controls.Add(tableDesc);
pn.ContentContainer.Controls.Add(fu);
pn.ContentContainer.Controls.Add(btnSubmit);
Accordion1.Panes.Add(pn);
}
//int i = 0;
//foreach (DataRow dr in ordersNoParamsDT)
//{
// FileUpload fu = new FileUpload();
// AjaxControlToolkit.AccordionPane pn;
// pn = new AjaxControlToolkit.AccordionPane();
// pn.ID = "pane" + i;
// Label lblTitle = new Label();
// Label lblDesc = new Label();
// lblTitle.Text = dr["order_id"].ToString();
// //lblTitle.Text = "מס' משרה" +"|" + "שם משרה" +"|"+ "אזור עבודה"+ "|";
// pn.HeaderContainer.Controls.Add(lblTitle);
// lblDesc.Text = dr["description"].ToString();
// //pn.ContentContainer.Controls.Add(lblDesc);
// HtmlTable tableDesc = new HtmlTable();
// HtmlTableRow row;
// HtmlTableCell cell;
// HtmlTableCell cell2;
// cell = new HtmlTableCell();
// cell2 = new HtmlTableCell();
// row = new HtmlTableRow();
// cell.InnerHtml = dr["notes"].ToString();
// fu.Width = Unit.Percentage(100.00);
// cell2.Controls.Add(fu);
// row.Cells.Add(cell);
// tableDesc.Rows.Add(row);
// pn.ContentContainer.Controls.Add(tableDesc);
// Accordion1.Panes.Add(pn);
// i++;
//}
//Accordion1.DataSource = new System.Data.DataTableReader(ordersNoParamsDT);
//Accordion1.DataBind();
//ucResults.Proffesion = int.Parse(ddlProffesion.SelectedValue);
//ucResults.SubProffesion = 0;
//ucResults.Area = int.Parse(ddlArea.SelectedValue);
}
else
{
// ucResults.Proffesion = int.Parse(ddlProffesion.SelectedValue);
// ucResults.SubProffesion = int.Parse(ddlSubProffesion.SelectedValue);
// ucResults.Area = int.Parse(ddlArea.SelectedValue);
}
}
private void btnPrev_Click(object sender, System.EventArgs e)
{
// Set viewstate variable to the previous page
CurrentPage -= 1;
// Reload control
//ItemsGet();
}
private void btnNext_Click(object sender, System.EventArgs e)
{
// Set viewstate variable to the next page
CurrentPage += 1;
// Reload control
//ItemsGet();
}
}
}
Your OnLoad() method only triggers during the first page load. The data needs to be rebound every time the page is changed. Try removing the if(!IsPostBack) from the Page_Load method and see if it works.

Categories