I'm working with selenium chromedriver. So far I have been able to log on, check a check box, navigate to another web page. I've hit a brick wall though when I get to the upload file page.
The form has 4 or 5 buttons that will open up a dialog box to pick a file off of the local hard drive. There is no input to put in directly. I think that when you click one of the buttons it executes a javascript function that choose a file.
Please look at the source code of this page and see if you have any ideas how to accomplish this:
^^^`enter code here<head><link rel="shortcut icon" href="/favicon.ico"/><title>NYWB-ECF v10.5.2 NextGen Production Database</title>
<script type="text/javascript">document.cookie = "PRTYPE=aty; path=/;"</script> <script>var default_base_path = "/"; </script> <link rel="stylesheet" type="text/css" href="/css/default.css"><script type="text/javascript" src="/lib/core.js"></script><script type="text/javascript" src="/lib/autocomplete.js"></script><script type="text/javascript" src="/lib/DisableAJTALinks.js"></script><script type="text/javascript">if (top!=self) {top.location.replace(location.href);}</script><script>var default_base_path = "/"; </script></head><body BGCOLOR=ffffff TEXT=000000 onLoad='SetFocus()'>
<div class="noprint">
<div id="topmenu" class="yuimenubar"><div class="bd">
<img id="cmecfLogo" class="cmecfLogo" src="/graphics/logo-cmecf-sm.png" alt="CM/ECF" title="" />
<ul class="first-of-type">
<li class="yuimenubaritem" ><a class="yuimenubaritemlabel" href='/cgi-bin/DisplayMenu.pl?BankruptcyEvents&id=492888'>Ban</u>kruptcy <div class='spritedownarrow'></div></a></li>
<li class="yuimenubaritem" ><a class="yuimenubaritemlabel" href='/cgi-bin/DisplayMenu.pl?AdversaryEvents&id=492888'>A</u>dversary <div class='spritedownarrow'></div></a></li>
<li class="yuimenubaritem" ><a class="yuimenubaritemlabel" href='/cgi-bin/iquery.pl'>Q</u>uery</a></li>
<li class="yuimenubaritem" ><a class="yuimenubaritemlabel" href='/cgi-bin/DisplayMenu.pl?Reports&id=492888'>R</u>eports <div class='spritedownarrow'></div></a></li>
<li class="yuimenubaritem" ><a class="yuimenubaritemlabel" href='/cgi-bin/DisplayMenu.pl?Utilities&id=492888'>U</u>tilities <div class='spritedownarrow'></div></a></li>
<li class="yuimenubaritem" ><a class="yuimenubaritemlabel" href='javascript: CMECF.MainMenu.searchPrompt();'>Searc</u>h</a></li>
<li class="yuimenubaritem" ><a class="yuimenubaritemlabel" onClick="CMECF.MainMenu.showHelpPage(''); return false">Help</a></li>
<li class="yuimenubaritem"><a class="yuimenubaritemlabel" href='/cgi-bin/login.pl?logout'>Log Out</a></li><li class='yuimenubaritem' id='placeholderForAlertsIcon'></li>
</ul></div>
<hr class="hrmenuseparator"></div></div>
<script type="text/javascript">
callCreateMenu=function(){
var fn = "CMECF.MainMenu.renderSimpleMenu";
if(typeof CMECF.MainMenu.renderSimpleMenu == 'function') {
CMECF.MainMenu.renderSimpleMenu();
}
}
if (navigator.appVersion.indexOf("MSIE")==-1){window.setTimeout( function(){ callCreateMenu(); }, 1);}else{CMECF.util.Event.addListener(window, "load", callCreateMenu());}</script> <div id="cmecfMainContent"><input type="hidden" id="cmecfMainContentScroll" value="0"><SCRIPT LANGUAGE="JavaScript">
var IsForm = false;
var FirstField;
function SetFocus() {
if(IsForm) {
if(FirstField) {
var ind = FirstField.indexOf('document.',0);
if(ind == 0)
{
eval(FirstField);
}
else
{
var Code = "document.forms[0]."+FirstField+".focus();";
eval(Code);
}
} else {
var Cnt = 0;
while(document.forms[0].elements[Cnt] != null) {
try {
if(document.forms[0].elements[Cnt].type != "hidden" &&
!document.forms[0].elements[Cnt].disabled &&
!document.forms[0].elements[Cnt].readOnly) {
document.forms[0].elements[Cnt].focus();
break;
}
}
catch(e) {}
Cnt += 1;
}
}
}
return(true);
}
</SCRIPT>
<div id="main-page-title" style="margin-bottom: .5em">
<font face="arial,helvetica" color="0000cc" size="4"><b><span id="main-page-title-content">Open New Bankruptcy Case</span></b></font>
</div> <FORM ENCTYPE='multipart/form-data' method=POST action="/cgi-bin/Dispatch.pl?127734820136425">
<!-ShowPage(CaseUpLoad.htm)->
<!-- RPM Packages: ao-bkecf-web-* -->
<!-- RPM Permissions: 444 -->
<!-- RPM Owner: nobody -->
<!-- RPM Group: nobody -->
<!-- RPM Flags: configure -->
<script src="/lib/CommonLib.js" language="Javascript"></script>
<SCRIPT LANGUAGE="JavaScript">
function CheckCreditorMatrix(input,lower,upper,field) {
var strng = "" + input;
var len = strng.length;
if (len < lower || len > upper) {
var msg = "The List of Creditors is empty or does not exist";
alert(msg);
if (field) {
field.focus();
field.select();
}
return 0;
} else if (len == 0) { return 2; }
else return 1;
}
</script>
<table cellpadding="5"><tr>
<td><b>Case information</b><br/>
<input name="case_1" type="file" size="40" />
<font size = "-1">c:\Debtor.txt</font>
</td>
</tr><tr>
<td><b>Petition</b><br/>
<input name="file_1" type="file" size="40" />
<font size = "-1">c:\Petition.pdf</font>
</td>
</tr><tr>
<td><b>List of creditors</b><br/>
<input name = "creditorMatrixFilename" type="hidden" />
<input name="file_1_MTX" type="file" size="40" onChange="document.forms[0].creditorMatrixFilename.value = this.value"/>
<font size = "-1">c:\Creditor.txt</font>
</td>
<script>
var numEvents = 1;
// record the names so we know if the user tried to upload a file, even if it is invalid
function AssignHiddenValues() {
document.forms[0].creditorMatrixFilename.value = document.forms[0].file_1_MTX.value;
for (var i = 0; i <= numEvents; i++) {
if(document.forms[0]["configured_file_"+i])
document.forms[0]["configured_filename_"+i].value = document.forms[0]["configured_file_"+i].value;
}
return 1;
}
</script>
</tr><tr>
<td><b>Chapter 13 plan (<em>chapter 13 only</em>)</b><br/>
<input name = "configured_filename_0" type="hidden" />
<input name="configured_file_0" type="file" size="40"
onChange="document.forms[0].configured_filename_0.value = this.value" />
<font size = "-1">c:\Plan.pdf</font>
</td>
</tr><tr>
<td><b>Certificate of credit counseling </b><br/>
<input name = "configured_filename_1" type="hidden" />
<input name="configured_file_1" type="file" size="40"
onChange="document.forms[0].configured_filename_1.value = this.value" />
<font size = "-1">c:\CCC.pdf</font>
</td>
</tr></table>
<script>numEvents = 2</script>
<SCRIPT LANGUAGE="JavaScript">
document.cookie = "DPFFuncs='CaseUpLoadCollectCaseInfo-'; path=/; |";
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var timerId;
var BeenHere = 0;
IsForm = true;
function empty(s) {
var whitespace = " \ \
\
";
if(s == null || s.length == 0) {
return(true);
}
// Is s only whitespace characters?
for (var i = 0; i < s.length; i++) {
var c = s.charAt(i);
if (whitespace.indexOf(c) == -1) return false;
}
return(true);
}
function ClearTimer() {
BeenHere = 0;
clearTimeout(timerId);
return(true);
}
var FormId = 0;
function ProcessForm() {
if(BeenHere == 1) {
return(false);
}
if( ! AssignHiddenValues() ) {return false}
if( ! CheckString(document.forms[0].case_1.value, 1, 1000, document.forms[0].case_1) ) {return false}
if( ! CheckString(document.forms[0].file_1.value, 1, 1000, document.forms[0].file_1) ) {return false}
if( ! CheckCreditorMatrix(document.forms[0].file_1_MTX.value, 1, 1000, document.forms[0].file_1_MTX) ) {return false}
BeenHere = 1;timerId=setTimeout("ClearTimer()",5000);document.forms[FormId].submit();return true }
function RunAfterClear() {
}
</SCRIPT>
<TABLE><TR> <TD><INPUT NAME="button1" Value='Next' TYPE= "button" ONCLICK="ProcessForm()" > <TD> <TD> <INPUT NAME="reset" TYPE="RESET" VALUE="Clear" onClick="setTimeout('RunAfterClear()',100)"></TD> </TR></TABLE></FORM></div></body></html>
}
You can click the choose file button , and use sendkeys to give your location of the file.
WebElement upload = driver.findElement(By.linkText("Upload a Document:( .tex, .txt, .doc, .docx, .odt, .pdf, .rtf )"));
upload.sendKeys("C:\path\File.txt");
Checkout this code.
Related
How to fix code have select all asp:CheckBoxList within current table only in .NET C# same as "JQuery - Select All CheckBoxes within current table only" question ?
Because I try coding with sample but can't select all asp:CheckBoxList within current table only.
Link to "JQuery - Select All CheckBoxes within current table only" question.
My snipplet to describe problem.
<!DOCTYPE html>
<html>
<head>
<script
type="text/javascript"
src="//code.jquery.com/jquery-1.6.4.js"></script>
<style>
form , p , td, th{
font-size: 24px;
}
input.largerCheckbox
{
width: 22px;
height: 22px;
}
</style>
</head>
<body>
<h1>Show checkboxes:</h1>
<p><label><input type="checkbox" class="largerCheckbox" id="checkAll"/> Check all</label></p>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"><br><br>
<table id="myTable">
<tr class="header">
<th>Checkbox</th>
<th>Number</th>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle1" value="1"></td>
<td>1</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle2" value="11"></td>
<td>11</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle3" value="111"></td>
<td>111</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle4" value="1111"></td>
<td>1111</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle5" value="11111"></td>
<td>11111</td>
</tr>
</table>
<script>
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
<script>
$("#checkAll").change(function () {
$("input:checkbox").prop('checked', $(this).prop("checked"));
});
</script>
</body>
</html>
My full source code.
https://github.com/doanga2007/CheckLoopQR3
Sample code at the bottom.
Default.aspx (HTML Code)
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CheckLoopQR3.Default" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-1.6.4.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<style>
#myInput {
font-size: 16px;
padding: 6px 20px 6px 10px;
border: 1px solid #ddd;
margin-bottom: 3px;
}
</style>
<script type="text/javascript">
$(window).load(function(){
$("#checkAll").change(function () {
$("input:checkbox").prop('checked', $(this).prop("checked"));
});
});
</script>
<script>
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("CheckBox1");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h2>QR Code Generator</h2>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Please Input Data</label>
<div class="input-group">
<asp:TextBox ID="txtQRCode" runat="server" CssClass="form-control"></asp:TextBox>
<div class="input-group-prepend">
<asp:Button ID="btnGenerate" runat="server" CssClass="btn btn-secondary" Text="Generate" OnClick="btnGenerate_Click" />
</div>
</div>
</div>
</div>
</div>
<asp:Button ID="btnSelect" runat="server" CssClass="btn btn-secondary" Text="Display Text" OnClick="btnSelect_Click" /><br /><br />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:CheckBox ID="checkAll" runat="server" Font-Size="Large"/><asp:Label id="checkTextAll" runat="server" Font-Size="Large"></asp:Label><br /><br />
<label>Input Number to Search </label>
<input type="text" id="myInput" onkeyup="myFunction()"><br /><br />
<asp:CheckBoxList ID="CheckBox1" runat="server" Border="1"
BorderColor="LightGray" Font-Size="Large"></asp:CheckBoxList>
</div>
</form>
</body>
</html>
Default.aspx.cs (C# Code)
using System;
using System.Drawing;
using System.IO;
using ZXing;
using ZXing.QrCode;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CheckLoopQR3
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.checkTextAll.Text = " Check All";
}
protected void btnSelect_Click(object sender, EventArgs e)
{
string code = txtQRCode.Text;
long num = Convert.ToInt64(code);
int i;
for (i = 1; i < 6; i++)
{
num *= i;
CheckBox1.Items.Add(new ListItem(" " + num));
}
}
protected void btnGenerate_Click(object sender, EventArgs e)
{
if (CheckBox1.SelectedItem == null)
{
Response.Redirect("Default.aspx");
}
string[] texture = { "Selected Text 1 -> ", "Selected Text 2 -> ", "Selected Text 3 -> ",
"Selected Text 4 -> ", "Selected Text 5 -> "};
string[] texture2 = { " is Checkbox 1.", " is Checkbox 2.", " is Checkbox 3.",
" is Checkbox 4.", " is Checkbox 5."};
foreach (ListItem listItem in CheckBox1.Items)
{
if (listItem.Selected)
{
int a = CheckBox1.Items.IndexOf(listItem);
a = a + 1;
string code = listItem.Text;
CheckBox1.Visible = false;
checkAll.Visible = false;
checkTextAll.Visible = false;
QrCodeEncodingOptions options = new QrCodeEncodingOptions();
options = new QrCodeEncodingOptions
{
DisableECI = true,
CharacterSet = "UTF-8",
Width = 150,
Height = 150,
Margin = 0,
};
var barcodeWriter = new BarcodeWriter();
barcodeWriter.Format = BarcodeFormat.QR_CODE;
barcodeWriter.Options = options;
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
imgBarCode.Height = 150;
imgBarCode.Width = 150;
Label lblvalues = new Label();
lblvalues.Text += texture[a - 1] + listItem.Text + texture2[a - 1];
lblvalues.Font.Size = FontUnit.Large;
using (Bitmap bitMap = barcodeWriter.Write(code))
{
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
}
PlaceHolder1.Controls.Add(imgBarCode);
PlaceHolder1.Controls.Add(new HtmlGenericControl("br"));
PlaceHolder1.Controls.Add(lblvalues);
PlaceHolder1.Controls.Add(new HtmlGenericControl("br"));
}
}
else
{
//do something else
}
}
}
}
}
Good news : I have answer to fix code have select all asp:CheckBoxList within current table only in .NET C# same as "JQuery - Select All CheckBoxes within current table only" question.
Key of answer to "jQuery :visible Selector".
jQuery :
$(window).load(function(){
$("#checkAll").change(function () {
$("input:checkbox:visible").prop('checked', $(this).prop("checked"));
});
});
My snipplet to another solve problem in HTML.
<!DOCTYPE html>
<html>
<head>
<script
type="text/javascript"
src="//code.jquery.com/jquery-1.6.4.js"></script>
<style>
form , p , td, th{
font-size: 24px;
}
input.largerCheckbox
{
width: 22px;
height: 22px;
}
</style>
</head>
<body>
<h1>Show checkboxes:</h1>
<p><label><input type="checkbox" class="largerCheckbox" id="checkAll"/> Check all</label></p>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"><br><br>
<table id="myTable">
<tr class="header">
<th>Checkbox</th>
<th>Number</th>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle1" value="1"></td>
<td>1</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle2" value="11"></td>
<td>11</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle3" value="111"></td>
<td>111</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle4" value="1111"></td>
<td>1111</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle5" value="11111"></td>
<td>11111</td>
</tr>
</table>
<script>
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
<script>
$("#checkAll").change(function () {
$("input:checkbox:visible").prop('checked', $(this).prop("checked"));
});
</script>
</body>
</html>
My full source code.
https://github.com/doanga2007/CheckLoopQR3
Default.aspx (HTML Code)
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CheckLoopQR3.Default" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-1.6.4.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<style>
#myInput {
font-size: 16px;
padding: 6px 20px 6px 10px;
border: 1px solid #ddd;
margin-bottom: 3px;
}
</style>
<script type="text/javascript">
$(window).load(function(){
$("#checkAll").change(function () {
$("input:checkbox:visible").prop('checked', $(this).prop("checked"));
});
});
</script>
<script>
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("CheckBox1");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h2>QR Code Generator</h2>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Please Input Data</label>
<div class="input-group">
<asp:TextBox ID="txtQRCode" runat="server" CssClass="form-control"></asp:TextBox>
<div class="input-group-prepend">
<asp:Button ID="btnGenerate" runat="server" CssClass="btn btn-secondary" Text="Generate" OnClick="btnGenerate_Click" />
</div>
</div>
</div>
</div>
</div>
<label>Input Number to Search </label>
<input type="text" id="myInput" onkeyup="myFunction()"><br />
<asp:Button ID="btnSelect" runat="server" CssClass="btn btn-secondary" Text="Display Text" OnClick="btnSelect_Click" /><br /><br />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:CheckBox ID="checkAll" runat="server" Font-Size="Large"/><asp:Label id="checkTextAll" runat="server" Font-Size="Large"></asp:Label><br /><br />
<asp:CheckBoxList ID="CheckBox1" runat="server" Border="1"
BorderColor="LightGray" Font-Size="Large"></asp:CheckBoxList>
</div>
</form>
</body>
</html>
Default.aspx.cs (C# Code)
using System;
using System.Drawing;
using System.IO;
using ZXing;
using ZXing.QrCode;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CheckLoopQR3
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.checkTextAll.Text = " Check All";
}
protected void btnSelect_Click(object sender, EventArgs e)
{
string code = txtQRCode.Text;
long num = Convert.ToInt64(code);
int i;
for (i = 1; i < 6; i++)
{
num *= i;
CheckBox1.Items.Add(new ListItem(" " + num));
}
}
protected void btnGenerate_Click(object sender, EventArgs e)
{
if (CheckBox1.SelectedItem == null)
{
Response.Redirect("Default.aspx");
}
string[] texture = { "Selected Text 1 -> ", "Selected Text 2 -> ", "Selected Text 3 -> ",
"Selected Text 4 -> ", "Selected Text 5 -> "};
string[] texture2 = { " is Checkbox 1.", " is Checkbox 2.", " is Checkbox 3.",
" is Checkbox 4.", " is Checkbox 5."};
foreach (ListItem listItem in CheckBox1.Items)
{
if (listItem.Selected)
{
int a = CheckBox1.Items.IndexOf(listItem);
a = a + 1;
string code = listItem.Text;
CheckBox1.Visible = false;
checkAll.Visible = false;
checkTextAll.Visible = false;
QrCodeEncodingOptions options = new QrCodeEncodingOptions();
options = new QrCodeEncodingOptions
{
DisableECI = true,
CharacterSet = "UTF-8",
Width = 150,
Height = 150,
Margin = 0,
};
var barcodeWriter = new BarcodeWriter();
barcodeWriter.Format = BarcodeFormat.QR_CODE;
barcodeWriter.Options = options;
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
imgBarCode.Height = 150;
imgBarCode.Width = 150;
Label lblvalues = new Label();
lblvalues.Text += texture[a - 1] + listItem.Text + texture2[a - 1];
lblvalues.Font.Size = FontUnit.Large;
using (Bitmap bitMap = barcodeWriter.Write(code))
{
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
}
PlaceHolder1.Controls.Add(imgBarCode);
PlaceHolder1.Controls.Add(new HtmlGenericControl("br"));
PlaceHolder1.Controls.Add(lblvalues);
PlaceHolder1.Controls.Add(new HtmlGenericControl("br"));
}
}
else
{
//do something else
}
}
}
}
}
I'm working with sitecore 8 Update 2.
I'm extending the TreelistEx field.
The user is presented with a modal dialog ( created by Sheerresponse using QuickContact.html ).
Here the user can fill in 4 fields. When the user clicks "OK" the value of these fields are saved into an object. I would like to return this object/values. I have however found no way to achieve this.
( The ClientPipelineArgs never returns with any result )
namespace be.absi.kbs.extensions
{
class AbsiTreeListEx : TreelistEx, IMessageHandler
{
void IMessageHandler.HandleMessage(Message message)
{
if (message == null)
{ return; }
if (message["id"] == null)
{ return; }
if (!message["id"].Equals(ID))
{ return; }
var fieldInfo = _fieldInformation[message["id"]];
switch (message.Name)
{
case "treelist:edit":
var nvcEdit = new NameValueCollection { { "source", fieldInfo.Source } };
Sitecore.Context.ClientPage.Start(this, "Edit", nvcEdit);
break;
case "absitreelistex:absiquickadd":
var nvcQuickAdd = new NameValueCollection { { "clientFieldId", message["id"] } };
Sitecore.Context.ClientPage.Start(this, "QuickAddItem", nvcQuickAdd);
break;
}
}
protected void QuickAddItem(ClientPipelineArgs args)
{
if (args.IsPostBack)
{
// GET information from the QuickContact.html
}
else
{
var options = new ModalDialogOptions("/QuickContact.html")
{
Closable = true,
Response = true
};
SheerResponse.ShowModalDialog(options);
args.WaitForPostBack();
}
}
}
}
QuickContact.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base target="_self">
<title></title>
<script type="text/javascript">
function sendResponse()
{
var o = new Object();
o.forename = document.getElementById("FirstNameId").value;
o.surname = document.getElementById("LastNameId").value;
o.phone = document.getElementById("PhoneId").value;
o.mail = document.getElementById("MailId").value;
window.returnValue = o;
return o;
}
function OK()
{
var returnVal = sendResponse();
var jQueryResult = window.parent.$('.ui-dialog-content:visible');
self.returnValue = returnVal;
document.returnValue = returnVal;
window.returnValue = returnVal;
jQueryResult.dialog('close');
}
</script>
</head>
<body>
<label style="min-width: 80px;">First Name: </label><input type="text" id="FirstNameId" /><br />
<label style="min-width: 80px;">Last Name: </label><input type="text" id="LastNameId" /><br />
<label style="min-width: 80px;">Phone: </label><input type="text" id="PhoneId" /><br />
<label style="min-width: 80px;">Mail: </label><input type="text" id="MailId" /><br />
<br />
<input type="button" value="OK" onclick="OK()" />
</body>
</html>
Try setting result value with window.top.returnValue = returnVal; in JavaScript and reading it with args.Result iny our C# code. This worked for me.
I didn't realy find a legit solution for this issue.
I did solve it by writing my result to a coockie and reading it server-side ( deleting it afterwards )
I have this aspx code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="SearchCustomer.aspx.cs" Inherits="WebApplication1.eyeofheaven.SearchCustomer" %>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="viewport" content="width = device-width, initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no" />
<!-- Stylesheets -->
<link rel="stylesheet" type="text/css" href="StyleSheets/SearchCustomerStyle.css">
<link rel="stylesheet" href="Plugins/bootstrap-3.3.4-dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Pagination Script -->
<!--Customer Script-->
<script src="JavaScripts/SearchCustomerJavascript.js"></script>
<title>Search Customer</title>
</head>
<body>
<div class="container">
<div class="row">
<form id="Form1" class="form1" runat="server">
<div class="row">
<div class="twelve columns">
<!-- Header-->
<div class="container">
<nav role="navigation" class="navbar navbar-inverse navbar-fixed-top">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collection of nav links, forms, and other content for toggling -->
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle active" href="#">Search<b class="caret"></b></a>
<ul role="menu" class="dropdown-menu">
<li>Search Form(Customer)</li>
<li>Search Form(Vehicle)</li>
</ul>
</li>
</ul>
</div>
</nav>
</div>
</div>
</div>
<!-- Search form customer-->
<div id="searchcustomer" class="page-header">
<h3><span class="glyphicon glyphicon-th-large"></span>Search Customer</h3>
</div>
<div class="row">
<div class="col-md-4">
<input type="text" runat="server" id="search" size="20" class="form-control" placeholder="Customer ID">
</div>
<div class="col-md-4">
<select class="form-control" runat="server" id="Country">
<option value="select" selected disabled>Search by Country</option>
<option value="A:C ESTUDIO">A:C ESTUDIO</option>
<option value="Aaron McEwen-194712">Aaron McEwen-194712</option>
<option value="Accra">Accra</option>
<option value="Adoany">Adoany</option>
<option value="Aduanas">Aduanas</option>
<option value="Alex Sanchez-259029">Alex Sanchez-259029</option>
<option value="ALG Consulting-288078">ALG Consulting-288078</option>
<option value="Algeria">Algeria</option>
<option value="Algimantas Ramaskevicius">Algimantas Ramaskevicius</option>
<option value="Allan Demeritte-233953">Allan Demeritte-233953</option>
<option value="Althea Gibson-223990">Althea Gibson-223990</option>
<option value="Alvaro Delgado-279974">Alvaro Delgado-279974</option>
<option value="Amber Williamsen-212332">Amber Williamsen-212332</option>
<option value="Amos Peters-217784">Amos Peters-217784</option>
<option value="andersongordon-234453">andersongordon-234453</option>
<option value="Andrey Bolshakov-189544">Andrey Bolshakov-189544</option>
<option value="Angela green-220269">Angela green-220269</option>
<option value="ANGELMILLER-179184">ANGELMILLER-179184</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Anthony Knight-235064">Anthony Knight-235064</option>
<option value="Antigua and Barbuda">Antigua and Barbuda</option>
</select>
</div>
<div class="col-md-4">
<select class="form-control" runat="server" id="Currency">
<option value="selected" selected disabled>Search by Currency</option>
<option value="AUD">AUD (Australian Dollar)</option>
<option value="EUR">EUR (Euro)</option>
<option value="GBP">GBP (United Kingdom Pounds)</option>
<option value="JPY">JPY (Japan Yen)</option>
<option value="NZD">NZD (New Zealand Dollar)</option>
<option value="USD">USD (United States Dollar)</option>
</select>
</div>
</div>
<div class="row">
<div class="col-md-4">
<button type="button" runat="server" onserverclick="Button1_Click" id="searchinfo" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>Search Info</button>
<button type="button" runat="server" onserverclick="Button2_Click" id="Button2" class="btn btn-danger"><span class="glyphicon glyphicon-repeat"></span>Reset</button>
</div>
</div>
<hr style="border-top: dotted 1px;" />
<!-- Information Table-->
<div class="row">
<asp:Repeater runat="server" ID="repeater">
<ItemTemplate>
<div class="col-md-8">
<div id="panelmain" class="panel panel-default">
<div id="panel-heading" class="panel-heading">
<h3 id="name" align="center" class="panel-title"><%# String.Format("{0} {1}", DataBinder.Eval(Container.DataItem, "Firstname").ToString(), DataBinder.Eval(Container.DataItem, "Lastname").ToString()) %></h3>
</div>
<div id="panelbody" class="panel-body">
<ul class="list-unstyled">
<li>
<span class="spanlist">IDCustomer : </span><%# DataBinder.Eval(Container.DataItem, "IDCustomer").ToString() %>
</li>
<li>
<span class="spanlist">IDAccountManager : </span><%# DataBinder.Eval(Container.DataItem, "IDAccountManager").ToString() %>
</li>
<li>
<span class="spanlist">IDBillingAddress : </span><%# DataBinder.Eval(Container.DataItem, "IDBillingAddress").ToString() %>
</li>
<li>
<span class="spanlist">IDCountry : </span><%# DataBinder.Eval(Container.DataItem, "IDCountry").ToString() %>
</li>
<li>
<span class="spanlist">IDCredit : </span><%# DataBinder.Eval(Container.DataItem, "IDCredit").ToString() %>
</li>
<li>
<span class="spanlist">IDFrequency : </span><%# DataBinder.Eval(Container.DataItem, "IDFrequency").ToString() %>
</li>
<li>
<span class="spanlist">IDOwner : </span><%# DataBinder.Eval(Container.DataItem, "IDOwner").ToString() %>
</li>
<li>
<span class="spanlist">IDPort : </span><%# DataBinder.Eval(Container.DataItem, "IDPort").ToString() %>
</li>
<li>
<span class="spanlist">IDSite : </span><%# DataBinder.Eval(Container.DataItem, "IDSite").ToString() %>
</li>
<li>
<span class="spanlist">IDRecipient : </span><%# DataBinder.Eval(Container.DataItem, "IDRecipient").ToString() %>
</li>
<li>
<span class="spanlist">AccessType : </span><%# DataBinder.Eval(Container.DataItem, "AccessType").ToString() %>
</li>
<li>
<span class="spanlist">Active : </span><%# DataBinder.Eval(Container.DataItem, "Active").ToString() %>
</li>
</ul>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
<div>
<asp:LinkButton ID="linkPrevious" runat="server" NavigateUrl="~/SearchCustomer.aspx" Font-Bold="true" OnClick="linkPrevious_Click">Prev Page</asp:LinkButton>
<asp:LinkButton ID="linkNext" runat="server" NavigateUrl="~/SearchCustomer.aspx" Font-Bold="true" OnClick="linkNext_Click">Next Page</asp:LinkButton>
</div>
</form>
</body>
</html>
and its aspx code behind:
using MSSQLConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services.Description;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1.eyeofheaven
{
public partial class SearchCustomer : System.Web.UI.Page
{
public static string query = null;
private int cnt;
private DataSet selectedData;
private DataTable dt;
private MSConnector connector = new MSConnector();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//Function for BindRepeater
BindRepeater();
}
protected void Button2_Click(object sender, EventArgs e)
{
this.repeater.Visible = false;
this.search.Value = "";
this.Country.Value = "select";
this.Currency.Value = "selected";
}
//This property will contain the current page number
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
{
return Convert.ToInt32(ViewState["PageNumber"]);
}
else
{
return 0;
}
}
set { ViewState["PageNumber"] = value; }
}
//Asp:ListView
private void BindRepeater()
{
//ConnectionString for accessing into MSSql
connector.ConnectionString = "SERVER=xbetasql,52292;UID=username;Password=secret;DATABASE=ATDBSQL;";
//Get the values from id's
string customer = (this.search.Value);
string country = (this.Country.Value);
string idcurrency = (this.Currency.Value);
//Conditions for query
if (country != "select")
{
if (idcurrency != "selected")
{
query = "select * from customer where country = '" + country + "' and idcurrency = '" + idcurrency + "'";
}
else
{
query = "select * from customer where country = '" + country + "'";
}
}
else if (idcurrency != "selected")
{
query = "select * from customer where idcurrency = '" + idcurrency + "'";
}
else if ((this.search.Value) == customer)
{
query = "select * from customer where idcustomer = '" + customer + "'";
}
else if (customer == "")
{
Response.Write("<script>alert('No Id Inputted, Data Not Found.')</script>");
}
//DataSet and DataTable (get the data and display it into asp:repeater
selectedData = connector.ExecuteQuery(query);
dt = selectedData.Tables[0];
//Set PageData Settings
PagedDataSource pagedData = new PagedDataSource();
pagedData.DataSource = dt.DefaultView;
pagedData.AllowPaging = true;
pagedData.PageSize = 3;
pagedData.CurrentPageIndex = PageNumber;
int vcnt = cnt / pagedData.PageSize;
if (PageNumber < 1)
{
linkPrevious.Visible = false;
}
else if (PageNumber > 0)
{
linkPrevious.Visible = true;
}
if (PageNumber == vcnt)
{
linkNext.Visible = false;
}
else if(PageNumber < vcnt)
{
linkNext.Visible = true;
}
//Binding the repeater
repeater.Visible = true;
repeater.DataSource = pagedData;
repeater.DataBind();
//Binding the repeater
}
protected void linkNext_Click(object sender, EventArgs e)
{
PageNumber += 1;
BindRepeater();
}
protected void linkPrevious_Click(object sender, EventArgs e)
{
PageNumber -= 1;
BindRepeater();
}
}
}
My asp:LinkButton, does not work for paging in my repeater when I first open my web page the asp:linkbutton is there, but when searched and display all the data from my page the linkbutton is gone although it display data that I searched for. But the problem is pagination doesn't seem to work. What seems to be the problem for my code? Here's the link as a reference for my code.
I'm new to c# programming(webform) and I have few knowledge about pagination in c#.
It's because of
int vcnt = cnt / pagedData.PageSize;
'cnt' you haven't set, So its always zero that's why 'vcnt' will zero.
that's why your link will visible false always after you search things.
So Solution is
int vcnt = dt.DefaultView.Count / pagedData.PageSize;
Hope this will solve your problem
Happy Coding :)
I got it right :)
here's the code for pagination:
using MSSQLConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services.Description;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1.eyeofheaven
{
public partial class SearchCustomer : System.Web.UI.Page
{
public static string query = null;
private int cnt;
private DataSet selectedData;
private DataTable dt;
private MSConnector connector = new MSConnector();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//Function for BindRepeater
BindRepeater();
}
protected void Button2_Click(object sender, EventArgs e)
{
this.repeater.Visible = false;
this.linkPrevious.Visible = false;
this.linkNext.Visible = false;
this.search.Value = "";
this.Country.Value = "select";
this.Currency.Value = "selected";
}
//This property will contain the current page number
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
{
return Convert.ToInt32(ViewState["PageNumber"]);
}
else
{
return 0;
}
}
set { ViewState["PageNumber"] = value; }
}
//Asp:ListView
private void BindRepeater()
{
//ConnectionString for accessing into MSSql
connector.ConnectionString = "SERVER=xbetasql,52292;UID=username;Password=secret;DATABASE=ATDBSQL;";
//Get the values from id's
string customer = (this.search.Value);
string country = (this.Country.Value);
string idcurrency = (this.Currency.Value);
//Conditions for query
if (customer != "")
{
query = "select * from customer where idcustomer = '" + customer + "'";
}
else if (country != "select")
{
if (idcurrency != "selected")
{
query = "select * from customer where country = '" + country + "' and idcurrency = '" + idcurrency + "'";
}
else
{
query = "select * from customer where country = '" + country + "'";
}
}
else if (idcurrency != "selected")
{
query = "select * from customer where idcurrency = '" + idcurrency + "'";
}
else if (customer == "")
{
Response.Write("<script>alert('No Id Inputted, Data Not Found.')</script>");
}
else
{
Response.Write("<script>alert('Invalid input.')</script>");
}
//DataSet and DataTable (get the data and display it into asp:repeater
selectedData = connector.ExecuteQuery(query);
dt = selectedData.Tables[0];
//Set PageData Settings
PagedDataSource pagedData = new PagedDataSource();
pagedData.DataSource = dt.DefaultView;
pagedData.AllowPaging = true;
//Set to 2 pages to be viewed
pagedData.PageSize = 2;
pagedData.CurrentPageIndex = PageNumber;
//Count to 2 pages to appear when clicking next or previous
int vcnt = dt.DefaultView.Count / pagedData.PageSize;
if (PageNumber == 1)
{
linkPrevious.Visible = false;
}
else if (PageNumber < 1)
{
linkPrevious.Visible = false;
}
else if (PageNumber > 0)
{
linkPrevious.Visible = true;
}
if (PageNumber == vcnt)
{
linkNext.Visible = false;
}
//Hide previous and next if it is firstpage and lastpage
else if(PageNumber < vcnt)
{
linkNext.Visible = !pagedData.IsLastPage;
linkPrevious.Visible = !pagedData.IsFirstPage;
}
//Binding the repeater
if (dt.Rows.Count > 0)
{
repeater.Visible = true;
repeater.DataSource = pagedData;
repeater.DataBind();
}
else
{
Response.Write("<script>alert('No Data Found.')</script>");
}
}
protected void linkNext_Click(object sender, EventArgs e)
{
linkNext.Visible = true;
PageNumber += 1;
BindRepeater();
}
protected void linkPrevious_Click(object sender, EventArgs e)
{
linkPrevious.Visible = true;
PageNumber -= 1;
BindRepeater();
}
}
}
Hope this is a good reference among programmers. :)
I have a jquerymobile multipage document.
With this layout
#using ParadigmaNet.Infraestructure;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>#ViewBag.Title</title>
<meta name="viewport" content="width=device-width" />
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link rel="stylesheet" href="#Url.Content("~/css/ParadigmaNTouch.css")" />
#Styles.Render("~/Content/mobileCss", "~/Content/css")
#Scripts.Render("~/bundles/modernizr")
</head>
<body>
#RenderBody()
#Scripts.Render("~/bundles/jquery", "~/bundles/jquerymobile")
#Scripts.Render("~/Scripts/paradigmaN_Ajax.js")
<script type="text/javascript">
var Wres = $(window).width();
var Hres = $(window).height();
document.cookie = "ScreenRes=" + Wres + "x" + Hres;
</script>
if (IsSectionDefined("scripts"))
{
#RenderSection("scripts", false)
}
</body>
</html>
And a document with two pages
#model ParadigmaNet.Areas.Documentos.Models.Merlin_MovimientoDocumentosFacturacion_Enc
#using ParadigmaNet.Infraestructure
#using ParadigmaNet.Areas.Items.Models
#using ParadigmaNet.Areas.Documentos.Models
#using ParadigmaNet.Areas.Items.Controllers;
#{
Layout = "~/Views/Shared/_LayoutMobile.cshtml";
}
#*Pagina principal de pedidos*#
<div id="DocumentoPedidoPrincipal" data-role="page" data-theme="b">
<div data-role="header" data-position="fixed" >
#Html.ActionLink("Cancelar", "DocsCancelar", "Docs", new { area = "Documentos" }, new { StrIdDocumento = "", data_icon="delete" })
<h1 id="NombreItem">Ubicacion: #SessionBag.Current.IntIdUbicacion</h1>
#Html.ActionLink("Grabar", "DocsGuardar", "Docs", new { area = "Documentos", StrIdDocumento = SessionBag.Current.StrIdDocumento }, new { data_icon="check" })
<div style="padding:2px;">
#if (ViewBag.ParaEdicion)
{
#MyHelpers.menu("MenuItemEnPedido", new System.Collections.ArrayList { #Html.ActionLink("Detalle", "DocsDetalle", "Docs", new { area = "Documentos", StrIdDocumento = SessionBag.Current.StrIdDocumento }, new { #class = "no-Ajax ui-btn ui-btn-up-a" }) })
}
else
{
string detalle = "<a id=" + ParadigmaNTouchHelpers.quote("MostrarDetallePedido") + " href=" + ParadigmaNTouchHelpers.quote("#") + " onclick=" + ParadigmaNTouchHelpers.quote("mostrarDetallePedido(true);") + " data-role=" + ParadigmaNTouchHelpers.quote("button") + " data-theme=" + ParadigmaNTouchHelpers.quote("e") + ">";
string condiciones = "<a id=" + ParadigmaNTouchHelpers.quote("ItemCondiciones") + " href=" + ParadigmaNTouchHelpers.quote("#CondicionesDocumento") + " data-role=" + ParadigmaNTouchHelpers.quote("button") + " data-theme=" + ParadigmaNTouchHelpers.quote("e") + ">Condiciones</a>";
#MyHelpers.menu("MenuItemEnPedido",
new System.Collections.ArrayList
{
#Html.ActionLink("Adiciones", "DocsDetalle", "Docs", new { area = "Documentos", StrIdDocumento = SessionBag.Current.StrIdDocumento }, new { data_role="button", data_ajax = "false" ,data_theme="a" , id="ItemAdiciones" , #class="ui-disabled"})
,#Html.ActionLink("Componentes", "DocsDetalle", "Docs", new { area = "Documentos", StrIdDocumento = SessionBag.Current.StrIdDocumento }, new { data_role="button", data_ajax = "false" ,data_theme="c" , id="ItemComponentes" , #class="ui-disabled"})
,#MvcHtmlString.Create(condiciones) //#Html.ActionLink("Condiciones", "", "", new {}, new { data_role="button", data_ajax = "false" ,data_theme="e" , id="ItemCondiciones" , #class="ui-disabled" , onclick="mostrarCondiciones(true)"})
,#Html.ActionLink("Eliminar", "DocsDetalle", "Docs", new { area = "Documentos", StrIdDocumento = SessionBag.Current.StrIdDocumento }, new { data_role="button", data_ajax = "false" ,data_theme="d" , id="ItemEliminar" , disable="true",#class="ui-disabled"})
,#Html.ActionLink("Detalle", "", "", new {} , new { data_role="button", id = "MostrarDetallePedido", data_ajax = "false" ,data_theme="b", onclick="mostrarDetallePedido(true)"})
}
, 1, "c")
}
</div>
</div>
<div id="BodyContent" data-role="content" data-theme="a" style="height:auto; min-height:90%; width:100%;position:absolute;overflow:visible;">
<div id="LineasTouchContainer">
#ParadigmaNTouchHelpers.TouchContainer(ViewBag.LineasList, ViewBag.LineasTouchContainer);
</div>
<div id="ItemsTouchContainer">
#ParadigmaNTouchHelpers.TouchContainer(ViewBag.ItemsList, ViewBag.ItemsTouchContainer)
</div>
<div id="GruposTouchContainer">
</div>
<div id="QuickList">
#ParadigmaNTouchHelpers.TouchContainer(ViewBag.QList, ViewBag.QuickListAccess)
</div>
<div data-role="collapsible-set" data-mini="true" data-inset="true" data-filter="true" id="DetalleDocumento" class="ParadigmaNDetallePedidoHide">
<div data-role='button' onclick="mostrarDetallePedido(false)" data-theme="b">Ocultar Detalle</div>
<div data-role="collapsible-set" data-mini="true" data-inset="true" data-filter="true" id="DetallePedidoRegistros">
#if (1==1){
Merlin_MovimientoDocumentosFacturacion_Enc DatosDoc = (Merlin_MovimientoDocumentosFacturacion_Enc)SessionBag.Current.DocEditar;
<div data-role="collapsible" data-collapsed="false">
<h3>Datos del Pedido</h3>
Abierto por #DatosDoc.StrUsuarioGenera<br />
A las #DatosDoc.DatFechaDocumento<br />
Mesa: #DatosDoc.IntIdMesa
</div>
}
</div>
#foreach (Merlin_Movimientos_Pedidos Item in SessionBag.Current.DocEditar.Merlin_MovimientoDocumentos_Pedidos_Enc.Merlin_Movimientos_Pedidos)
{
Html.RenderPartial("DocsDetalleTransaccionPedido", Item);
}
</div>
</div>
</div>
#*Pagina de condiciones*#
<div id="CondicionesDocumento" data-role="page" data-theme="b">
<div data-role="header" data-position="fixed" >
Volver
<h1 id="TituloCondiciones">Editando condiciones</h1>
#if (1 == 1)
{
<a>Hola Mundo</a>
}
</div>
<div data-role="content" data-theme="a" style="height:auto; min-height:90%; width:100%;position:absolute;overflow:visible;">
<div class="ui-grid-a">
<div class="ui-block-a" style="width:50%; top:1em; position:relative;left:0em;" data-theme="a" >
<ul id ="CondicionesDocumentoDisponibles" data-role="listview" data-filter="true" data-inset="true">
</ul>
</div>
<div class="ui-block-b" style="width:48%;position:relative; left:1%;">
<ul id ="CondicionesDocumentoSeleccionadas" data-role="listview" data-filter="false" data-inset="true" style="left:51%;top:1em;postion:relative;" >
</ul>
</div>
</div>
</div>
</div>
#section scripts {
<script type="text/javascript">
$('#CondicionesDocumentoDisponibles').listview();
$('#CondicionesDocumentoSeleccionadas').listview();
$('#DetalleDocumento').listview();
</script>
}
The document is called by redirecttoaction() into a controller method, until here everything is ok.
The problem is that the second page id="CondicionesDocumento" don't render into _Layout
I don't see any place that the page "CondicionesDocumento" gets loaded or linked to... Am I missing something? You need to explicitly link to the page:
Second Page
Or load the page via JavaScript:
$.mobile.changePage("CondicionesDocumento);
The problem is that jQUery mobile render all pages only for the firs call, other calls only render the first page on the document.
After the first call only one page must be included per document.
I wrote a google map lookup page. Everthing worked fine until I referenced the page to use a master page. I removed the form tag from the master page as the search button on the map page is a submit button. Everything else on my page appears but the google map div appears with map navigation controls and logo but no map visuals appear.
I retested with the previous, non master page version and the map appears correctly. Any thoughts on what I'm missing?
Please view below Code and let me know its useful ...
MasterPage Code ( GMap.master page)
< body onload="initialize()" onunload="GUnload()" >
< form id="form1" runat="server" >
< div >
< asp:contentplaceholder id="ContentPlaceHolder1" runat="server" >
< /asp:contentplaceholder >
< /div >
< /form >
< /body >
GMatTest.aspx Page which is used GMap.Master page
< %# Page Language="C#" MasterPageFile="~/MasterPages/GMap.master" AutoEventWireup="true"
CodeFile="GMapTest.aspx.cs" Inherits="GMapTest" Title="Google Map Page" % >
< asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server" >
< script src="http://maps.google.com/maps?file=api&v=2&key=< % = AppConfig.GoogleMapApiKey % >"
type="text/javascript" >< /script >
< script type="text/javascript" >
var map = null;
var geocoder = null;
var latsgn = 1;
var lgsgn = 1;
var zm = 0;
var marker = null;
function initialize()
{
if (GBrowserIsCompatible())
{
var latitude= "";
var longitude= "";
map = new GMap2(document.getElementById("map_canvas"));
var center = new GLatLng(0,0);
map.setCenter(center, 17);
map.addControl(new GLargeMapControl());
map.addControl(new GScaleControl());
map.enableScrollWheelZoom();
map.addControl(new GMapTypeControl());
map.enableDoubleClickZoom();
marker = new GMarker(center,{draggable: true});
geocoder = new GClientGeocoder();
GEvent.addListener(marker, "dragend", function() {
var point = marker.getLatLng();
marker.openInfoWindowHtml("Latitude: " + point.y + "< /br > Longitude: " + point.x );
});
GEvent.addListener(marker, "click", function() {
var point = marker.getLatLng();
});
map.addOverlay(marker);
GEvent.trigger(marker, "click");
if (latitude > 0 && longitude > 0)
{
}
else
{
showAddress();
}
}
}
Below porsion is continue so please copy it also
function showAddress()
{
var isAddressFound=false;
var companyAddress = '';
var address='satyam mall, vastrapur, ahmedabad, gujrat, india';
if (geocoder)
{
geocoder.getLatLng(address,function(point) {
if (!point) {
alert(address + " not found");
} else {
isAddressFound =true;
map.setCenter(point,17);
zm = 1;
marker.setPoint(point);
GEvent.trigger(marker, "click");
}
}
);
//If address not found then redirect to company address
if(!isAddressFound)
{
geocoder.getLatLng(companyAddress,
function(point) {
if (!point) {
} else {
isAddressFound =true;
map.setCenter(point,17);
zm = 1;
marker.setPoint(point);
GEvent.trigger(marker, "click");
}
}
);
}
}
}
< /script >
< div id="map_canvas" style="width: 100%; height: 425px" >
< /div >
< /asp:Content >
this is the code i used.it works fine here but whenever i add master page it does not perform any use functionality
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Find latitude and longitude with Google Maps</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAPkZq56tNYNmeuZjNQQ2p3hT0NZP-HbfQNNfWb9Z5SLbjZKYKwBTrGBqtttFmF2d-kWv2B2nqW_NyEQ"
type="text/javascript"></script>
<script type="text/javascript">
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var center = new GLatLng(48.89364, 2.33739);
map.setCenter(center, 15);
geocoder = new GClientGeocoder();
var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);
document.getElementById("lat").innerHTML = center.lat().toFixed(6);
document.getElementById("lng").innerHTML = center.lng().toFixed(6);
GEvent.addListener(marker, "dragend", function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById("lat").innerHTML = point.lat().toFixed(6);
document.getElementById("lng").innerHTML = point.lng().toFixed(6);
});
GEvent.addListener(map, "moveend", function() {
map.clearOverlays();
var center = map.getCenter();
var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);
document.getElementById("lat").innerHTML = center.lat().toFixed(6);
document.getElementById("lng").innerHTML = center.lng().toFixed(6);
GEvent.addListener(marker, "dragend", function() {
var point =marker.getPoint();
map.panTo(point);
document.getElementById("lat").innerHTML = point.lat().toFixed(6);
document.getElementById("lng").innerHTML = point.lng().toFixed(6);
});
});
}
}
function showAddress(address) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
document.getElementById("lat").innerHTML = point.lat().toFixed(6);
document.getElementById("lng").innerHTML = point.lng().toFixed(6);
map.clearOverlays()
map.setCenter(point, 14);
var marker = new GMarker(point, {draggable: true});
map.addOverlay(marker);
GEvent.addListener(marker, "dragend", function() {
var pt = marker.getPoint();
map.panTo(pt);
document.getElementById("lat").innerHTML = pt.lat().toFixed(6);
document.getElementById("lng").innerHTML = pt.lng().toFixed(6);
});
GEvent.addListener(map, "moveend", function() {
map.clearOverlays();
var center = map.getCenter();
var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);
document.getElementById("lat").innerHTML = center.lat().toFixed(6);
document.getElementById("lng").innerHTML = center.lng().toFixed(6);
GEvent.addListener(marker, "dragend", function() {
var pt = marker.getPoint();
map.panTo(pt);
document.getElementById("lat").innerHTML = pt.lat().toFixed(6);
document.getElementById("lng").innerHTML = pt.lng().toFixed(6);
});
});
}
}
);
}
}
</script>
</head>
<body onload="load()" onunload="GUnload()" >
<p>This page uses the Google Maps API to find out accurate geographical coordinates (latitude and longitude) for any place on Earth. <br/>It provides two ways to search, either by moving around the map and zooming in, or by typing an address if the place is unknown.<br/>
<i>
<p> The default location and address are those of Mondeca office in Paris.<br />
<p><b> Find coordinates by moving around the map</b></p> <p>1. Drag and drop the map to broad location. <br/>
2. Zoom in for greater accuracy. <br/>
3. Drag and drop the marker to pinpoint the place. The coordinates are refreshed at the end of each move. </p>
<form action="#" onsubmit="showAddress(this.address.value); return false">
<p>
<input type="text" size="60" name="address" value="3 cité Nollez Paris France" />
<input type="submit" value="Search!" />
</p>
</form>
<p align="left">
<table bgcolor="#FFFFCC" width="300">
<tr>
<td width="100"><b>Latitude</b></td>
<td id="lat"></td>
</tr>
<tr>
<td width="100"><b>Longitude</b></td>
<td id="lng"></td>
</tr>
</table>
</p>
<p>
<div align="center" id="map" style="width: 600px; height: 400px"><br/></div>
</p>
</body>
</html>
It was same problem as mentioned above. when I used master page no google map was drawn. I found solution later.
You need to call the Javascript function in .aspx page where you want to show google map (like initialize();) may be different in your case.
code in my case:
<script type="text/javascript"">
window.onload = function () {
DrawGoogleMap();
}
function DrawGoogleMap() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("GoogleMap_Div"));
geocoder = new GClientGeocoder();
GService.GetGoogleObject(fGetGoogleObject);
}
}
</script>
Load up FireFox and FireBug, start looking for javascript errors.
One item that I have found, you have to call setCenter on the map for it to display.
Also, if you are adding markers (or layers), you have to add the marker after you call setCenter.
Ended up having to force the div to visible
See this thread on google maps support forums:
http://groups.google.com/group/Google-Maps-Troubleshooting/browse_thread/thread/0d27b66eef5f5d9e/1259a2991412f796?lnk=raot
Thanks!!
One thing that can change when you add a master page is your elements ids.
If the div you are displaying the map in has runat="server" on it, you could have a problem.
You would add that tag so you could manipulate the div from code-behind.
So, if my div looks like this:
<div id="gmap" runat="server"></div>
If so, when you are initializing your map, you need to get the ClientId of the div. That would look like this:
var mapDiv = '<%= gmap.ClientID %>';
var map = new GMap2(mapDiv);
the code i used is
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<META NAME="AUTHOR" CONTENT="Rakshith Krishnappa">
<META NAME="DESCRIPTION" CONTENT="KML Tool - Get Latitude and Longitude for KML Polyline">
<META NAME="KEYWORDS" CONTENT="Google, maps, mashup, tools, kml, polyline">
<META NAME="ROBOTS" CONTENT="ALL">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>Mapmash | Geocoder Tool | Geocode - Reverse Geocode - IP Geocode</title>
<%--<style type="text/css">
<!--
html {
height: 100%; width:100%;overflow:hidden;
}
body {
background-color: white;
font-family: Arial, sans-serif;
font-size:10pt
}
h1 {
font-size: 18pt;
}
#map {
height: 100%;
}
#hand_b {
width:31px;
height:31px;
background-image: url(http://google.com/mapfiles/ms/t/Bsu.png);
}
#hand_b.selected {
background-image: url(http://google.com/mapfiles/ms/t/Bsd.png);
}
#placemark_b {
width:31px;
height:31px;
background-image: url(http://google.com/mapfiles/ms/t/Bmu.png);
}
#placemark_b.selected {
background-image: url(http://google.com/mapfiles/ms/t/Bmd.png);
}
#line_b {
width:31px;
height:31px;
background-image: url(http://google.com/mapfiles/ms/t/Blu.png);
}
#line_b.selected {
background-image: url(http://google.com/mapfiles/ms/t/Bld.png);
}
#shape_b {
width:31px;
height:31px;
background-image: url(http://google.com/mapfiles/ms/t/Bpu.png);
}
#shape_b.selected {
background-image: url(http://google.com/mapfiles/ms/t/Bpd.png);
}
-->
</style>
<style type="text/css">
v\:* {
behavior:url(#default#VML);
}
</style>--%>
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAPkZq56tNYNmeuZjNQQ2p3hT0NZP-HbfQNNfWb9Z5SLbjZKYKwBTrGBqtttFmF2d-kWv2B2nqW_NyEQ"></script>
<script type="text/javascript">
google.load("maps", "2");
</script>
<script src="dragzoom.js" type="text/javascript"></script>
<script src="http://adserver.lat49.com/lat49/v0.10/lat49.js" type="text/javascript"></script>
<!-- Start of Google Analytics Code -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2417064-1";
urchinTracker();
</script>
<!-- End of Google Analytics Code -->
<script type="text/javascript">
//<![CDATA[
//rakf1 modified code taken from these 2 sources: - http://www.gorissen.info/Pierre/maps/googleMapLocationv4.php and - Distance Measurement Tool - Google Mapplets
// argItems code taken from
// http://www.evolt.org/article/Javascript_to_Parse_URLs_in_the_Browser/17/14435/?format=print
var map;
var coordinates = '';
var geocoder = new GClientGeocoder();
var added = 0;
var marker;
function write_point() {
var position = marker.getPoint();
var lat = position.y.toFixed(6);
var lng = position.x.toFixed(6);
coordinates = lng + "," + lat + "\n";
document.getElementById("attribute").value = 'lat="'+lat+'" lng="'+lng+'"';
document.getElementById("latlng").value = '<lat>'+lat+'</lat>\n<lng>'+lng+'</lng>';
document.getElementById("kml").value = lng+','+lat;
document.getElementById("coord").value = marker.getPoint().toUrlValue();
}
function get_address1() {
GEvent.addListener(marker, "click", function(){
var position = marker.getPoint();
var lat = position.y.toFixed(6);
var lng = position.x.toFixed(6);
var html = 'FreeReverseGeo.com (~address):<br><iframe id="RSIFrame" name="RSIFrame" style="overflow:hidden; width:200px; height:55px; border: 1px" src="http://www.freereversegeo.com/gmap-api.php?lat_1=' + lat + '&lng_1=' + lng + '"></iframe><br>('+lat+','+lng+')';
marker.openInfoWindowHtml(html);
});
}
function get_address() {
GEvent.addListener(marker, "click", function(){
var position = marker.getPoint();
geocoder.getLocations(position, function(addresses) {
if(addresses.Status.code != 200) {
marker.openInfoWindowHtml("<b>Google Reverse Geocode:</b><br>Reverse geocoder failed to find an address for " + position.toUrlValue());
}
else {
address = addresses.Placemark[0];
var html = address.address;
marker.openInfoWindowHtml("<b>Google Reverse Geocode:</b><br>"+html);
}
});
});
}
function my_location() {
if (google.loader.ClientLocation) {
var cl = google.loader.ClientLocation;
var html = 'Google ClientLocation: <br><font size="+1">' + cl.address.city + ', ' + cl.address.region+ '<br> ' + cl.address.country+'</font><br>('+cl.latitude+','+cl.longitude+')';
var point = new GLatLng(cl.latitude, cl.longitude);
if(!marker) {
map.setZoom(12);
marker = new GMarker(point,{title: "Click to get address", draggable: true});
map.addOverlay(marker);
added = 1;
}
map.setCenter(point);
marker.setPoint(point);
marker.openInfoWindowHtml(html);
}
}
function draw_point() {
GEvent.addListener(map, 'click', function(overlay, point) {
if (point && !added) {
marker = new GMarker(point, {icon:G_DEFAULT_ICON, draggable: true, title: "Click to get address"});
map.addOverlay(marker);
added = 1;
GEvent.addListener(marker, "dragend", function(){
write_point();
});
}
else if (point && added) {
marker.setPoint(point);
}
write_point();
get_address();
});
}
function showAddress(address) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 11);
if(!marker) {
marker = new GMarker(point, {icon:G_DEFAULT_ICON, draggable: true, title: "Click to get address"});
map.addOverlay(marker);
get_address();
added = 1;
}
marker.setPoint(point);
write_point();
}
}
);
}
function showLat49Ads(){
Lat49.initAds(19);
var center = map.getCenter();
var lat = center.lat();
var lng = center.lng();
var zoomlevel = Lat49.Tile.convertGMap2Zoom(map.getZoom());
Lat49.updateAdByLatLon("lat49ads", lat, lng, zoomlevel);
}
function load(){
map = new GMap2(document.getElementById("map"),{draggableCursor: 'crosshair', draggingCursor: 'crosshair'});
map.addControl(new GSmallZoomControl());
map.addControl(new GMenuMapTypeControl(),new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(61,7)));
map.addMapType(G_PHYSICAL_MAP);
map.addControl(new GOverviewMapControl());
var boxStyleOpts = { opacity: .2, border: "2px solid yellow" };
var otherOpts = {
buttonHTML: "<img src='zoom-control-inactive1.png' title='Drag Zoom' />",
buttonZoomingHTML: "<img src='zoom-control-active1.png' title='Drag Zoom: Cancel' />",
buttonStartingStyle: {width: '15px', height: '15px'},
overlayRemoveTime: 0 };
map.addControl(new DragZoomControl(boxStyleOpts, otherOpts, {}), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(25,7)));
map.setCenter(new GLatLng(37.35, -121.93), 12);
draw_point();
showLat49Ads();
GEvent.addListener(map, "moveend", showLat49Ads);
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<table width="100%" height="100%" style="width:100%; height:100%">
<tr style="vertical-align:top">
<td style="width:320px">
<table><tr>
</tr></table>
</td>
<td>
</td>
<td align="right">
<nobr>
<form action="#" onsubmit="showAddress(this.address.value); return false">
<input type="text" size="30" name="address" value="Chicago, IL" />
<input type="submit" value="Go!" />
</form>
</nobr>
</td>
</tr>
<tr>
<td valign="top">
<div style="width:300px;font-size:8pt"><h1>GeoCoder</h1>Click on the map or search a place to add a marker and drag marker around to get marker position coordinates. Click on marker to get approximate address.</div>
<br><span style="font-size:8pt"><b>Coordinates (lat, lng):</b> [for GLatLng]</span><br>
<input type="text" size="30" id="coord" onclick="this.select()"/>
<br><br><span style="font-size:8pt"><b>Coordinates (lng, lat):</b> [for KML]</span><br>
<input type="text" size="30" id="kml" onclick="this.select()"/>
<br><br><span style="font-size:8pt"><b>Coordinates (lat="x.xx" lng="x.xx"):</b></span><br>
<input type="text" size="30" id="attribute" onclick="this.select()"/>
<br><br><span style="font-size:8pt"><b>Coordinates (<lat> <lng>):</b></span><br>
<textarea rows="2" cols="24" id="latlng" onclick="this.select()" ></textarea>
<br>
<br>
<script type="text/javascript"><!--
google_ad_client = "pub-2773616400896769";
/* maptools_300x250_01 */
google_ad_slot = "1034665593";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>
<td colspan="2" width="100%" height="100%">
<div style="position:relative;width:100%;height:100%">
<div id="lat49ads" lat49adposition="top-right"
style="position:absolute;top:7px; right:4px; width:125px; height:133;z-index:99999;"></div>
<div id="map" style="width:100%;height:400px;min-height:400px;border:1px solid #999;"></div>
</div>
</td>
</tr>
</table>
</body>
</html>
if anyone have any idea regarding to code i posted earlier please post a comment.
thanks