codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
This 16 message thread spans 2 pages: [1]  2  > >  
  Questions about web user control in ASP.NET  ipsoftware at 07:30 on Thursday, January 13, 2005
 


Suppose I have a web user control page (.ascx) which contains 3 buttons.
One Web page (.aspx) will use all 3 buttons and functions associated. It is easy to add this web user control page to the .aspx page. However, I get another page whic will use ONLY 2 buttons of the web user control. How to extract those particular two buttone from the web user control and add them in?

Thank u!!!

  Re: Questions about web user control in ASP.NET  tgreer at 15:17 on Thursday, January 13, 2005
 

I don't think you can. I could be wrong. But the approach I would take is to disable the unneeded button, in code, in the second project.


  Re: Questions about web user control in ASP.NET  ipsoftware at 15:41 on Thursday, January 13, 2005
 

exactly, I am thinking the same as you :) :)

Another question I have is suppose I have a button in the ASPNET page. It will trigger an backend function (in the .aspx.cs file) which may take quite some time to complete upon being clicked. The funtion call will be synchronous. Coz the implementation takes some time to complete, I like to display a progress bar (as I asked before and you suggested, I used a animated GIF :)) to indicate the ongoing activity. However, if I write code in the behind like the following

Button_Click(...){
image.visible = true;
call function;
image.visible = false;
}

This won't work since it is a synchronous call, the .aspx page won't get image rendered until the function implementation completes. So setting image visibility status here has no use.
However, how may I achieve my purpose? That is: once the button is clicked, the image is displayed first, then the time-consuming function will start exectuing. once it is done, the image will be set to be not visible.
I don't want to write the Button_Click(...) in the .aspx page as I want separation between GUI and backend control.

Is it possible to do that? thank u!!!

  Re: Questions about web user control in ASP.NET  tgreer at 16:16 on Thursday, January 13, 2005
 

Yes, you have to use JavaScript though.

Here is the basic workflow.

1) User browses to page.

2) Server Code runs to generate page, including form.

3) Users clicks a button

3a) JavaScript runs to alter visibility of controls via CSS.
3b) JavaScript submits the form

4) Server processed the form, generates new page.


The key is that on the button (Step 3), not only do you have to code a server event function, you also have to code a JavaScript function. You can do that when your page first loads, by adding an attribute:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
Button1.Attributes.Add("onclick","myJavaScriptFunction();");
}
}

The JavaScript will run first, in the client. Then the page will submit, and the server code will run.

One trick I use is to place all the page controls into a <div>. I put the "Please Wait" stuff in a second <div> with a CSS style applied "visibility: hidden;".

The in my JavaScript, I toggle the visibility of both divs, so that the main form is hidden, and the Please Wait stuff is "visibility: visible;".

As always:

Was this post helpful? Please note that CodeToad is advertiser supported.

I have some articles on my site about ASP.NET and HTML and client-server issues. www.tgreer.com is also advertiser supported.




  Re: Questions about web user control in ASP.NET  ipsoftware at 16:44 on Thursday, January 13, 2005
 

but one problem seems not to be resolved using your approach. when clicking on button1, the IsPostBack is false, therefore, I may register the javascript function with it using Button1.Attributes.Add("onclick","button1ScriptFunction();"); , after excuting the function, I click the button again to reissue the function call, the javascript function won't be associated with it coz IsPostBack if true now. Am I right?

If we don't use the IsPostBack checking condition and still write

private void Page_Load(object sender, System.EventArgs e)
{
Button1.Attributes.Add("onclick","myJavaScriptFunction();");
}

then every time, when the page is loaded, the progress bar will be displayed even if the page_load may be triggered by some other controls which don't need the progress bar.

  Re: Questions about web user control in ASP.NET  ipsoftware at 16:45 on Thursday, January 13, 2005
 

but one problem seems not to be resolved using your approach. when clicking on button1, the IsPostBack is false, therefore, I may register the javascript function with it using Button1.Attributes.Add("onclick","button1ScriptFunction();"); , after excuting the function, I click the button again to reissue the function call, the javascript function won't be associated with it coz IsPostBack if true now. Am I right?

If we don't use the IsPostBack checking condition and still write

private void Page_Load(object sender, System.EventArgs e)
{
Button1.Attributes.Add("onclick","myJavaScriptFunction();");
}

then every time, when the page is loaded, the progress bar will be displayed even if the page_load may be triggered by some other controls which don't need the progress bar.

  Re: Questions about web user control in ASP.NET  ipsoftware at 16:45 on Thursday, January 13, 2005
 

but one problem seems not to be resolved using your approach. when clicking on button1, the IsPostBack is false, therefore, I may register the javascript function with it using Button1.Attributes.Add("onclick","button1ScriptFunction();"); , after excuting the function, I click the button again to reissue the function call, the javascript function won't be associated with it coz IsPostBack if true now. Am I right?

If we don't use the IsPostBack checking condition and still write

private void Page_Load(object sender, System.EventArgs e)
{
Button1.Attributes.Add("onclick","myJavaScriptFunction();");
}

then every time, when the page is loaded, the progress bar will be displayed even if the page_load may be triggered by some other controls which don't need the progress bar.

  Re: Questions about web user control in ASP.NET  ipsoftware at 16:46 on Thursday, January 13, 2005
 

but one problem seems not to be resolved using your approach. when clicking on button1, the IsPostBack is false, therefore, I may register the javascript function with it using Button1.Attributes.Add("onclick","button1ScriptFunction();"); , after excuting the function, I click the button again to reissue the function call, the javascript function won't be associated with it coz IsPostBack if true now. Am I right?

If we don't use the IsPostBack checking condition and still write

private void Page_Load(object sender, System.EventArgs e)
{
Button1.Attributes.Add("onclick","myJavaScriptFunction();");
}

then every time, when the page is loaded, the progress bar will be displayed even if the page_load may be triggered by some other controls which don't need the progress bar.

  Re: Questions about web user control in ASP.NET  ipsoftware at 16:46 on Thursday, January 13, 2005
 

but one problem seems not to be resolved using your approach. when clicking on button1, the IsPostBack is false, therefore, I may register the javascript function with it using Button1.Attributes.Add("onclick","button1ScriptFunction();"); , after excuting the function, I click the button again to reissue the function call, the javascript function won't be associated with it coz IsPostBack if true now. Am I right?

If we don't use the IsPostBack checking condition and still write

private void Page_Load(object sender, System.EventArgs e)
{
Button1.Attributes.Add("onclick","myJavaScriptFunction();");
}

then every time, when the page is loaded, the progress bar will be displayed even if the page_load may be triggered by some other controls which don't need the progress bar.

  Re: Questions about web user control in ASP.NET  tgreer at 17:18 on Thursday, January 13, 2005
 


No, no... the first and only the first time the page loads, associate the onlick with the button. You don't have to do it every time, because it will be maintained by the ViewState mechanism (read the ViewState article on my site).

When the button is clicked, the script runs. You have to include the script on the page somehow. You can use standard <script src="/forum/myjavascript.js" type="text/javascript" /> syntax or include it inline.

The script makes the "Please wait!" stuff visible, and then the form submits.

When the Page come back to the user, it will revert to the original visibility settings because CSS styles aren't maintained by ViewState.

Make sense?


  Re: Questions about web user control in ASP.NET  ipsoftware at 02:40 on Friday, January 14, 2005
 

exactly, you are right, I got your idea.

Sorry for my stupid question, I just cannot make the image to be visible, I am trying to write the script.
In the script function

showImage()
{
document.form.image1.Visible = true;
//which is not working, cause for a html image, it has
//no "visible" property, for a asp:image, I cannot set
//the visibility property value here. and no Hidden
//property is available.
}

I just cannot manage the image visibility. I did a search in goole, there is no finding.

Please forgive if this question is too stupid!

Thank u!

  Re: Questions about web user control in ASP.NET  tgreer at 03:58 on Friday, January 14, 2005
 

The question isn't stupid at all, don't worry about that.

You're confusing Server Control Properties, such as "Visible = False", with HTML style properties.

Consider this complete HTML page (no ASP.NET stuff here at all):



<html>
<head>
<title>tgreer sample code</title>
<style type="text/css">
.invisbleParagraph
{
visibility: hidden;
}
</style>
</head>
<body>
<p id="myParagraph" class="invisibleParagraph">An invisible paragraph!</p>
</body>
</html>


Now, in JavaScript, you can change style attributes by using the "style" property of a control. So this line of JavaScript would make our paragraph visible:

document.getElementById("myParagraph").style.visibility = "visible";

You shouldn't use the ASP.NET Web Server Control "visible" property at all. Remember that server controls are objects that produce, or render, HTML. If IIS/ASP.NET sees that a server control has a "false" visibility, it won't render any HTML at all. What I'm suggesting is to use client styles and code to control the visibility of your HTML.



  Re: Questions about web user control in ASP.NET  ipsoftware at 08:07 on Friday, January 14, 2005
 

I have a much better understanding now :):)

But your code seems a bit not right, coz when I paste them to text editor and save it to be a .htm file. Text "An invisible paragraph!" is still visible when opening the file using IE.

  Re: Questions about web user control in ASP.NET  tgreer at 14:40 on Friday, January 14, 2005
 

Sorry, there is a typo. In the style definition, add the missing "i":

invisibleParagraph vs. invisbleParagraph

They have to match exactly, of course.


  Re: Questions about web user control in ASP.NET  ipsoftware at 16:15 on Friday, January 14, 2005
 

yes, right, I also didn't notice that. ~~~~

upon clicking on the button, the hidden image is shown. However, surprisingly, the animated gif becomes a still one while the backend time-consuming activity is in progress. The image is not animated at all.....funny


<Added>

Do you know how come the gif is not animated any more? you experienced this before? thank u

This 16 message thread spans 2 pages: [1]  2  > >  







CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: How to Change user to root using ssh::expect
•  Re: huffman encoding and decoding in C++...
•  Re: how to convert wav file to text file
•  Re: Need Javascript Multiple sidebar menu with sliding effects
•  DBD::DB2 Module On Linux -Error
•  XMLHttpRequest returns 404 on Php files
•  Re: Save up to 80% on SSL Certificates, RapidSSL Certificate @ $ 11.00/yr.
•  Re: horizontal scroll bar for drop down list box
•  IFRAME question


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010