Controlling one page controls on other page - c#

I have been working on a project and i got stucked on in a problem as i have a popup on a page student.aspx and the popup get visible onpageload and i have another page as email.aspx and also email page do contain the button,what i want is when i click on a button the popup should get invisible.
i got a solution as
if (Page.PreviousPage != null){
TextBox SourceTextBox =
(TextBox)Page.PreviousPage.FindControl("TextBox1");
if (SourceTextBox != null)
{
Label1.Text = SourceTextBox.Text;
}}
how to implement it with modalpopupextender

Related

Stay on the current page after refresh using iFrame asp.net

I am using 'iFrame' on the website, and right now, whenever I directed to the another page (says Register Page) and I click F5 (Refresh button on the browser), it will go to the Default.aspx and not Register Page. I notice that while I directed to the Register Page or another Page, the url stays on: www.something.com/Default.aspx, but it should be www.something.com/Register.aspx. I think the cause for it cannot go back to the current page is because of the URL linked to the Default.aspx.
ID for Main Frame is MainFrame and here is the code:
if (Session["AFFM_RoleCode"] != null && Session["AFFM_RoleCode"].ToString() == "0")
{
// If the user is not logged in
if (Session["IsAgent"] != null && Session["IsAgent"].ToString() == "1")
{
mainFrame.Attributes["src"] = "BlankPage.aspx";
}
else
{
mainFrame.Attributes["src"] = "Main.aspx";
}
}
How do I can solve this problem?
Your answer much appreciated!
Thanks
This is a quick patch you can do to this, add a session to your register page when it load, such as
session["Load"] = "register";
and when the page is refreshed, if you find register in the load session, redirect it to the register
if (session["load"] == "register"){
session["load"] = "";
//you redirect code
}

Rebind grid view in previous popup window from the current popup window using session ASP.net c#

I am working on a project in which I get a dataset and assign this to a session in the newly opened popup window. Now I need to rebind the grid view of the previous popup window using this updated session from the newly opened popup window. How can I implement this.
Details in Elaborate:
First Popup window (previous): model.htm inner binds attendee.aspx (in which grdAttendees exists)
New pop up: (display.aspx) genertated in button click from attendee.aspx
Referring to some samples i tried this but didn't work.
GridView grv = new GridView();
grv = ((GridView)this.Page.PreviousPage.FindControl("grdAttendees"));
grv.DataSource = "";
if (Session["map_hcp"] != null)
{
DataSet ds = (DataSet)Session["map_hcp"];
grv.DataSource = ds;
}
Any better idea to implement this?
you can use javscript for this
PARENT WINDOW:
function jsparentfunction()
{
alert('youve successfully calledme');
}
CHILD WINDOW
function executethischildjsfunction()
{
window.opener.jsparentfunction();
window.close();
}

Enter Does Not Work For Submit, ASP.NET Page Refreshes and Doesn't Search

I am working with an ASP.NET site with a C# back end. There is a .Master page where the tag is, and other search pages on the site will search when you hit enter after filling out the form. However we have one page that has a few text boxes and when you hit enter to search, it appears to just refresh and reload the page without searching. In order to search you have to hit the search button (which is an igtxt:WebImageButton ). All of the solutions I have found to this issue so far involve people using javascript to call some kind of function on submit. As far as I know there is no javascript being called when you hit the search button, it is all in the C# code. Once again I find myself searching SO and other sites for an answer but none of the solutions seem to fit my situation. The form tag is as follows:
<form id="form1" runat="server">
The web image buttons call a btn_SearchClick function that runs the search code. But since the form is started in the .Master file I can't edit that as it would effect all other pages as well. Is there any way to have enter call the btn_SearchClick from the form without having to put it in the form tag? I'm not sure what would've changed to cause this behavior on one page and none of the others.
if (!IsPostBack)
{
TextBox1.Attributes.Add("onKeyPress",
"doClick('" + btnSearch.ClientID + "',event)");
}
<SCRIPT type=text/javascript>
function doClick(buttonName,e)
{
//the purpose of this function is to allow the enter key to
//point to the correct button to click.
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
if (key == 13)
{
//Get the button the user wants to have clicked
var btn = document.getElementById(buttonName);
if (btn != null)
{ //If we find the button click it
btn.click();
event.keyCode = 0
}
}
}
</SCRIPT>
or u can use default button.it's work while cursor's in this box
protected void Page_Load(object sender, EventArgs e)
{
this.Form.DefaultButton = this.btnSubmit.UniqueID;
}
Add some jquery to control the Enter key behavior on your textbox. Something like this:
$(function() {
$('#<%=txtTextbox.ClientID%>').keypress(function (e) {
if (e.which == 13) {
e.preventDefault();
$('#<%=btn_SearchClick.ClientID%>').click();
}
});
});

How to use an ajax modal popup and consume a value from a link?

I've read a few articles regarding getting values back from a modal popup in an ASP .NET page, but they all seem to use JavaScript to accomplish this which isn't really want I want to do if possible.
I have a web user control which has a repeater that I populate from a list into a table. Each row has a link button which has a redirect url with a value as a query string.
Then I have another web user control which is just a link button with a panel and the repeater web user control that once clicked shows the actual modal popup.
Is it possible to get a value from the web user control once the link button on the repeater is clicked without having to redirect to the same page? I basically want to click on the link, show the modal and once closed, want to access the value.
I'm populating the repeater with the links as follows:
string linkUrl = "";
string action = "";
if (Request.QueryString["action"] != null)
{
action = Request.QueryString["action"];
switch (action)
{
case "SetupCompany":
{
linkUrl = "<a href=CreateCompanies.aspx?companyId=";
break;
}
case "ViewCompany":
{
linkUrl = "<a href=ViewCompany.aspx?companyId=";
break;
}
}
}
CompaniesBusinessManager mgr = new CompaniesBusinessManager();
var companies = mgr.GetCompanies(txtCompanyName.Text, txtRegistrationNumber.Text);
if (linkUrl != "")
{
foreach (var c in companies)
{
c.Name = linkUrl + c.Id.ToString() + "&action=" + action + ">" + c.Name + "</a>";
}
}
rptrCompanies.DataSource = companies;
rptrCompanies.DataBind();
if you don't want the page to be redirected, you will need to use javascript.
There is now way you can pass values from different controls without going back to the server.
In case you keep it without the javascript:
I think you need to pass values from one user control to another. I used to accomplish this by firing reachable events between them.
For example:
in your parent view:
<uc:YourUserControl runat="server" ID="UserControl_Test"
OnYourCustomAction="UserControl_YourUserControl_YourCustomAction" />
In your user control:
public event EventHandler<CustomActionEventArgs> YourCustomAction;
also in the same user control create a public trigger method to be access from others usercontrols
public void TriggerCustomActoinEvent(CustomActionEventArgs EventArgs)
{
if (this.YourCustomAction!= null)
{
this.YourCustomAction(this, EventArgs);
}
}
Hope this help, in on my way to home this was from my mind!
Without a page postback or JavaScript it not really possible. If you are using modal popups you are already using JS, so why not just get the value in JS? You could setup an event handler for all repeater buttons and if they are loaded via ajax use something like this to attach the event handler:
$(document).on('click', '.repeaterButton', function(e) {
var valueOfBtnClicked = $(this).val();
// Do something else
});

Close Page on click button press asp.net c#

This is my first Page Name: RiskQuery.aspx. From this page on Click the
Link button of Grid View , open another page name, RiskMessage.aspx.
Both pages are under same master Page.
1st Page's Grid View Link button tag below:
<asp:HyperLinkField DataNavigateUrlFields="AppID" DataNavigateUrlFormatString="~\RiskMessage.aspx?AppID={0}" Text="Message" target="_blank" />
code behind of my RiskMessage.aspx:
if (!IsPostBack)
{
string id = null;
try
{
id = Session["cust_id"].ToString();
}
catch { }
if (id != null)
{
txtEntryHomeID.Text = id;
}
getMasterInfo();
}
I successfully opened the 2nd Page and from this page, I update my required
record. But I want to Close the 2nd page after I update the record on the [Save] button press.
I need help closing the 2nd page.
Add this line of code on Save button press:
Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>self.close();</script>");
if suppose your page was popup u can close by using window.close()
here u can use instead of
Page.ClientScript.RegisterStartupScript
ClientScript.RegisterClientScriptBlock
otherwise go back one step of your history by using JavaScript
end of your saving code if it is popup
ClientScript.RegisterClientScriptBlock(Page.GetType(), "script", "window.close();", true);

Categories