How to send POST request to JSF with help HttpWebRequest - c#

I send post request with body login=login&login:loginName={0}&login:password={1}&login:clientCode=&login:j_idt171=&javax.faces.ViewState=stateless
with help HttpWebRequest. Before that I was doing GET request, for getting JSESSIONID.
Web form looks like that:
<form id="login" name="login" method="post" action="/csologin/login.jsf">
<input type="hidden" name="login" value="login">
<div id="login:j_idt122" class="ui-messages ui-widget" aria-live="polite"></div><table border="0" cellpadding="2" cellspacing="0" width="580px">
<tbody>
<tr>
<td class="ecol1"><label id="login:j_idt125" class="ui-outputlabel ui-widget fbold" for="login:loginName">Username<span class="ui-outputlabel-rfi">*</span></label></td>
<td class="ecol2"><input id="login:loginName" name="login:loginName" type="text" autocomplete="off" size="40" class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" role="textbox" aria-disabled="false" aria-readonly="false" aria-multiline="false"></td>
<td class="ecol3"><div id="login:j_idt126" aria-live="polite" class="ui-message"></div></td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="2" cellspacing="0" width="580px">
<tbody>
<tr>
<td class="ecol1"><label id="login:j_idt132" class="ui-outputlabel ui-widget fbold" for="login:password">Password<span class="ui-outputlabel-rfi">*</span></label></td>
<td class="ecol2"><input id="login:password" name="login:password" type="password" class="ui-inputfield ui-password ui-widget ui-state-default ui-corner-all ui-state-hover" autocomplete="off" size="40" role="textbox" aria-disabled="false" aria-readonly="false" aria-multiline="false"></td>
<td class="ecol3"><div id="login:j_idt133" aria-live="polite" class="ui-message"></div></td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="2" cellspacing="0" width="580px">
<tbody>
<tr>
<td class="ecol1"><label id="login:j_idt135" class="ui-outputlabel ui-widget fbold" for="login:clientCode">Client Code</label></td>
<td class="ecol2"><input id="login:clientCode" name="login:clientCode" type="text" maxlength="32" size="40" class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" role="textbox" aria-disabled="false" aria-readonly="false" aria-multiline="false"></td>
<td class="ecol3"><div id="login:j_idt136" aria-live="polite" class="ui-message"></div></td>
</tr>
</tbody>
</table>
<br><div class="text-center">
<button id="login:j_idt139" name="login:j_idt139" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onclick="barWaitDialog.show();" type="submit" role="button" aria-disabled="false"><span class="ui-button-text ui-c">Login</span></button>
<!-- <p:commandButton value="Clear" onclick="clearVisibleTextFields();" /> --><button id="login:j_idt141" name="login:j_idt141" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onclick="PrimeFaces.ab({source:'login:j_idt141',oncomplete:function(xhr,status,args){clearVisibleTextFields();;}});return false;" type="submit" role="button" aria-disabled="false"><span class="ui-button-text ui-c">Clear</span></button><button id="login:j_idt142" name="login:j_idt142" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="submit" role="button" aria-disabled="false"><span class="ui-button-text ui-c">Cancel</span></button>
</div><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="stateless" autocomplete="off">
Not authenticated, it returns a redirect to login page. What am I doing wrong?

Basically, you didn't press the desired button. You need to include the name=value pair of the submit button you'd like to "press" programmatically. That's usually in the server side used to distinguish if a button was pressed and if so, which one.
There appear to be three submit buttons in the HTML form, simplified as below:
<button name="login:j_idt139" type="submit">Login</button>
<button name="login:j_idt141" type="submit">Clear</button>
<button name="login:j_idt142" type="submit">Cancel</button>
It appears that the JSF developer didn't give an explicit ID to those buttons, so an autogenerated ID is being used. This autogenerated ID depends on the position of the button component in the JSF component tree. So, if the JSF developer changes the view composition (adding/moving/removing components), then chances are that the final ID of the button in the HTML markup will also change. You'd need to alter your query string on that. The parameter login:j_idt171= in your query string likely needs to be changed to login:j_idt139=.
To make it more robust, you could try contacting the website admin/developer and ask to give those buttons an explicit ID as in <p:commandButton id="login">, so that you can always use the parameter login:login= without worrying about autogenerated IDs. If that's really not an option, then you'd basically need to use a HTML parser to find out the ID of the login button.

Related

Datalist not displaying items ASP.NET

I have a serious problem with data list I HATE IT so much. I have a list of data that displays cart items in a table.. basic right?
Sure, but not for data list! its like data list says I MUST DESTROY YOU. The data list does not show any items that I should display!
Here are some screenshots that will let you understand my issue here.
So basically the items are displayed in VS, but in the web application it doesn't.
PLEASE HELP :(
Here is the code:
<div class="container-sm cart-page">
<table>
<tr>
<th>المنتج</th>
<th>الكمية</th>
<th>السعر الفرعي</th>
</tr>
<asp:DataList ID="DataList1" runat="server" RepeatColumns="1" RepeatLayout="Flow">
<ItemTemplate>
<tr>
<td>
<div class="cart-info">
<img src="http://bestjquery.com/tutorial/product-grid/demo8/images/img-1.jpg" alt="camera">
<div>
<p>Camera 211</p>
<small>السعر: 50 ر.س.</small>
<br>
حذف
</div>
</div>
</td>
<td>
<input type="number" value="1" min="1" max="10"></td>
<td>50 ر.س.</td>
</tr>
</ItemTemplate>
</asp:DataList>
</table>
<div class="total-price">
<table>
<tr>
<td class="titles">السعر الفرعي</td>
<td>150 ر.س.</td>
</tr>
<tr>
<td class="titles">VAT</td>
<td>22.50 ر.س.</td>
</tr>
<tr>
<td class="titles">المجموع</td>
<td>172.50 ر.س.</td>
</tr>
<tr>
<td>
<a href="store.aspx">
<button type="submit" class="btn btn-primary btn-continue-shopping">إكمال التسوق</button>
</a>
</td>
<td>
<a href="checkout.aspx">
<button type="submit" class="btn btn-primary btn-checkout">إكمال الدفع</button>
</a>
</td>
</tr>
</table>
</div>
</div>
You need to set the DataSource property with some list or table of data.
Here is a link to the MSDN article: https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.basedatalist.datasource?view=netframework-4.8#System_Web_UI_WebControls_BaseDataList_DataSource
What is your data source? Are you using a database?
If you do not have a database you can mockup a dataset in XML, JSON, or CSV and then deserialize into your code.
I believe that you can bind anything that implements IList.

logic for getting discounted price based on the mrp

<table class="table table-condensed table-bordered" cellspacing="0" cellpadding="4" rules="all" border="1" id="MainContent_gviewProduct" style="color:#333333;border-collapse:collapse;">
<caption align="Top">
<table width="100%" class="gridtitle"><tbody><tr><td class="text_Title">Product Details</td></tr></tbody></table>
</caption><tbody><tr style="color:White;background-color:#008D7A;font-weight:bold;">
<th scope="col">Product Name</th><th scope="col">Product Code</th><th scope="col">Product UOM</th><th scope="col">Pack Size</th><th scope="col">RSP/MRP</th><th scope="col">Batch/MRP</th><th scope="col" style="width:150px;">Requested Price</th><th scope="col" style="width:150px;">Sale Qty in Packs</th><th scope="col" style="width:150px;">Remark</th>
</tr><tr style="color:#333333;background-color:#F7F6F3;">
<td>
<span id="MainContent_gviewProduct_lblSelectedProdName_0">2T</span>
</td><td>
<span id="MainContent_gviewProduct_lblSelectedProdCode_0">1010068</span>
</td><td>
<span id="MainContent_gviewProduct_lblSelectedProdUOM_0">Ltr</span>
</td><td>
<span id="MainContent_gviewProduct_lblPackSize_0">210.00</span>
</td><td>
<span id="MainContent_gviewProduct_lblRSP_0">222.00</span>
</td><td>
<span id="MainContent_gviewProduct_lblBatchPrice_0">220.00</span>
</td><td>
<input name="ctl00$MainContent$gviewProduct$ctl02$txtRequestPrice" type="text" maxlength="10" id="MainContent_gviewProduct_txtRequestPrice_0" oncopy="return false" onpaste="return false" oncut="return false" onkeyup="return checkDec(this);" onkeypress="return funDecNum(event);" style="width:75px;">
<br>
<span id="MainContent_gviewProduct_rextxtRequestPrice_0" style="visibility:hidden;">Provide Valid Requested Price!</span>
</td><td>
<input name="ctl00$MainContent$gviewProduct$ctl02$txtRequestQty" type="text" maxlength="5" id="MainContent_gviewProduct_txtRequestQty_0" oncopy="return false" onpaste="return false" oncut="return false" onkeyup="return funOnlyNum(this);" onkeypress="return funOnlyNum(event);" style="width:75px;">
<br>
<span id="MainContent_gviewProduct_rextxtRequestQty_0" style="visibility:hidden;">Provide Valid Sale Qty!</span>
</td><td>
<input name="ctl00$MainContent$gviewProduct$ctl02$txtRemark" type="text" maxlength="50" id="MainContent_gviewProduct_txtRemark_0" oncopy="return false" onpaste="return false" oncut="return false" style="width:150px;">
<br>
<span id="MainContent_gviewProduct_rextxtRemark_0" style="visibility:hidden;">Provide proper Remarks</span>
</td>
</tr>
</tbody></table>
i want a code in c# for getting the discounted price. In the screenshot ,under product details we have RSP/MRP. So the requested price that needs to be entered should always be greater then or equal to 50% of RSP/MRP. i am using POM framework. so i need to create a page object for the shown page and apply the logic in the pageobject and call the method from my test class.
While creating automation test cases you should not be creating a method for calculating the discount applied by your application or in fact any other business logic handled by the application.
Instead, you should have separate test cases with boundary values of prices and quantity for which you should know the expected values of discounts that will be applied.
If there is some change later in the logic for giving discount in your application then your test cases should fail as expected and then you will then update the expected result values in your test suite.

ASP.NET C# CSS/Boostrap overlapping

Needed some assistance,
Please look at the picture below, as you can see, When I click the input which has calender, the calender pop up inside the table and it generates a scroll bar which I have to scroll down to see the bottom calender, how do I make sure it is send to front which will show the entire calender outside that table ?
Thanks!
Calender CSS: https://github.com/benitolopez/hotel-datepicker/tree/master/dist
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><i class="fa fa-shopping-cart"></i> Shopping cart</h4>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<td class="text-center"></td>
<td class="text-center">Image</td>
<td class="text-left">Product Name</td>
<td class="text-left">Rental Period</td>
<td class="text-left">Rental Rate</td>
<td class="text-left">Deposit Amount</td>
<td class="text-right">Total</td>
</tr>
</thead>
<tbody>
<tr>
<td class="text-center"><p></p><button type="button" data-toggle="tooltip" title="Remove" class="btn btn-danger" onClick=""><i class="fa fa-times-circle"></i></button></td>
<td class="text-center"><img width="60px" src="image/demo/shop/product/E4.jpg" alt="Xitefun Causal Wear Fancy Shoes" title="Xitefun Causal Wear Fancy Shoes" class="img-thumbnail"></td>
<td class="text-left">Emasa rumas gacem</td>
<td class="text-left"><div class="input-group btn-block" style="min-width: 100px;">
<form method="POST" action="checkout.html">
<input type="text" name="input-id" id="input-id" value="" class="form-control">
</form>
<span class="input-group-btn">
<button type="submit" data-toggle="tooltip" title="Update" class="btn btn-primary"><i class="fa fa-refresh"></i></button>
</span></div></td>
<td class="text-right">$114.35</td>
<td class="text-right">$114.35</td>
<td class="text-right">$114.35</td>
</tr>
</tbody>
<tfoot>
<tr>
<td class="text-right" colspan="1"><strong>Meeting Location:</strong></td>
<td class="text-left" colspan="6">$93.73</td>
</tr>
<tr>
<td class="text-right" colspan="6"><strong>Total Amount Payable:</strong></td>
<td class="text-right">$121.85</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
Update:
I removed the "position" in the css of the calender and it now looks like this.
Everytime the calender pop up, the table will adjust/squeeze to fit the calender, how to make sure that calender just shows without changing the size of the table?
Thanks!

Javascript for a popup. Asp.net for Visual Studio 2005

What JavaScript has to be written for a popup when a link is clicked? Correct me if there is anything else to be done.
Link is written like this.
<div style="float:left; padding-left:9px;">
<asp:LinkButton ID="lnkActiveInactive" runat="server" OnClick="lnkActiveInactive_Click"
CssClass="linkclass" Font-Underline="True">Cancel My Account</asp:LinkButton>
</div>
And popup extender is like this.
<cc1:ConfirmButtonExtender DisplayModalPopupID="ModalPopupExtender2" ID="ConfirmButtonExtender2"
runat="server" TargetControlID="lnkActiveInactive">
</cc1:ConfirmButtonExtender>
<cc1:ModalPopupExtender ID="ModalPopupExtender2" OkControlID="btnYesCancel" CancelControlID="btnNoCancel"
BackgroundCssClass="modalBackground" PopupControlID="pnlCancelPopup" TargetControlID="lnkActiveInactive"
runat="server">
</cc1:ModalPopupExtender>
<asp:Panel CssClass="modalPopup" ID="pnlCancelPopup" runat="server">
<!-- Common Popup Control Begin -->
<table class="tblCommonPopup" width="690px" cellpadding="0" cellspacing="0">
<tr>
<td class="topLeft">
</td>
<td class="topMiddle">
</td>
<td class="topRight">
</td>
</tr>
<tr>
<td colspan="3" class="middle" align="center">
<!-- Content Area Begin -->
<table>
<tr>
<td>
</td>
<td colspan="2" style="padding-top: 10px;">
<table width="100%">
<tr>
<td align="center">
Feel free to change your package to Basic, there is no charge for this Package.<br /><br />If you still wish to cancel,
your account will become inactive within DealTown and any further billing will <br />discontinue.
We will keep you account in our system for some time if you wish to active it again.<br /><br />Are you sure you
wish to cancel your account?
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" colspan="4">
<input id="btnYesCancel" type="button" value="YES" class="popupButton" />
<input id="btnNoCancel" type="button" value="NO" class="popupButton" />
</td>
</tr>
</table>
<!-- Content Area Ends -->
</td>
</tr>
<tr>
<td class="bottomLeft">
</td>
<td class="bottomMiddle">
</td>
<td class="bottomRight">
</td>
</tr>
</table>
<!-- Common Popup Control End -->
</asp:Panel>
Im not sure if I understood your question clearly, but this is how to pop up in JS
<script type="text/javascript">
<!--
function Confirmation() {
var answer = confirm("Are you sure you want to Cancel your Account?")
if (answer){
alert("Goodbye!")
}
else{
alert("Thanks for not Cancelling")
}
}
//-->
</script>
<div style="float:left; padding-left:9px;">
<asp:LinkButton ID="lnkActiveInactive" onclick="Confirmation();">Cancel My Account</asp:LinkButton>
</div>
This code is used is you run on the client side. If you want it to run on server side you have to do it on the codebehind like such
if (!IsPostBack) {
this.lnkActiveInactive.Attributes.Add("onclick", "javascript:Confirmation()");
}
If you just want a confirmation dialog for the 'cancel my account' you can simply place some javascript in your aspx page.
Something like:
onclick="javascript:confirm()"
Hope this helps!
I think the other responders have missed that you are using the ASP.NET Ajax Toolkit ModalPopupExtender.
The answer to your question is, no, no Javascript is required. Setting the TargetControlID of the ModalPopupExtender to your LinkButton should be sufficient to get the pop-up to appear. If that's not happening, something else is wrong.
One thing I notice is that you have an OnClick handler on the LinkButton. This shouldn't be necessary if the only function of the link button is to pop up the dialog.

Yes No Cancel (3 buttons) for AJAX Modalpopupextender

Does Ajax ModalPopupExtender has an option to create 3 buttons? Yes, No and Cancel? for ASP.NET WebForms, C#
I could not come up with a solution. I can just find OKControlID and CancelControlID.
<table id="pnlPopupMerchantUpdate" runat="server" style="display:none">
<tr>
<td>
<asp:Panel runat="server" CssClass="modalPopup">
<table width="350" height="80" class="warningPopup">
<tr>
<td>
<!-- <img src="images/warning_blue.gif" alt="Warning" /> -->
</td>
<td colspan="2" align="left" style="padding-left: 75px; padding-top: 10px;">
Do you wish to update the Location Information as well.
</td>
</tr>
<tr>
<td align="center" colspan="4">
<input id="btnYesMerchant" type="button" value="Yes" class="popupButton" causesvalidation="true" onclick="btnYessave_Click"/>
<input id="btnNoMerchant" type="button" value="No" class="popupButton" causesvalidation="true" onclick="btnNosave_Click" />
<input id="btnCancel" type="button" value="Cancel" class="popupButton"/>
</tr>
</table>
</asp:Panel>
</td>
</tr>
Here, I do want to call different functions for Yes and No.
Instead of OKontrolID, you can use extender's client side API to hide it on button's on-click event. See this article that shows multiple cancel button - your scenario is similar, you just need to return true from your button's onclick event handler.
<ajaxToolkit:ModalPopupExtender runat="server" BehaviorID="myPopup" ...
and
<input id="btnYesMerchant" type="button" onclick="$find('myPopup').hide(); return true;" ...
Thought i found it to be so tough, it is simple to handle this problem. We just got to add return true for each asp button.
ANd remove the OKCOntrolID from ModalPopupExtender. It solved my problem. Thanks all who gave it a try reading.

Categories

Resources