<asp:Button runat="server" ID="hiddenPopupPatientRegistration" Style="display: none" />
<asp:ModalPopupExtender ID="popupPatientRegistration" runat="server" PopupControlID="panelPatientRegistration"
TargetControlID="hiddenPopupPatientRegistration" BackgroundCssClass="cssmodalbackground"
BehaviorID="modalBehaviour" CancelControlID="btnClose">
</asp:ModalPopupExtender>
<div id="panelPatientRegistration" class="cssmodalpopup" style="display: none">
<iframe id="iframePatientRegistration" class="csstable" runat="server" width="600px"
height="485px" scrolling="auto"></iframe>
<table>
<tr>
<td align="right">
<asp:Button ID="btnClose" runat="server" CssClass="cssbutton" Text="Close" />
</td>
</tr>
</table>
</div>
protected void btn_Click(object sender, EventArgs e)
{
iframePatientRegistration.Attributes["src"] = "Patient_Registration.aspx?flowType=" + flowType + "&fromTime=" + hidFromTime.Value + "&toTime=" + hidToTime.Value + "&acqModalityID=" + hidAcqModalityID.Value + "&schLocationID=" + ddlScheduledProcedureStepLocation.SelectedValue;
popupPatientRegistration.Show();
}
I have to show aspx page in modal popup extender control.
And pass values through query string
BUT ASPX page not loads in Iframe.code behind.
when i see html source then getting these two lines
<HTML>
</HTML>
the display property for the containing Div "panelPatientRegistration" is set to none. The iframe is inside that and it never gets rendered.
Collect all your Querystring data and save them in hidden fields and write javascript function where change the src of the Iframe by passing the values as querystrings using Hidden fields.
<script>
function changeIframSrc(src) {
document.getElementById('<%=iframePatientRegistration.ClientID %>').src = src;
}
</script>
the problem i saw in the code is you are clicking a server side button where the page is getting posted back and even though you are changing the src of the iframe but controls are getting created again due to the postback. so use the javascript function above to call that particular page and pass the querystrings using the hidden fields solve the issue.
Related
I have two textboxes, txtA and txtB, both are never shown on the display simultaneously, and in code behind when i am applying the condition to check the visibility of textbox, its coming to be true when the textbox is don't even created.
ASPX Code:
<%if(CurrentOrderItem.MasterModelName.ToLower().Contains("string1"))
{ %>
<div class="CustomerName clearfix ">
<div class="txtInput width464">
<asp:TextBox ID="txtA" runat="server" MaxLength="12" />
</div>
</div>
<%} %>
<%if (CurrentOrderItem.MasterModelName.ToLower().Contains("string2"))
{ %>
<div class="txtInput width464">
<asp:TextBox ID="txtB" runat="server" MaxLength="20" autocomplete="off"/>
</div>
</div>
<%} %>
And when i check into the codebehind visibility of the not created textbox is shown as true.
Note that, the server side code embedded in the aspx page will be excecuted during the Render phase. Which means all your controls are created and initialized with the values. So in all the events before Render, you get each control available in the codebehind with the data.
http://msdn.microsoft.com/en-us/library/vstudio/0e39s2ck(v=vs.100).aspx
Also as mentioned in the article, it is not good practice to embed server side code in the ASPX page, because it leads to difficult in maintainance and un expected result.
What you can do instead is that, in the code behind, in the page load you can check the values and make your controls visible or hidden
when i am applying the condition to check the visibility of textbox,
its coming to be true when the textbox is don't even created.
TextBox's Visible will always be true. Althought it is not visible in the browser, its information is stored ViewState.
Other thought
Placing the c# code in ASPX page is fragile and hard to maintain.
Instead, you can easily achieve the same result using Panel control which renders as html div tag.
<asp:Panel ID="APanel" runat="server" CssClass="CustomerName clearfix">
<div class="txtInput width464">
<asp:TextBox ID="txtA" runat="server" MaxLength="12" />
</div>
</asp:Panel>
<asp:Panel ID="BPanel" runat="server" CssClass="CustomerName clearfix">
<div class="txtInput width464">
<asp:TextBox ID="txtB" runat="server" MaxLength="20" autocomplete="off"/>
</div>
</asp:Panel>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (CurrentOrderItem.MasterModelName.ToLower().Contains("string1"))
{
APanel.Visible = true;
BPanel.Visible = false;
}
else
{
APanel.Visible = false;
BPanel.Visible = true;
}
}
}
In this approach, you can check Panel's Visible instead of TextBox.
I have been researching this, but haven't been able to find anything so far.
Currently, I am using a Javascript alert box on my ASP page:
public static class Alert
{
public static void Show(string message)
{
string script = "<script type=\"text/javascript\">alert('" + message + "');</script>";
Page page = HttpContext.Current.CurrentHandler as Page;
if (!page.ClientScript.IsStartupScriptRegistered("alert"))
{
page.ClientScript.RegisterStartupScript(typeof(Alert), "alert", script);
}
}
}
I am able to call this from code behind by: Alert.Show("Text");
My plan is to replace the Javascript alert by utilizing the AjaxControlToolkit's ModalPopupExtender. I am creating a user control that looks something like this:
<ajax:ModalPopupExtender ID="mpAlert" runat="server" PopupControlID=""
TargetControlID="btnExport" OkControlID="btnOK">
</ajax:ModalPopupExtender>
<asp:Panel ID="pnlSteps" runat="server" BackColor="#C5D9FC" Width="10%"
BorderColor="#093E9A" BorderStyle="Double" BorderWidth="5px"
style="border-radius: 10px; padding: 5px;">
<div>
<asp:Literal ID="lSteps" runat="server" />
</div>
<div>
<input id="btnOK" type="button" value="OK" />
</div>
</asp:Panel>
I am wondering if there is a way I can create a static method to show this from codebehind, similar to how I used the Javascript alert. I'd like to be able to wrap this in a class so I could just call AjaxAlert.Show(), without having to call anything in the aspx file.
This is still a rough idea, so if any more details are needed, just let me know.
You can show the ModalPopupExtender from codebehind. Therefore you need an invisible trigger button.
mpAlert.Show();
So set the TargetControlID of the ModalPopupExtender to a hidden button:
<asp:Button ID="Hid_ShowDialog" Style="display: none" runat="server" />
I am trying to post a form in codebehind and show the response in Iframe. Following code is opening another browser window with target url but now showing in Iframe.
This is my Aspx code:
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button1" onclick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Button2" onclick="Button2_Click1" />
</div>
</form>
<iframe name="iframe1" id="iframe1" frameborder="0" height="450px" width="100%" style="overflow:hidden;" scrolling="yes">
</iframe>
</body>
On Button1 click I try to post a form with following code. Everything works fine but new browser window open instead of opening it in Iframe.
protected void Button1_Click(object sender, EventArgs e)
{
System.Web.HttpContext.Current.Response.Write("<form id='ssoForm' name='ssoForm' method=post action='" + formAction + "' target='iframe1'>");
System.Web.HttpContext.Current.Response.Write("<input type='hidden' name='TARGET' value='" + formTarget + "' />");
System.Web.HttpContext.Current.Response.Write("<input type='hidden' name='Encoding' value='B64' />");
System.Web.HttpContext.Current.Response.Write("<input type='hidden' name='SAMLResponse' value='" + resp + "' />");
System.Web.HttpContext.Current.Response.Write("</form>");
Response.Write("<SCRIPT LANGUAGE='JavaScript'> document.forms['ssoForm'].submit();</SCRIPT>");
}
You could try setting the target attribute of the FORM tag to the name of your iFrame. I believe this should work per the HTML spec, but I don't know if ASP.NET will honor it.
Alternatively, you could place the actual ASP.NET form in the iFrame, and have the parent page use JavaScript to set the values inside of the iFrame and submit the form within the iFrame.
I have a lengthy asp.net page. An HTML table in the page has a link with <a>. when the link is clicked the page shows the textbox using javascript and takes me to the top part of the page. Instead, i want to see the part of the page that has the link and textbox. It should automatically scroll down to that part once the page refreshes. How is that possible?
I have tried using Linkbutton instead of but have issues with javascript.
Here is the code.
<script type="text/javascript">
$(document).ready(
function()
{
$("#aChangeDefault").click
(
function()
{
alert('hi');
//$("#<%=trChangeLoc.ClientID %>").fadeIn(1000);
$("#<%=rowChangeLoc.ClientID %>").fadeIn(1000);
}
)
$("#btnClose").click
(
function()
{
$("#<%=rowChangeLoc.ClientID %>").fadeOut(1000);
if(document.getElementById("<%=divSearchResult.ClientID %>").style.display != "none")
{
$("#<%=divSearchResult.ClientID %>").fadeOut(1000);
}
//$("#<%=trChangeLoc.ClientID %>").fadeOut(10);
}
)
}
);
The Linkbutton is here :
<asp:LinkButton id="aChangeDefault" runat="server" style="font-size: 12px;font-family:Arial;vertical-align:bottom;" ToolTip = "Click here to set your town as default location" Text ="Change Location" > </asp:LinkButton>
And the portion that shows up when the link is clicked is here:
<input id="btnClose" type="button" class="closeButton2" language="javascript" onclick="return btnClose_onclick()" />
<div style="display: inline-block;">
<span class="searchheadder" style="color: #000000; padding-right: 8px; padding-top: 4px;">
LOCATION: </span>
<asp:TextBox ID="txtChangedLocation" onkeyup="doCapitalize();" runat="server" Height="19px"
Width="200px" CssClass="textBox" Style="margin-right: 10px;"></asp:TextBox>
<cc1:AutoCompleteExtender ID="ACE1" runat="server" TargetControlID="txtChangedLocation" ServicePath="../AutoComplete.asmx" ServiceMethod="GetCompletionList" MinimumPrefixLength="2" CompletionSetCount="10" EnableCaching="true" CompletionInterval="0" ></cc1:AutoCompleteExtender>
<asp:Button ID="btnGetNewList" BorderWidth="0" CssClass="searchButton" runat="server" OnClick="btnGetNewList_Click" /> </div>
Appreciate all your help. Thank you!
MaintainScrollPositionOnPostBack only affects the position of the page in your browser when a PostBack occurs, and if you're using JavaScript you don't want a PostBack to happen. If you're doing everything in JavaScript, it sounds like the problem is that when you click a link, the browser's default behavior is to follow the link, even if it's to a location on the same page. In some browsers, for the click event to register on an <a> tag, the href property must have a value, so it's common practice to use a blank anchor name as the href:
<a onClick="MyJavaScriptFunction()" href="#">Click here</a>
What this is actually telling the browser to do is to call your function MyJavaScriptFunction() and unless that function evaluates to false, it will then follow the anchor to the top of the page, which is where href="#" takes you. You can either finish your onClick with return false; or else change your JavaScript function to always return false, either way it will keep the browser from following the link:
<a onClick="MyJavaScriptFunction();return false;" href="#">Click here</a>
I'm not sure I understand what you're trying to do, but if the page is reloading perhaps you can use a named anchor to have the browser go to the section of the page you want automatically.
In my ASP.NET main page I have one hidden field and and one button. When the user clicks the button I am showing the pop up (child page). I need to access a Hidden field while the pop up is loading. How could I access the Hidden field using c#?
Well, you can pass the value of the hidden field to the query string of the pop up. Something like this:
<asp:button id="ButtonInMainPage" runat="server" onclick="Popup();return false;" />
<asp:hidden id="hiddenValue" runat="server" />
<script type="text/javascript">
function Popup()
{
window.open('Child.aspx?hiddenValue='+document.getElementById('<%=hiddenValue.ClientID%>').value);
}
In child page_load:
string hiddenValue = Request.QueryString["hiddenValue"];
What I show is simple code, you must add necessary check or other according to your project.
This is your question:
In main page, there is a gridview, which contains a checkbox column, when a checkbox of a row is selected, add the corresponding ID to a hidden field. When user clicks the popup button, a window will be opened and the selected IDs will be passed to the new window. The question is the IDs are too long to pass in the query string.
My solution:
I think you can remove the hidden field, and remove all client scripts of your popup button.
<asp:button id="PopupButton" runat="server" Text="Click to pop up" />
Add a server event of the button, like:
void PopupButton_Onclick(object sender, EventArgs e)
{
string IDs = CollectTheSelectedIDsInTheGridView();
Session["IDs"] = IDs;
string js = #"<script type='text/javascript'>
window.open('Child.aspx');
</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(),"showChild",js);
}
EDIT
Your data list must look like this:
<table>
<asp:Repeater ID="myData" runat="server">
<ItemTemplate>
<tr>
<td><asp:CheckBox ID="selectedFlag" runat="server" Checked=<%# Eval("Checked") %> /></td>
<td><asp:Label ID="dataText" runat="server" Text=<%# Eval("TextData") %>></asp:Label></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>