#layer1 {
width: 575px;
height: 400px;
background-color: #E0E0EB;
position: absolute;
top: 36px;
left: 222px;
}
#layer2 {
width: 575px;
height: 400px;
background-color: #E0E0EB;
position: absolute;
top: 36px;
left: 222px;
visibility:hidden;
}
And i have some controls on both of the divs....
<asp:HyperLink ID="HyperLink1" runat="server" onclick="f1();" NavigateUrl="#">Add Personal Details</asp:HyperLink>
<asp:HyperLink ID="HyperLink1" runat="server" onclick="f2();" NavigateUrl="#">Add Personal Details</asp:HyperLink>
On Click Of HyperLink i have following Code...
function f1() {
document.getElementById("layer1").style.visibility = "visible";
document.getElementById("layer2").style.visibility = "hidden";
}
function f2() {
document.getElementById("layer1").style.visibility = "hidden";
document.getElementById("layer2").style.visibility = "visible";
}
And i have a button..
<asp:Button ID="Button5" runat="server" Text="Button" />
Everything works fine when i click on HyperLink but when i CLICK on BUTTON which i hv in div2 due to postback Page Reset occurs and div1 is showing.which is true as per PostBack.But I want div2 only to displayed aftr button click.Can anyone provide me code for that...Please Help...
If you're trying to prevent Button5 from causing postback then add onclientclick="return false;" to the control. Otherwise you can just handle the visibility of your divs in the click event handler. Something like this:
protected void Button5_Click(object sender, EventArgs e)
{
div1.Style["display"] = "block";
div2.Style["display"] = "none";
}
In order to access your divs in codebehind you may need to make them server controls by adding runat="server"
I think you know what happens when there is a postback, Page is reloaded. So, you have to handle the case that when it is postback retain the old value (IsPostback)
Its been a while since I used asp but here goes.
You can store varables in a Viewstate object and check the varable upon loading the program. For example
function f1() {
document.getElementById("layer1").style.visibility = "visible";
document.getElementById("layer2").style.visibility = "hidden";
ViewState("layer") = "1"
}
function f2() {
document.getElementById("layer1").style.visibility = "hidden";
document.getElementById("layer2").style.visibility = "visible";
ViewState("layer") = "2"
}
When you load the page you do something similar to this
String strLayer = ViewState("layer").ToString();
if(strLayer.equals("2"))
f2();
You may find more information here that could help
http://www.dotnetuncle.com/aspnet/75_viewstate.aspx
Hope this helps.
Related
I have a webform that displays an alert box when a searched for item is not found. the alertbox is all asp side, calling it is c# side in codebehind.
the issue is that after the first time it is called, it calls on every postback of the page. after the click it should not fire again until after another missed search.
i have tried if(!ispostback), but the initial firing is a postback, so it won't fire at all.
during the postback it doesn't even call the c# code again, it just shows the alertbox.
<style type="text/css">
.alertBox
{
position: absolute;
top: 100px;
left: 50%;
width: 500px;
margin-left: -250px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
padding: 4px 8px;
}
</style>
<script type="text/javascript">
function closeAlert(e) {
e.preventDefault();
this.parentNode.style.display = "none";
}
</script>
</head>
<body>
<form id="form_rooftopSAQPM" runat="server">
<div runat="server" id="AlertBox" class="alertBox" Visible="false">
<div runat="server" id="AlertBoxMessage"></div>
<button onclick="closeAlert.call(this, event)">Ok</button>
</div>
...
private void site_Load(string siteNumber)
{
DataSet ds = retrieveDataFromSQL("exec s_RooftopSite " + siteNumber, "Couldn't retrieve site information");
if(ds.Tables.Count>0)
{
//load the fields
txtFoo.Text = ds.Tables[0].Rows[0][0].ToString();
}
else
{
MessageBoxShow("Site not found.");
}
}
protected void MessageBoxShow(string message)
{
this.AlertBoxMessage.InnerText = message;
this.AlertBox.Visible = true;
}
...
how can i set the alertbox to only fire when it is called by the c# code, yet still allow it to pop off on the first call, which is a postback?
I fixed it by switching from JavaScript to C#:
ASP:
<asp:Button runat="server" id="btnCloseAlert"
onclick="btnCloseAlert_Click" Text="Ok" />
CodeBehind in C#:
protected void btnCloseAlert_Click(object sender, EventArgs e)
{
AlertBox.Visible = false;
AlertBoxMessage.InnerText = "";
}
Hello guys i have a problem with iframe. I want to play video in asp.net and i used iframe.
<iframe runat="server" id="videoPlayer" onended="handlerEnd" style="align-content: center; position:absolute; border:0; top:0; left:0; right:0; bottom:0; width:100%; height:100%" src="http://www.w3schools.com/html/mov_bbb.mp4" frameborder="0" allowfullscreen></iframe>
I want to use onended event from iframe to use in aspx.cs file.
How to get it ?
Put a hidden field to your page and set it's value to 0.
Set event handler to onended event, when it fires, set value 1 to hidden field and do postback.
On Page_Load event check if hidden field contains 1.
Aspx file
<asp:HiddenField runat="server" ID="videoEndedFlag" />
<iframe onended="raiseVideoEnded" />
function raiseVideoEnded()
{
var field = document.getElementById('<%=videoEndedFlag.ClientID%>');
field.value = '1';
// do postback
window.location.reload(true);
// or window.location.href = window.location.href;
// or __doPostBack('','');
}
Aspx.cs file
protected void Page_Load()
{
if(IsPostBack)
{
if(videoEndedFlag.Value == "1")
{
// video ended
}
}
}
i have following code in cs file
QueMAnsM[] Answers = Curr.AnsM;
rdbAns.DataSource = Answers;
rdbAns.DataTextField = "Answer";
rdbAns.DataValueField = "AnsId";
rdbAns.DataBind();
rdbAns.TextAlign = TextAlign.Right;
where rdbAns is asp:radiobuttonlist control
i have set TextAlign property to right (This code is at page load)
but text is still showing at left side
what is wrong with this code
Set the TextAlign property to "Right" on the list .
<asp:RadioButtonList id="RadioButtonList1"
RepeatDirection="Vertical"
RepeatLayout="Table"
TextAlign="Right"
runat="server">
OR, In code behind :
RadioButtonList1.TextAlign = TextAlign.Right;
OR, Perhaps you can use some css.
Give your list a CssClass="rbListWrap" and add following style:
.rbListWrap {
width: 500px;
}
.rbListWrap tr td {
height:20px;
vertical-align: middle;
padding: 5px;
width: 33%;
}
.rbListWrap input {
float:right;
}
.rbListWrap label {
position: relative;
padding-left:20px;
}
Set CheckAlign Property to MiddleLeft if you want to move the text of the radio button to the left. You can move it to other positions if you want to.
I have a issue with Jquery Modal dialog being called from a button inside an update panel..
here are the insights..
Javascript used for opening a Jquery modal dialog in aspx page..
<script type='text/javascript'>
function openModalDiv(divname) {
$('#' + divname).dialog({
autoOpen: false,
bgiframe: true,
closeOnEscape: true,
modal: true,
resizable: false,
height: 'auto',
buttons: { Ok: function () { closeModalDiv(divname) } },
open: function (event, ui) { jQuery('.ui-dialog-titlebar-close').hide(); }
});
$('#' + divname).dialog('open');
('#' + divname).parent().appendTo($('form:FrmSearch'));
$('#' + divname).css('overflow', 'hidden')
}
function closeModalDiv(divname) {
$('#' + divname).dialog('close');
}
</script>
the button in aspx page..
<asp:UpdatePanel ID="upDialogs" runat="server">
<ContentTemplate>
<asp:Button ID="btnOpenDialog" runat="server" Text="Open Dialog" onclick="btnOpenDialog_Click" />
</ContentTemplate>
</asp:UpdatePanel>
The Div which needs to be called from code behind via javascript..
<div id="ErrorDiv2" title="Error" style="visibility:hidden">
<p><span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>Please select an option among the results and try again!</p>
</div>
Finally the code behind ..
protected void btnOpenDialog_Click(object sender, EventArgs e)
{
if (ProfileID == null)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorDivOpen", "document.getElementById('ErrorDiv2').style.visibility = 'visible';", true);
Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorDivShow", "openModalDiv('ErrorDiv2');", true);
}
}
Now the Issue in detail..
Without the update panel the modal dialog pops very fine but makes full post back..
I want to have only a partial post back and hence am using a update panel..
The following are the solutions I have tried..
Added update panel to the existing div, dint work.
added an update panel along with runat="Server" for the div, still dint work..
Can any one help me with possible solutions?
Thanks for your quick reply but I found another solution.
I added both update panel and runat parameters to the Div.
<asp:UpdatePanel ID="upErrorDiv" runat="server"><ContentTemplate>
<div runat="server" id="ErrorDiv2" title="Error" style="visibility:hidden">
<p><span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>Please select an option among the results and try again!</p>
</div>
</ContentTemplate></asp:UpdatePanel>
Changed the code behind as.
if (ProfileID == null)
{
ScriptManager.RegisterStartupScript(ErrorDiv2,this.GetType(), "ErrorDivOpen", "document.getElementById('ErrorDiv2').style.visibility = 'visible';", true);
ScriptManager.RegisterStartupScript(ErrorDiv2,this.GetType(), "ErrorDivShow", "openModalDiv('ErrorDiv2');", true);
return;
}
Could you try injecting the javascript into a Literal control inside UpdatePanel, istead registering it with ClientScriptManager ?
Kris
I'm handling the onSelectIndexChanged event. An event is raised when the DropDownList selection changes. the problem is that the DropDownList still returns the old values for SelectedValue and SelectedIndex. What am I doing wrong?
Here is the DropDownList definition from the aspx file:
<div style="margin: 0px; padding: 0px 1em 0px 0px;">
<span style="margin: 0px; padding: 0px; vertical-align: top;">Route:</span>
<asp:DropDownList id="Select1" runat="server" onselectedindexchanged="index_changed" AutoPostBack="true">
</asp:DropDownList>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</div>
Here is the DropDownList OnSelectedIndexChanged event handler:
protected void index_changed(object sender, EventArgs e)
{
decimal d = Convert.ToDecimal( Select1.SelectedValue );
Literal1.Text = d.ToString();
}
Do you have any code in page load that is by chance re-defaulting the value to the first value?
When the page reloads do you see the new value?
If you are using AJAX you may also be doing a callback, not a full postback. In that case you may want to use this in your page load method:
if (!IsCallback && !IsPostBack)
{
// Do your page setup here
}
add this:
if page.isnotpostback {
}
around your code to bind the dropdownlist.
This may seem obvious, but anyway.
Do you initialize this dropdown with an initial value in some other event handler like OnLoad ?
If so you should check if that event is risen by a postback or by the first load. So you should have something like
if(!IsPostback) d.SelectedValue = "Default"
Is it possible that you have items copied throughout your datasource for the drop down list?