CrossPost access to data - asp.net

I have a search form on a page that posts back to itself and shows the results, all works fine. I now have a requirement to put the same search form on the site home page. This needs to post back to the search form and run the findResults code. Using the PostBackURL parameter on the home page form's submit button I can hit the search page ok. However, when using the following code in the Page_Load section of the search page I hit the problem of not being able to access data from the posting page as I get the following error message on the line starting "yearList.SelectedValue....": "'Site._default1.Protected WithEvents yearList As System.Web.UI.WebControls.DropDownList' is not accessible in this context because it is 'Protected'".
'#################################
'# Handle form post from Home page
'#################################
Dim crossPostBackPage As Site._default1
If Not (Page.PreviousPage Is Nothing) Then
If Not (Page.IsCrossPagePostBack) Then
If (Page.PreviousPage.IsValid) Then
crossPostBackPage = CType(PreviousPage, Site._default1)
yearList.SelectedValue = crossPostBackPage.yearList.SelectedValue
getAvailability()
End If
End If
End If
As I didn't declare yearList Protected, I don't know where to change it or how to.
Any advice would be appreciated,
Craig

dim prevYearList as ListBox = CType(PreviousPage.FindControl("yearList"),ListBox)
reference: http://msdn.microsoft.com/en-us/library/ms178139.aspx
note: the vb is a quick off the top of my head translation of my tested c# code, so don't take it literally.

Related

HTML to PDF: Avoid having the download button in the downloaded PDF

I have an ASP.NET page that generates a document for the user based on parameters in the URL. At the bottom of the document is a button that says "Download to PDF".
To implement that feature, I am using ABCPdf. I just feed my web page to the library and it spits out a PDF, and it works very well. Almost TOO well in fact - because the PDF includes the "Download" button itself. How can I include my entire page EXCEPT that specific button?
Here is what I have tried:
In the AddImageToURL call, I added a parameter "&pdfmode" to the URL. Then in my page load, I check for that parameter. If it is there, I say "btnDownloadPDF.Visible=False". This has no effect. I tried a similar approach by checking the page.request.form arguments to detect whether the page is posting back because of a click of the button.
'This does not work; the PDF still includes the download button
Dim pbcontrol = GetPostBackControl(Page)
Dim pdfMode As Boolean =
(pbcontrol IsNot Nothing AndAlso pbcontrol.ID = "btnDownloadPDF") _
OrElse (Not String.IsNullOrEmpty(Context.Request.QueryString("pdfmode")))
If pdfMode Then
btnDownloadPDF.Visible = False
End If
Hum, we probably need some details of how, and when the page is sent to that PDF system.
I suspect that that system takes the page URL and re-loads it?
Or does some code feed the PDF system a existing page class in code?
This suggests?
Hence on your existing page, you need a session() value, (or hidden field) and you have to set that persisted value to "hide" the button.
Then in your on-page load event, check for that session() value, and simple go mybutton.visible = false. So, that external library probably is feed a page url, and it re-renders the whole page - so in page on-load, you need to hide the button?
It just not clear how you hiding that button, but in your code behind, that may well not suffice, since the PDF library is re-loading its OWN copy of the page - hence you need code in the on-load event to hide the button.

how to show search data after postback function call in asp.net

gridview details show exactly what as i want even search data also show fine but problem is when i post back page and return on search page search is not maintain in gridview i use gridview.Databind() function on page load use (!page.postback) function but then also not useful for me so please can you all give me any code for that
on page load i write but not useful for me
if(!page.postback)
{
sda = new SqlDataAdapter("Select Name,ContactNo,Address from gridviewtable",con);
ds = new DataSet();
sda.Fill(ds);
gvd_detail.DataSource = ds;
gvd_detail.DataBind();
}
Here are some solution :
1- After every user search , Redirect user to page with parameter( like query string) and then on that page retrieve parameter and show appropriate result
2-Asp.net pages by default maintain page state by "View-state" , First make sure ViewState property of the page is True , Then make sure in page life cycle where you have rebind gridview
3-If there is situation in which #2 solution didn't work , There are another solution and that is saving page state in ViewState page explicitly
Hope these help

How to wait three seconds then turn to another webpage

I'm new to web development, and I'm currently using ASP.net. I wonder what would I need to do to let the browser wait for 3 seconds so my users can read the text "Customer Successfully Added" before turning to another page? I have attached my code as follows.
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim db As New DatabaseClass
db.addProfile(txtLN.Text, txtFN.Text, txtUsername.Text, txtPassword.Text, txtAddress.Text, txtZip.Text, txtPhone.Text, txtEmail.Text)
lblMessage.Text = "Customer Successfully Added"
End Sub
In addition, I'm not sure how to utilize MSDN. For me, its information overload, I'm wondering how to go about finding the solution on MSDN so i would be able to solve my problems in the future. Thank you!
You can't do it in the code behind of the page because of how asp.net works - the label text would not update until after the timeout occurred if you did it in the code-behind.
The server-side processing spits all the html back to the browser only after it has completely processed any server-side code unless you're using Ajax. Since you're new, I won't even bother going into how to do it with Ajax as there is a MUCH simpler option for accomplishing what you want.
A simple method to accomplish what you're looking for would be to have a simple HTML page that just has a message that says "Customer successfully added" and use javascript (client-side code) to pause and then redirect using the Javascript "SetTimeout" function.
There's an example here: http://www.bloggingdeveloper.com/post/JavaScript-Url-Redirect-with-Delay.aspx
The logic flow wshould work like this:
The original page should add the record (in code-behind) then redirect to this simple html page (in code-behind). The html page should have the "Customer Added" message and use the SetTimeout and Redirect to go to whatever page you want the user to see after viewing the message.
For stuff like this you need the code to run client side rather than on the server. The easiest way to do this is to return some javascript with your page (in the .aspx part rather than the code behind)
Take a look here for an idea of what to do :)
The page is displayed for a few seconds and then the javascript triggers a redirect to a url of your choosing. Just add something like this into your html.
You can emit javascript to redirect to the other page, using the setTimeout function.
This is best accomplished using the ScriptManager to register any javascript on the page.

How to create ASPX Page Dynamically

i have two controls on asp.net page , textbox and button and i want to write new page into textbox then when i hit the button i want to create new asp.net web page with textbox text. what do you want me to prefer to do this? is there any step by step tutorial or any code you have done before? thanks for asnwers.
ok more detail about what i want.
textbox control text is "contact" and i click my button control. button take textbox text "contact" and create new web form page which name is "contact.aspx and its code page contact.cs" . thats it. just create new web form page under root directory with button click.
maybe there is a single code line like
Page pg =new Page();
pg.create();
You can use File.WriteAllText to write the contents of the textbox to any location that the application pool user has permissions to write to.
From your edit it appears that you are looking for a CMS/wiki kind of functionality. There is nothing like that built into the .NET framework.
I suggest you look for wiki software.
No need to worry about big codes etc
You can create it with 2 simple steps explained in my blog
Create one empty page then copy it using Files concept. Save it as what ever name you want.
Try to change the content inside newly created page to Run smoothly
Please visit my blog for example solution
Click here for Solution Post
You can use the Page.ParseControl method.
Beware, it does not support everything you can do with a real ASPX or ASHX file, but it works for simple things. An example is available here: Using Page.ParseControl to add new control from Control Tag
There is very simple way to do that. It is working on principe to Copy one your Page, you should put Page with controls that you want to use on your other pages. So first you need using System.IO; then you need this code
protected void Button1_Click(object sender, EventArgs e)
{
try
{
File.Copy(Server.MapPath("") + "\\Submit.aspx", (Server.MapPath("") + "\\" + TextBox1.Text + ".aspx"));
File.Copy(Server.MapPath("") + "\\Submit.aspx.cs", (Server.MapPath("")+ "\\" + TextBox1.Text + ".aspx.cs"));
Response.Redirect(TextBox1.Text + ".aspx");
}
catch
{
Response.Write("<script>window.alert('This page is taken. Please change name!')</script>");
}
}
As you can see, The page you are coping is called Submit, and new Name of your Page is called like textbox1.text.
I hope that this helped you and anyone else.
enter link description here
Before some time I saw a logical question in a web site in this a person give the problem as like this
“I have one page called First.aspx in my web application, in this page; I have a simple asp.net button control. And I want is, on the click event of that button control, create (render) a new dynamic "page" that can be opened in a new windows or tab”
.
Here we give An Example here to creating a new .aspx page at run time. We also give the option to give page name. The user can give as he/she like. Like Google blogging we make new page at runtime.The new page is not in the website, this page create needs to be created at runtime and needs to be dynamic.

How do I make a link in a master page, which includes dynamic information from the current page?

I have a master page, with a help link in the top menu. This link should contain the a dynamic bookmark from the current page, so that the user scrolls to the help for the page he is currently seeing.
Help
How would you implement this?
Another thing you could do is reference the master page through the content page itself.
To make it easier on myself, I create a publicly accessible method in the master page itself:
Public Sub SetNavigationPage(ByVal LinkName As String)
DirectCast(Me.FindControl(MenuName), HyperLink).NavigateUrl = "help.aspx#" & LinkName
End Sub
Then in the content page, I get a reference to the master page through the following...
Dim myMaster As MasterPageClass = DirectCast(Me.Master, MasterPageClass)
myMaster.SetNavigationPage("CurrentPage")
I would use "Request.PhysicalPath" to get the physical path that was requested, then within your help HMTL you can denote the sections by what page they are about.
You might go as far as to use:
Path.GetFileName(Request.PhysicalPath).ToUpper()
to normalize the data. Using the PhysicalPath would allow you to have all logic in the master page; which would eliminate the need to write code in all content pages. Just my preference.
i haven't written a line of c# in over three months but you could hook up an event in the masterpage (OnLoad) and set the link from there. See what's in the ContentPlaceholder that's your main page and get it's type or name, then apply it to the link.
Put
Help
into the MasterPage, and then anchors on the help page in the format of:
<a name="page1.aspx" />Blah, blah
<a name="page2.aspx" />Blah, blah
If you repeat page names in subfolders, eg., Sub1/page1.aspx and Sub2/page1.aspx - you'll have to be slightly more clever.

Resources