asp.net bootstrap alert data from database - c#

Need help on bootstrap alert function,below is my code that use to popup alert.
<div id="asd" runat="server">
<div class="alert alert-danger" id="success-alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong> Pending Approval-HR(Please approve now)</strong> Click to redirect
</div>
</div>
The alert text i want get from Database as well as url.The total alert will popup is depend on total data from database.

Your question is not much clear. Use ajax alert may fix your problem
string message = "alert('Hello! Mudassar.')";
ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);

Use Session variable Or Label and set value from database .
<div id="asd" runat="server">
<div class="alert alert-danger" id="success-alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong> Pending Approval-HR(Please approve now)</strong> <asp:Label ID="lbl_text" Text=""/>
</div>
</div>

Related

Selenium cannot find Cookie Accept button

Does anybody have any ideas why Selenium cannot find the Cookie Accept button defined below. I have tried a number of methods and wait strategies but nothing seems to work? When the Cookie banner comes up the main window behind greys out. URL: https://portal.everybody.org.uk/lhweb/identity/login?
HTML
<div class="xn-auth-form xn-login-form">
<div id="IJFIX74FEMS85U04VNHN9XD1G6T36PB6" class="xn-component" style=""><xn-cookiebanner-component params="{"newcomponent":"true"}">
<div data-bind="css: { 'xn-modal': isModal, 'xn-visible': isVisible}" class="xn-modal xn-visible">
<div class="xn-cookie-banner-header">
<div class="xn-cookie-banner-name">
<div class="xn-cookie-banner-title">Cookies Policy</div>
<div class="xn-name" style="word-break:keep-all">
<span> Cookies created and stored for this site are fundamental to its functionality and performance. Cookies are not used for marketing purposes, nor are any personally identifiable cookies stored.</span>
</div>
</div>
<div class="xn-buttons">
<button class="xn-button xn-cta" data-bind="click: confirm"><span data-bind="text: confirmationYes">Accept</span></button>
</div>
</div>
</div></xn-cookiebanner-component></div>
<form name="form" method="post" action="/lhweb/identity/login?signin=d367e21d0f8af2faf156cb566b51b78a" novalidate="novalidate">
<input type="hidden" name="idsrv.xsrf" value="GgTgFinGkFku2cMRPEcwMy9qv4fh3dUGJV26u-jv6Os0VF-1gFmP_JNHPRRz_lywbkTZ4XAaUs5atoqRHKu56gAHU_lfv-ZZplq476ZcpfQ" autocomplete="off">
C#
IWebElement button1 = driver.FindElement(By.XPath("/html/body/div[3]/div/div/div/xn-cookiebanner-component/div/div/div[2]/button"));
IWebElement button2 = driver.FindElement(By.Name("Accept"));
You can use the below locators:
XPATH:
.//*[#class='xn-button xn-cta' and #data-bind='click: confirm']
CSS SELECTOR:
.xn-cookie-banner-header .xn-button.xn-cta

Not able to access input text box value to code behind asp.net c#

Here my page :
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<%# Register Assembly="Microsoft.ReportViewer.WebForms" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:HiddenField ID="hdnfromDate" Value="" runat="server" />
<asp:HiddenField ID="hdntoDate" Value="" runat="server" />
<div id="myModal1" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Issue Invoice</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form id="reused_form" runat="server">
<p>
Send invoice to...
</p>
<div class="form-group">
<label for="name">
To:</label>
<input type="text" class="form-control"
id="name" name="name" readonly maxlength="50" runat="server">
</div>
<div class="form-group">
<label for="email">
CC:</label>
<input type="email" ID="cc" class="form-control" runat="server" multiple>
</div>
<div class="form-group">
<strong><i>Note:</i><small>&nbsp<i>The invoice can not be edited after issuing.</i></small></strong>
</div>
<asp:LinkButton CssClass="btn btn-warning m-btn btn-block btn-lg m-btn--custom m-btn--icon m-btn--air " OnClick="Onbtn3_Click" Text="Issue Invoice " ID="LinkButton3" runat="server"></asp:LinkButton>
</form>
<div id="success_message" style="width: 100%; height: 100%; display: none;">
<h3>Sent your message successfully!</h3>
</div>
<div id="error_message"
style="width: 100%; height: 100%; display: none;">
<h3>Error</h3>
Sorry there was an error sending your form.
</div>
</div>
</div>
</div>
</div>
In cs File i am trying to access email value using cc.Value as for email textbox id is cc. But it always gets empty string. In my default master page i have a form tag which runs at server so if i keep this modal in a form runat server then gives me error saying page can have only one form tag. Please can anyone help me out. Thanks in advance
This may help
There is Text property available, so you can use textBox.Text to get textbox contian. In your case cc.Text.
Try textBox.text(). Should work.
As Html 5 type=“email” control is not available using runat attribute, you can access TextBox like below:
<asp:TextBox ID="txtBoxCc" runat="server" TextMode="Email"></asp:TextBox>
Now in codebehind you can access it like txtBoxCc.Text
Also, you have to put it like below:
if(!Page.IsPostBack) {
string cc = txtBoxCc.Text;
}

How to open a modal from code behind?

I am trying to open a modal on a button click. Modal can be opened using a button click
<asp:Button ID="Button4" runat="server" class="btn btn-info" data-toggle="modal" OnClientClick="return false;" data-target="#View1" Text="View Details" />
I need to open this modal at the end of a function, but I don't know how to make that happen, from c# code behind. I tried:
protected void Button2_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "ModalView", "<script>$('#View1').modal('show');</script>", false);
}
Design
<!-- modal 1 -->
<div class="modal fade" id="View1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" runat="server">
<div class="modal-dialog">
<div class="modal-content">
<div class="alert alert-success">
<strong>Well done!</strong> Successfully Saved
</div>
</div>
<!-- modal-content -->
</div>
<!-- modal-dialog -->
</div>
<!-- modal -->
First of all please make sure ScriptManager is placed in form tag of aspx page.
secondly make sure the code is working on client side.
Refer my below code:
aspx code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:ScriptManager runat="server"></asp:ScriptManager>
</form>
</body>
serverside code:
protected void Button1_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(#"<script language='javascript'>");
sb.Append(#"$('#myModal').modal('show');");
sb.Append(#"</script>");
ClientScript.RegisterStartupScript(this.GetType(), "JSScript", sb.ToString());
}
I would guess that your script is running before the HTML it's trying to refer to is actually rendered. You can check it easily by doing a View Source on your rendered page. If that startup script is higher up the page than your HTML for your modal, then it won't work because the script runs as soon as it's rendered on the page, and it's before the HTML is rendered, so it tries to run "show" on an element that doesn't exist yet. You don't get an error because the way jQuery works means that if its selector doesn't match any element(s), it simply doesn't execute whatever command you specified to be run on the selected element(s).
If this is the issue, you can fix it easily by changing your startup script so that it doesn't run the "show" code until the whole page has loaded. This can be done using jQuery's standard "document.ready" syntax (I have used the shorthand version here):
ScriptManager.RegisterStartupScript(this, this.GetType(), "ModalView", "<script>$(function() { $('#View1').modal('show'); });</script>", false);
You also need to ensure you've got a ScriptManager control in your page somewhere (within the <form> tag):
<asp:ScriptManager runat="server"></asp:ScriptManager>
There can be two problems:
You are trying to load the model before page loads
Your id of modal is different
Change view1 to div1
Please try this code
ScriptManager.RegisterStartupScript(this, this.GetType(), "ModalView", "
<script>$(document).ready(function(){$('#Div1').modal('sho‌​w');});</script>", false);

Empty password field on an asp:login form using a LayoutTemplate

I have an asp:login control on an .aspx page. I'm using a LayoutTemplate. When a user enters a wrong username or password, on postback, the password field appears to be filled. So if the user only changes the username and try to log in again, it returns an error. Debugging I've seen that the password is empty.
I've tested the same behavior using the default asp:login, without LayoutTemplate, and it works well. It means that after entering a wrong username or password, on postback, the password field appears empty.
How can I make it work?
EDIT:
This is the code I use. When something is wrong and postback occurs, password field appears filled. If the user clicks again to login, on debug mode, I see that the password is empty.
<asp:Login ID="lgLogin" runat="server"
FailureText="Wrong data"
TextLayout="TextOnLeft"
OnAuthenticate="lgLogin_Authenticate"
DestinationPageUrl="http://www.blablabla.com/"
OnLoginError="lgLogin_Error"
RenderOuterTable="false"
DisplayRememberMe="False">
<LayoutTemplate>
<div class="form-group">
<label for="lgLogin_UserName" class="col-md-4 control-label">Login <span class="require">*</span></label>
<div class="col-md-8">
<div class="input-icon">
<i class="fa fa-user"></i>
<asp:TextBox runat="server" type="text" ID="UserName" CssClass="form-control" />
</div>
</div>
</div>
<div class="form-group">
<label for="lgLogin_Password" class="col-md-4 control-label">Password <span class="require">*</span></label>
<div class="col-md-8">
<div class="input-icon">
<i class="fa fa-lock"></i>
<asp:TextBox runat="server" type="password" ID="Password" CssClass="form-control" />
</div>
</div>
</div>
<div id="AvisoError" runat="server" class="alert alert-danger" visible="false">
<button class="close" data-close="alert"></button>
<span>
<asp:Label ID="FailureText" runat="server" ></asp:Label>
</span>
</div>
<div class="form-group">
<div class="col-md-offset-4 col-md-8">
<asp:Button class="btn btn-primary" ID="LoginButton" runat="server" CommandName="Login" Text="Entrar" />
</div>
</div>
</LayoutTemplate>
<TextBoxStyle CssClass="form-control"/>
<LoginButtonStyle CssClass="btn btn-primary" />
If I use the default asp:login, if something goes wrong and postback occurs, password appears empty.
<asp:Login ID="lgLogin" runat="server"
FailureText="Wrong data"
TextLayout="TextOnLeft"
OnAuthenticate="lgLogin_Authenticate"
DestinationPageUrl="http://www.blablabla.com/"
RenderOuterTable="false"
DisplayRememberMe="False">
Obviously, you have set the textbox or input id to password field and it will go off when a postback occurs. Good practices are to leave it as it is and let user enter it one more time because there is a reason why this functionality has been there, and even if you want to push it anyhow then.
Firstly set your autocomplete property for the form to off. Then at page_load, store the password textbox value to some temp variable and then push that temp variable value to textbox. For more security, you can store that password field value to session and then encrypt it with base64 and then use it.
You need to add an attribute at the to retain the state of the controls after postback
Change type of field on load page event completed, works for me:
$(document).ready(function () {
document.getElementById("textBoxSenha").type = "password";
});

keep dialog box(?) open after clicking submit button

<ul class="nav pull-right">
<li class="active">HOME</li>
<li>FEATURES</li>
<li>CHECK E-MAIL</li>
<li>TESTIMONIALS</li>
<li>CONTACT</li>
<li>Sign Up</li>
</ul>
<div id="Signup" class="modal hide fade LoginSignup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel2">Sign Up</h3>
</div>
<div class="modal-body">
<p>#alert</p>
<form method="POST" action="" name="signupform">
<input type="text" placeholder="First Name" name="firstname">
<input type="text" placeholder="Last Name" name="lastname">
<input type="text" placeholder="E-mail" name="email">
<input type="password" placeholder="Password" name="password">
<input type="password" placeholder="Confirm Password" name="password1">
<input type="submit" name="signup" value="Sign Up" />
<label>By registering you are automatically agreeing to our Terms of Service</label>
</form>
</div>
</div>
this is from a html5 template that i downloaded somewhere, when i click sign up in the menu (the first code i posted) it opens some kind of dialog box(?) i fill the textboxes just fine and when i click submit it registers just fine and i wanted to keep that dialog box(?) open so i can show a message through the variable alert that says you registered successfully blabla.
i can get everything working including the alert but i cant keep the signup dialog open after submitting so i have to click signup on the menu again to see the alert message.
That looks like bootstrap to me. First things first, you have to change the submit button in the pop-up to something like:
<span class="btn btn-primary" onclick="submitform()">Submit</span>
Then you have to create the javascript function called "submitform" to submit the signup form data to a webservice or whatever backend you have, read back the response and display the response in the popup itself.

Categories

Resources