How can i get input radio value to C# - c#

can you tell me whats bad? I need only check on button select language to continue on next website.
HTML
<asp:Content ID="BodyContent" ContentPlaceHolderID="BodySite" runat="server">
<h1>Výběr jazyka:</h1>
<p>Choose language | Sprachauswahl</p>
<form method="post" action="index.aspx">
<div class="checkbox-test">
<table style="border-spacing: 5px; border-collapse: separate;">
<tr>
<td>
<input type="radio" name="check_lang" id="check_cz" class="css-checkbox" value="cz" />
<label for="check_cz" class="css-label"><img src="http://terquil.cz/images/cz.png" class="img-flag" alt="CZ" /></label>
</td>
<td><h2>CZ</h2></td>
</tr>
<tr>
<td>
<input type="radio" name="check_lang" id="check_en" class="css-checkbox" value="en" />
<label for="check_en" class="css-label"><img src="http://terquil.cz/images/uk.png" class="img-flag" alt="EN" /></label>
</td>
<td><h2>EN</h2></td>
</tr>
<tr>
<td>
<input type="radio" name="check_lang" id="check_de" class="css-checkbox" value="de" />
<label for="check_de" class="css-label"><img src="http://terquil.cz/images/de.png" class="img-flag" alt="DE" /></label>
</td>
<td><h2>DE</h2></td>
</tr>
</table>
</div>
<input Type="submit" id="language_btn" VALUE="Pokračovat | Continue | Andere" >
</form>
C# (i tried this but dont work)
protected void submit(object sender, EventArgs e)
{
string cz = "cz";
string de = "de";
string en = "en";
if (Request.Form["check_lang"] != null)
{
string selectLanguage = Request.Form["check_lang"].ToString();
if (selectLanguage == cz)
Response.Redirect("http://terquil.cz/cs/index.aspx");
if (selectLanguage == en)
Response.Redirect("http://terquil.cz/en/index.aspx");
if (selectLanguage == de)
Response.Redirect("http://terquil.cz/cs/index.aspx");
}
}
CSS group objects:
input[type=radio].css-checkbox {
position:absolute;
z-index:-1000;
left:-1000px;
overflow: hidden;
clip: rect(0 0 0 0);
height:1px;
width:1px;
margin:-1px;
padding:0;
border:0;
}
input[type=radio].css-checkbox + label.css-label {
padding-left:37px;
height:32px;
display:inline-block;
line-height:32px;
background-repeat:no-repeat;
background-position: 0 0;
font-size:32px;
vertical-align:middle;
cursor:pointer;
}
input[type=radio].css-checkbox:checked + label.css-label {
background-position: 0 -32px;
}
label.css-label {
background-image:url(http://csscheckbox.com/checkboxes/u/csscheckbox_c1a4f40d98f1c23d1ad84d2af9c314be.png);
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
I need make only that if someone select radio for his specify language and click on submit button so he will redirect to specify html page for his language.

Either use runat="server" to access it in c# code
Or use javascript, on change event of radio button you can store value in a hidden field which will be accessible into your c# code.
$(document).ready(function(){
$('#rdbEnglish').click(function(){
$('#hdn').val('English');
});

Related

How does one get the value of a button click in ASP.NET Core MVC?

I am trying to understand how the connection between a controller and a view works. I have set up four buttons with the tag asp-action expecting it to allow me to implement a method with the name check
<table style="width: 100%; margin-bottom: 25px">
<tr>
<td>
<button name="button" style="background-color: transparent; color: yellow"
type="button" value="cph" asp-action="check">København</button>
</td>
<td>
<button style="background-color: transparent; color: yellow" type="button" value="odense" asp-action="check">Odense</button>
</td>
<td>
<button style="background-color: transparent; color: yellow" type="button" value="aarhus" asp-action="check">Århus</button>
</td>
<td>
<button style="background-color: transparent; color: yellow" type="button" value="aalborg" asp-action="check">Aalborg</button>
</td>
</tr>
</table>
I tried to print the value of the button
public IActionResult check(string button)
{
Console.WriteLine(button);
return View();
}
However, it does never print anything, nor does it break on the method. What I would like to achieve is just the value. I would prefer just passing the value and do nothing e.g.
public striing check(string button)
{
return button;
}
EDIT:
I tried following this tutorial
When we access data from a view to the controller's action method, we could use the Parameter method to get the form value, by using this method the input field Name and parameter Name should be the same. So, if you want to get button value, it should have the same Name value (but in your sample code, only the first button has a name attribute).
Second, when we using the <button> tag, it will implicitly submit the form, but if we add "type='button'" for the <button> tag, the button will not submit the form, so the action method not executed. To solve this issue, you could remove the type="button" or change it to type="submit".
So, you could modify your code as below (use the same name value and remove the type="button"):
<form>
<table style="width: 100%; margin-bottom: 25px">
<tr>
<td>
<button name="button" style="background-color: transparent; color: yellow"
value="cph" asp-action="check">
København
</button>
</td>
<td>
<button name="button" style="background-color: transparent; color: yellow" value="odense" asp-action="check">Odense</button>
</td>
<td>
<button name="button" style="background-color: transparent; color: yellow" value="aarhus" asp-action="check">Århus</button>
</td>
<td>
<button name="button" style="background-color: transparent; color: yellow" value="aalborg" asp-action="check">Aalborg</button>
</td>
</tr>
</table>
</form>
<div>
#TempData["ButtonValue"]
</div>
Code in the controller:
public IActionResult ButtonClick()
{
return View();
}
public IActionResult check(string button)
{
if(!string.IsNullOrEmpty(button))
{
TempData["ButtonValue"] = string.Format("{0} button clicked.", button);
}
else
{
TempData["ButtonValue"] = "No button click!";
}
return RedirectToAction("ButtonClick");
}
Then, the result like this:

Acumatica Rest API get Business Account

I'm trying to receive Business Account info through the rest API. I try with a filter and without the filter. It is using the default end point and the default BusinessAccount. The results of both runs are below after the code.
My code to get the Acumatica content
public async void GetCustomersActivitiesAsync(int top, string filterOperation, string filter)
{
string url = settings.url + settings.endpoint + "BusinessAccount";
string parametersFilter = "&$filter=BusinessAccount eq 'ABARTENDE'";
var uri = new Uri(url + parametersFilter);
try
{
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
}
else
{
err = await response.Content.ReadAsStringAsync();
try
{
ResponseMessage msg = JsonConvert.DeserializeObject<ResponseMessage>(err);
if (msg != null && msg.exceptionMessage != "") err = msg.exceptionMessage;
}
catch (Exception ex)
{
err = ex.Message;
}
}
}
catch (Exception ex)
{
Debug.WriteLine(#" ERROR {0}", ex.Message);
err = ex.Message;
}
}
When I run the filter it fails auto manically
When I do a filter it returns this:
<!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 id="Head1"><link href="/A000/Content/font-awesome.css?timestamp=636698449900000000" type="text/css" rel="stylesheet" /><link href="/A000/App_Themes/Default/00_Controls.css?timestamp=636698449900000000" type="text/css" rel="stylesheet" /><title>
Error Has Occurred
</title><meta http-equiv="content-script-type" content="text/javascript" />
<style type="text/css">
.main
{
padding-left: 40px;
padding-right: 20px;
padding-top: 30px;
font-family: Arial;
}
.errCode
{
padding-bottom: 20px;
font-family: Arial;
font-size: 15pt;
}
.errMsg
{
font-size: 12pt;
}
.img
{
float: left;
margin-right: 10px;
}
.nxtSt
{
margin-top: 30px;
font-family: Arial;
font-size: 15pt;
}
.navTo
{
margin-top: 10px;
margin-left: 20px;
}
.errPnl
{
padding: 10px;
padding-top: 15px;
}
.grayBox
{
border: solid 1px #CCC;
background-color: #F9F9F9;
padding-top: 20px;
padding-bottom: 25px;
padding-left: 10px;
padding-right: 20px;
}
.traceLnk
{
margin-top: 20px;
}
</style>
<style type="text/css">
.frmBottom_CaptionL { background-position:left top;width:5px; }
.frmBottom_CaptionR { background-position:right top;width:5px; }
.frmBottom_CaptionM { }
</style></head>
<body>
<form name="form1" method="post" action="./Error.aspx" id="form1">
<input type="hidden" name="__RequestVerificationToken" id="__RequestVerificationToken" value="Aq4LEYY5T50IzZfjFHxJWWVP0lq4kLBG-ljIPF3eUYBdBo3UHLHNgHdHF8YW9hpS3nHqiATSFrDybUkJvaXapM_ZItg1" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="frmBottom_state" id="frmBottom_state" value="" />
<input type="hidden" name="__SmartPanelVisible" id="__SmartPanelVisible" value="" />
<input type="hidden" name="L10nEditor_state" id="L10nEditor_state" value="" />
<input type="hidden" name="inputBox_state" id="inputBox_state" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />
<script type="text/javascript">
//<![CDATA[
var __appPath = '/A000/';var __nodePath="";var __nodeGuid="00000000-0000-0000-0000-000000000000";//]]>
</script>
<script src="/A000/PX.ScriptBatch.axd?d=cFBYLldlYi5VSXxQWC5XZWIuVUkuRXh00&t=636698318120000000" type="text/javascript"></script>
<script src="/A000/PX.ScriptBatch.axd?d=cFBYLldlYi5VSXxQWC5XZWIuVUkuQmFzZQ2&t=636698318120000000" type="text/javascript"></script>
<script src="/A000/PX.ScriptBatch.axd?d=cFBYLldlYi5VSXxQWC5XZWIuVUkuRWRpdA2&t=636698318120000000" type="text/javascript"></script>
<script src="/A000/PX.ScriptBatch.axd?d=cFBYLldlYi5VSXxQWC5XZWIuVUkuR3JpZA2&t=636698318120000000" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var __loadImgUri = "/A000/App_Themes/Default/Images/spinner.gif?imgTimeStamp=636698449900000000";
var __loadStr = "";
var _numbFormatInfo = {negativeSign:"-",currencySymbol:"$",percentSymbol:"%",number:{groupSeparator:",",decimalSeparator:".",groupSizes:[3],negativePattern:1,decimalDigits:2},currency:{groupSeparator:",",decimalSeparator:".",groupSizes:[3],positivePattern:0,negativePattern:0,decimalDigits:2},percent:{groupSeparator:",",decimalSeparator:".",groupSizes:[3],positivePattern:1,negativePattern:1,decimalDigits:2}};
var _dateFormatInfo = {am:"AM",pm:"PM",shortDate:"M/d/yyyy",shortTime:"h:mm tt",longDate:"dddd, MMMM d, yyyy",longTime:"h:mm:ss tt",timeSeparator:":",yearFix:0,monthNames:"January,February,March,April,May,June,July,August,September,October,November,December,",abbrMonthNames:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,",dayNames:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",abbrDayNames:"Sun,Mon,Tue,Wed,Thu,Fri,Sat"};
__createPxContext(window);
var __PXFormView = {maxFileSizeMsg:"The file exceeds the maximal allowed size (25000 KB).",allowedFiles:".als;.cer;.csv;.dat;.doc;.docx;.epl;.exe;.gif;.ico;.ics;.jpeg;.jpg;.js;.mdb;.msi;.ofx;.pdf;.pfx;.ppt;.pptx;.qbo;.qfx;.rar;.rtf;.sql;.swf;.txt;.xls;.xlsx;.xml;.zip;.zpl;.pbix;.png;.svg;.tif;.tiff",allowedFilesMsg:"Only the following file types are allowed: {0}.",callbacks:[{name:"Refresh",repaintControls:1,blockPage:1,postData:0},{name:"Search",repaintControls:1,blockPage:1},{name:"Save",repaintControls:1,blockPage:1,commitChanges:1},{name:"Delete",repaintControls:1,blockPage:1},{name:"AddNew",repaintControls:1,blockPage:1,postData:0},{name:"NoteShow",blockPage:1,postData:0},{name:"NoteSave",repaintControls:3,blockPage:1,postData:0},{name:"FilesMenuShow",blockPage:1,postData:0},{name:"ActivityShow",blockPage:1,postData:0},{name:"LinkShow",repaintControls:3,blockPage:1,postData:0},{name:"LinkUpdate",repaintControls:3,blockPage:1,postData:0},{name:"LinkSend",repaintControls:3,blockPage:1,postData:0},{name:"NotifyMenuShow",repaintControls:3,blockPage:1,postData:0},{name:"NotifyShow",repaintControls:3,blockPage:1,commitChanges:1,postData:0},{name:"CheckActivity",blockPage:1,postData:0},{name:"UploadFile",blockPage:1}],errorCss:"FormError",warningCss:"FormWarn",infoCss:"FormInfo",minHeight:63,filesMenuUrls:{filesDisplayUrl:"~/Frames/GetFile.ashx",fileInfoUrl:"~/Pages/SM/SM202510.aspx"}};
var _frmBottom = {allowCollapse:0,minHeight:0,autoSize:{enabled:1,container:1}};
var _confirmMsg = "Any unsaved changes will be discarded.";
var __PXSmartPanel = {callBackMode:{blockPage:1,postData:0}};
var _L10nEditor = {loadOnDemand:1,autoReload:1,commandName:"SaveLoc",autoCallBack:{behavior:{postData:0}}};
var __PXInputBox = {activeEnter:0,buttonCss:"MessageButton",autoAdjustSize:1,callBackMode:{blockPage:1,postData:0}};
var _inputBox = {};
//]]>
</script>
<div class="main">
<div name="frmBottom" id="frmBottom">
<div style="position:relative;">
<div class="errCode">
</div>
<div class="grayBox">
<div class="img">
<img id="frmBottom_imgMessage" tabindex="100" src="../App_Themes/Default/Images/Message/error2.gif" border="0" />
</div>
<div class="errMsg">
<span id="frmBottom_lblMessage" class="errMsg">We're sorry! An error has occurred while processing your request. A report has been generated for our technical staff to investigate the problem. Please try to repeat your request later. Thank you for understanding.</span>
</div>
</div>
<div class="traceLnk">
<a id="frmBottom_lnkTrace" tabindex="101" href="Trace.aspx"><u><font color="Blue" size="4">Show Trace</font></u></a>
</div>
<div class="nxtSt">
</div>
<div class="navTo">
</div>
</div>
</div>
</div>
<table name="L10nEditor" cellspacing="0" cellpadding="0" id="L10nEditor" tabindex="300" class="SmartPanel" style="display:none;">
<tr>
<td id="L10nEditor_cap" class="SmartPanelC" valign="middle"><div class="sprite-icon control-icon" icon="Close" mode="c" style="float:right;">
<div class="control-icon-img control-Close">
</div>
</div>Translations</td>
</tr><tr>
<td class="SmartPanelCN" id="L10nEditor_cont" width="0" height="0"><div class="panelContent">
</div></td>
</tr>
</table><table name="inputBox" cellspacing="0" cellpadding="0" id="inputBox" tabindex="400" class="SmartPanel" width="400" style="display:none;">
<tr>
<td id="inputBox_cap" class="SmartPanelC" valign="middle"><div class="sprite-icon control-icon" icon="Close" mode="c" style="float:right;">
<div class="control-icon-img control-Close">
</div>
</div>Copy to clipboard (Ctrl+C)</td>
</tr><tr>
<td class="SmartPanelCN" id="inputBox_cont" width="400" height="0"><table tabindex="400" border="0" width="100%">
<tr>
<td><input name="inputBox$ctl01" type="text" class="editor" /></td>
</tr><tr>
<td align="right"><button type="button" class="MessageButton Button">OK</button><button type="button" class="MessageButton Button">Cancel</button></td>
</tr>
</table></td>
</tr>
</table></form>
</body>
</html>
The query parameters, such as $filter, are separated from the path by ?. In your case that should give <base url>/BusinessAccount?$filter=<filter espression>.

Unable to click button which is inside iframe and table in Selenium webDriver with c#

I am new to c# and I am working with Selenium chrome webdriver in c#. I am trying to click button which inside table. I am not able to identify and click button.The hierarchy of button is (Page > PopOver > PopOverFrame > Table1 > Table2 > Button to click )
Any help with this would be much appreciated thank you.
my code is :
*/
// Closing old tab, keeping control in new tab and trying to perform click operation
var currentWindow = BaseTest.Driver.CurrentWindowHandle;
var availableWindows = new List<string>(BaseTest.Driver.WindowHandles);
foreach (string mywindows in availableWindows)
{
if (mywindows != currentWindow)
{
Driver.SwitchTo().Window(mywindows).Close();
}
else
{
Driver.SwitchTo().Window(currentWindow);
// performing click action on RUN REPORT button
IWebElement popOver = Driver.FindElement(By.Id("popOver"));
IWebElement popOverFrame = popOver.FindElement(By.Id("popOverFrame"))
IWebElement table1 = popOverFrame.FindElement(By.XPath("//*[#id='form1']/table"));
IWebElement Table2 = table1.FindElement(By.XPath("//*[#id='tblReport']"));
Table2.FindElement(By.Id("contentPlaceholder_btnPrint")).Click();
}
}
Please refer to attached screenshot of what html page looks like.
<html xmlns="http://www.w3.org/1999/xhtml" ><title>
<div id="divReportHeader">
<span id="contentPlaceholder_lblReportDescHeader" class="reportHeader">Description</span>
<br>
<span id="contentPlaceholder_lblReportDescription">Offer</span>
</div>
<table>
<tbody><tr>
<td style="vertical-align: top;">
<div style="margin: 2px; padding: 8px;">
<table width="1000px" style="border-spacing: 0; padding: 0" id="tblReport">
<tbody><tr>
<td></td>
</tr>
<tr>
<td><div id="contentPlaceholder_generalInformation" class="reportHeader">Information</div></td>
</tr>
<tr>
<td>
<span id="contentPlaceholder_lblRptInfo">
This report may require more information. Click "Run Report" to view the report inline.
</span>
<br>
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
<td>
<span id="contentPlaceholder_lblfrom">abc </span>
<select name="ctl00$contentPlaceholder$ddlfromYear" onchange="javascript:setTimeout('__doPostBack(\'ctl00$contentPlaceholder$ddlfromYear\',\'\')', 0)" id="contentPlaceholder_ddlfromYear">
</select>
<span id="contentPlaceholder_lblFilter5" style="display: block; margin-top: 10px; margin-bottom: 4px;">Additional columns to be included:<br>Due to potential page size limitations, additional custom columns should only be selected when intending to view inline or export as Excel.</span>
<input type="submit" name="ctl00$contentPlaceholder$btnSelectAll" value="Select All" id="contentPlaceholder_btnSelectAll" class="roundedButton">
<input type="submit" name="ctl00$contentPlaceholder$btnDeselectAll" value="Deselect All" id="contentPlaceholder_btnDeselectAll" class="roundedButton" style="margin-bottom:5px;">
<table id="chkList2" class="correctCheckboxes">
<tbody><tr>hkList2_0" value="Select"><label for="chkList2_0">Help</label></td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td>
<br>
<div id="contentPlaceholder_parameterNotes" class="reportHeader">
Notes
</div>
<br>
<span id="contentPlaceholder_txtParameterNotes">None</span>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<input type="submit" name="ctl00$contentPlaceholder$btnPrint" value="RUN REPORT" onclick="disable('contentPlaceholder_btnPrint');__doPostBack('ctl00$contentPlaceholder$btnPrint','');" id="contentPlaceholder_btnPrint" class="roundedButton" style="width:130px;">
</td>
</tr>
</tbody></table>
</div></td>
</tr>
</tbody></table>
<iframe id="ifrmDownload" style="display: none;"></iframe>
<iframe id="ifrmStatus" src="statuscheck.aspx" style="display: none;"></iframe>
</form>
</body></html>
Try this:
//remove this line IWebElement popOver = Driver.FindElement(By.Id("popOver"));
Driver.SwitchTo().DefaultContent();
IWebElement popOverFrame = Driver.FindElement(By.Id("popOverFrame"))
Driver.SwitchTo().Frame(popOverFrame);
//remove this line IWebElement table1 = popOverFrame.FindElement(By.XPath("//*[#id='form1']/table"));
IWebElement Table2 = Driver.FindElement(By.XPath("//*[#id='tblReport']"));
Table2.FindElement(By.Id("contentPlaceholder_btnPrint")).Click();
Try the below one:
driver.switchTo().frame(driver.findElement(By.xpath(iframeXpath)));
And once the operations are completed inside iFrame, switch back to default content.
driver.switchTo().defaultContent();

How to open a popup div in Codebehind c#

Open Popup on Item Template c#.
My problem is that when i click the popup it will open the popup but it will not hit the RowCommand argument(i.e. e.commandname).
Here is the code:
<ItemTemplate><asp:LinkButton ID="imgAppointment" Text="Appointment" runat="server" Style="float: left; margin-right: 5px;" CommandName="App" CommandArgument='<%#Eval("ID") %>' CssClass="label label-sm label-success" data-backdrop="static" data-toggle="modal" data-target="#AddTask"></asp:LinkButton></ItemTemplate>
This is the code on :
protected void gvTaskDetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "App")
{
DataTable retval = obj.FetchAppointmentByMalmrktId(Convert.ToInt32(e.CommandArgument));
if (retval.Rows.Count > 0)
{
Repeater rptCustomers = (Repeater)Page.FindControl("rptCustomers");
rptCustomers.DataSource = retval;
rptCustomers.DataBind();
}
}
}
This is the popup div:
<div class="modal fade " id="AddTask" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-right: -15px !important;">
<div class="modal-dialog" style="margin-right: 0; width: 50%; margin-top: 0; margin-bottom: 0px; background: #fff; height: 100vh; overflow-y: auto;">
<div class="modal-header">
<div class="row">
<div class="col-sm-6">
<h3 class="text-primary text-big" style="margin-top: 0px; margin-bottom: 0px;"><b>Appointment </b></h3>
</div>
<div class="col-sm-6">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-chevron-circle-right" id="btnAddTaskclose"></i></button>
</div>
</div>
<asp:Repeater ID="rptCustomers" runat="server">
<HeaderTemplate>
<div class="box-model">
<table class="table">
<tr>
<th style="width: 140px;">Appointment Date :
</th>
</tr>
<tr>
<th style="width: 140px;">Details :
</th>
</tr>
</table>
</div>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width: 400px;">
<asp:Label ID="lbAppointmentdt" runat="server" Text='<%# Eval("Appointmentdate") %>' />
</td>
<td style="width: 400px;">
<asp:Label ID="lblDetails" runat="server" Text='<%# Eval("Details") %>' />
</td>
<td>Status
<br />
<button type="button" class="btn btn-xs btn-danger">Cancel Appointment</button>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
ter>
You can try to trigger the event manually if nothing else works.
If the command event is what you need (if I correctly understand), you can hit the event like this:
<script >
function myModalFunction() {
$("#AddTask").modal();
} </script>
// method to trigger an jsFunction
public void dispararJSfunction(string script)
{
try
{
Page page = HttpContext.Current.CurrentHandler as Page;
ScriptManager.RegisterStartupScript(Page, this.Page.GetType(), "its working", script, true);
}
catch (Exception ex) { Master.MostrarMsn(ex.Message, 0); }
}
protected void imgAppointment_Click(object sender, EventArgs e)
{
// script = the js modal function
dispararJSfunction("myModalFunction()");
CommandEventArgs commandArgs = new CommandEventArgs("Command Name Here", "Your Command Argument Here");
//You can pass any row
//You can also skip the row parameter and get the row from Command Argument
GridViewCommandEventArgs eventArgs = new GridViewCommandEventArgs(GridView1.Rows[0], GridView1, commandArgs);
GridView1_RowCommand(GridView1, eventArgs);
}
If I'm missing something let me know. This is what it came up first to my head. I hope this can help you in some way.

WebGrid: GetSelectLink() returning wrong details for selected record

Context: I’m building a web application using WebMatrix and C# Razor. The application searches a database and returns the results to a WebGrid. Once the results are returned, you can click a Details link and view the details on a new browser tab.
Problem: The initial search, which returns all records, works fine. If I enter search words, the correct results are returned, but when I click on Details, I get details for the record that was in the selected row in the initial search.
Example: The initial search returns records 1-5. The subsequent search returns records 31, 65, 86,92, 101. If I click on Details for record 65, I get details for record 2 because record 2 occupied row 2 in the initial search.
Code:
#{
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Home Page";
}
#{
var db = Database.Open("xyz");
var query = "select bg_bug_id [BUGID], BG_SUMMARY SUMMARY from [dbo].[BUG] where BG_SUMMARY like #0 and BG_SUMMARY like #1";
var input1 = "%" + Request["input1"] + "%";
var input2 = "%" + Request["input2"] + "%";
var data = db.Query(query, input1, input2);
var gridBug = new WebGrid(source: data, canPage: true, canSort: true, rowsPerPage: 10);
if(gridBug.HasSelection){
var recordIdInt = 0;
recordIdInt = gridBug.SelectedRow.Value.BUGID;
var recordId = recordIdInt.ToString();
var bugDescQuery = "select [BG_DESCRIPTION] from [dbo].[BUG] where [BG_BUG_ID] =" + recordId; // or [BG_BUG_ID] = 25001";
var bugDescResult = db.Query(bugDescQuery);
foreach(var item in bugDescResult){
var desc = item.BG_DESCRIPTION;
var modDesc = desc.Replace("<div align=\"left\">", "<div>").Replace("<font face=\"Arial\">", "<font>").Replace("<span style=\"font-size:8pt\">", "<span>");
<script>
$(document).ready(function(){
var x = '#Html.Raw(HttpUtility.JavaScriptStringEncode(modDesc))';
var win = window.open();
win.document.body.innerHTML = "Record ID: " + #recordId + " - -" + x;
})
</script>
}
}
}
<form method="post">
<input type="text" name="input1"/>
<input type="radio" id="and" name="operator" value="and" checked>And
<input type="radio" id="or" name="operator" value="or">Or
<input type="text" name="input2" />
<select>
<option value="Unresolved">Unresolved</option>
<option value="Resolved">Resolved</option>
</select>
<input type="submit" value="Search" />
#gridBug.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: gridBug.Columns(
gridBug.Column(header:"", format:#<text>#item.GetSelectLink("Details")</text>, style: "product2"),
gridBug.Column("BUGID", "BUGID", style: "product2"),
gridBug.Column("SUMMARY", "SUMMARY", style: "product")))
</form>
#section script{
<script type="text/javascript">
$(function(){
$('th a, tfoot a').live('click', function() {
$('form').attr('action', $(this).attr('href')).submit();
return false;
});
});
</script>
}
<style type="text/css">
.grid {
margin: 4px;
border-collapse: collapse;
width: 950px;
margin-left: 5px
}
.head {
background-color: #0094ff;
font-weight: bold;
color: #fff;
}
.grid th, .grid td {
border: 1px solid #c0c0c0;
padding: 5px;
}
.alt {
background-color: #e8e8e8;
color: #000;
}
.product {
width: 200px;
font-weight: normal;
}
.product2 {
width: 10px;
font-weight: normal;
}
</style>
SOURCE AFTER 2nd SEARCH:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Home Page</title>
<link href="/Content/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css" />
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
<link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<script src="/Scripts/jquery-1.8.2.min.js"></script>
<script src="/Scripts/jquery-ui-1.8.24.js"></script>
<script src="/Scripts/modernizr-2.6.2.js"></script>
<meta name="viewport" content="width=device-width" />
<script type="text/javascript">
$(function(){
$('th a, tfoot a').live('click', function() {
$('form').attr('action', $(this).attr('href')).submit();
return false;
});
});
</script>
</head>
<body>
<header>
<div class="content-wrapper">
<div class="float-left">
<p class="site-title">XXXX</p>
</div>
<div class="float-right">
<section id="login">
<ul>
<li>Register</li>
<li>Log in</li>
</ul>
</section>
<nav>
<ul id="menu">
<li>XXXX</li>
<li>XXXX</li>
<li>XXXX</li>
</ul>
</nav>
</div>
</div>
</header>
<div id="body">
<section class="content-wrapper main-content clear-fix">
<form method="post">
<input type="text" name="input1"/>
<input type="radio" id="and" name="operator" value="and" checked>And
<input type="radio" id="or" name="operator" value="or">Or
<input type="text" name="input2" />
<select>
<option value="Unresolved">Unresolved</option>
<option value="Resolved">Resolved</option>
</select>
<input type="submit" value="Search" />
<table class="grid">
<thead>
<tr class="head">
<th scope="col">
</th>
<th scope="col">
BUGID </th>
<th scope="col">
SUMMARY </th>
</tr>
</thead>
<tfoot>
<tr >
<td colspan="3">1 2 3 > </td>
</tr>
</tfoot>
<tbody>
<tr>
<td class="product2">Details</td>
<td class="product2">1655</td>
<td class="product">summary text for record 1655</td>
</tr>
<tr class="alt">
<td class="product2">Details</td>
<td class="product2">2516</td>
<td class="product">summary text for record 2516</td>
</tr>
<tr>
<td class="product2">Details</td>
<td class="product2">2639</td>
<td class="product">summary text for record 2639</td>
</tr>
<tr class="alt">
<td class="product2">Details</td>
<td class="product2">2643</td>
<td class="product">summary text for record 2643</td>
</tr>
<tr>
<td class="product2">Details</td>
<td class="product2">3493</td>
<td class="product">summary text for record 3493</td>
</tr>
<tr class="alt">
<td class="product2">Details</td>
<td class="product2">3746</td>
<td class="product">summary text for record 3746</td>
</tr>
<tr>
<td class="product2">Details</td>
<td class="product2">3864</td>
<td class="product">summary text for record 3864</td>
</tr>
<tr class="alt">
<td class="product2">Details</td>
<td class="product2">5172</td>
<td class="product">summary text for record 5172</td>
</tr>
<tr>
<td class="product2">Details</td>
<td class="product2">7156</td>
<td class="product">summary text for record 7156</td>
</tr>
<tr class="alt">
<td class="product2">Details</td>
<td class="product2">7532</td>
<td class="product">summary text for record 7532</td>
</tr>
</tbody>
</table>
</form>
<style type="text/css">
.grid {
margin: 4px;
border-collapse: collapse;
width: 950px;
margin-left: 5px
}
.head {
background-color: #0094ff;
font-weight: bold;
color: #fff;
}
.grid th, .grid td {
border: 1px solid #c0c0c0;
padding: 5px;
}
.alt {
background-color: #e8e8e8;
color: #000;
}
.product {
width: 200px;
font-weight: normal;
}
.product2 {
width: 10px;
font-weight: normal;
}
</style>
</section>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>© 2015 - XXXX</p>
</div>
</div>
</footer>
</body>
</html>

Categories

Resources