Showing posts with label page. Show all posts
Showing posts with label page. Show all posts

Saturday, March 31, 2012

String Stripping

Hi,

I am trying to create a page that will check user input against a value in database. This page will have a text box for user to enter serial #.
Serial # length is variable but last 3 digit is always number.
For examples:
W04051234-PAY001 in this example code is 1234-PAY
W05051234-PAT002 in this example code is 1234-PAT

A12056040-G001 in this example code is 6040-G
B11056080-SU001 in this example code is 6080-s

Which is the best approach to extract CODE from user input?

Any help will be appriciated.

Thank

TekinUse the Regular Expression class, RegExp with a regular expression that looks for:
4 digits (or is it 3?) followed by
dash
followed by 1 or letters

That expression is:
\d{4}\-[A-Za-z]+
Actually,

I would like to Trancate first 5 digits and last 3 digits.

For examples:
W04051234-PAY001 in this example code is 1234-PAY
If you are attempting to strip a specific group of characters, the String class has numerous useful methods. I encourage you to read about the String class in the .net docs. I think the SubString() and Length() methods will be useful.

String to date error

Hi guys Ive got a slight problem..

When i run my asp.net page through visual studio the application works fine, however when i puslish it and view it over myhttp://localhost page i get the following error "Conversion from string "28/8/2007" to type 'Date' is not valid." when selecting dates from a calendar control i created.

Im thinking this is some formatting issue having to do with EU/US Date format, however im not too sure about it and with a few research there are some help files stating to use globalization and once again im not sure how that works.

What im doing is assigning a date within an arraylist (which are of type dates) to a Date variable as below

Dim tempDate asDatetempDate = NewDate.Item(0) // arraylist of containing dates
Would appreciate some help regarding this issue

Thanks :)

It is a en-eu related problem. This article should help

http://msdn2.microsoft.com/en-us/library/2h3syy57.aspx
thanks that was interesting, also found out that the root to the problem was due to regional settings under the aspnet user account, my currently logged on account was set to UK however the user account aspnet was still on US therefore it kept showing dates in US format

Monday, March 26, 2012

stringbuilder to excel

Hello Everyone,

I am trying to save a stringBuilder to excel spreadsheet from asp.net page. I can succesfully save the string, but how can I pur each string in different cells

so I have this string

StringBuilder sb= new StringBuilder();
sb.append("A");
sb.append("B");
sb.append("C");
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
btnExport.EnableViewState = false;
Response.Write(sb);
Response.End();

it saves and creates the excel spreadsheet, but ABC all come in one cell of spreadsheet. How can I place A in once and right below it in another cell, I want to place "B" and "C" in another cell below B.

Is it possible to do it.

Please let me know.

Thanks.

Im supprised it works as it is!! usually you have to call .ToString() on a string builder to retrieve its text? Then append method also starts with a capital :D

Putting that to one side, you can achieve your goal by creating a table!

StringBuilder sb= new StringBuilder();
sb.Append("<table><tr>");
sb.append("<td>A</td>");
sb.append("<td>B</td>");");
sb.append("<td>C</td>");");
sb.Append("</tr></table>
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
btnExport.EnableViewState = false;
Response.Write(sb);
Response.End();


Sorry miss-read what your requirements are. The code i provided will place text into ajacent horizontal cells. To have the rows in a verticle mannor create each <td> within a new row!

strings

i display tags on the page separated by commas

eg:tag1,tag2,tag3

if i have only 1 tag it should add

eg:tag1

not

eg:tag1,

if i have only 2 tag it should add

eg:tag1,tag2

not

eg:tag1,tag2,

how to do that because my functions returns with comma

while

(dtardrTagOther.Read())

{

strOtherTags += dtardrTagOther.GetValue(0).ToString()+ ",";

}

Hello,Just discard the last comma from the strOtherTags after the end of while loop. like

while

(dtardrTagOther.Read())

{

strOtherTags += dtardrTagOther.GetValue(0).ToString()+ ",";

}

strOtherTags = strOtherTags.Remove(strOtherTags.Length-1,1);

!!! Mark as Answer if it meets your requirement !!!


Thanks.

Try the below code

while(dtardrTagOther.Read())

{

if (strOtherTags == string.Empty)

{

strOtherTags = dtardrTagOther.GetValue(0).ToString();

}

else

strOtherTags += "," + dtardrTagOther.GetValue(0).ToString();

}

HC


after u exit while:

strOtherTags = strOtherTags.Substring(0, strOtherTags.Length - 1)

HTH

Strings and wildcard

I am doing some things with page url's, and of couse, I test on the local host.
Only thing is, when I post to the server, the name of the host chages.

I can do an if x or y then.... but as usual, want to save code space and incase the name of the server changes, need to do something else.

What I have been searching for, unsuccessfully, is a way to insert the wildcard * into the string... such as...

If myurl = "http://" & * & "pagename.aspx" Then

Well, the * is not declared and can't seem to find how to tell the string doesn't matter the host name.

Suggestions?

Thanks all,

ZathI don't recommend approaching this problem with a wildcard. There is a simpler solution.
Try something along these lines:

 Dim requestedUrl As String = System.Web.HttpContext.Current.Request.Path.ToLower()
Select Case requestedUrl
Case "default.aspx"
' settings for homepage
Case "about.aspx"
' settings for about page
Case "contact.aspx"
' settings for contact page
Case Else
' settings for page not found
End Select
The long first line will give us the requested URL, but without the host and application name.
So this ignores the host and application name, in the same way your wildcard would have done.

I hope this helps.
Thanks!

That works even better!

After posting the message, I was actually looking for a way to get the host name to input it that way and solve the problem.

Zath
The following is a test page that I use quite often.
It allows me to see various Request and HTTP values.

In situations such as the above, you can look at the results of this test page,
and see whether there are any existing values that will match your needs.

For example, this test page will show you which Request property to use if
your URL testing also takes into account QueryStrings.

Anyway, I thought that the following may help you.

<%@. Page Language="C#" Debug="True" Trace="True" %><html>
<head>
</head>
<body>
<h2>Request Report</h2>
<hr />
<p><asp:Label id="Message" runat="server" /></p>
</body>
</html>
<script runat="server">
public void Page_Load (object sender, EventArgs e)
{
Message.Text += "Page.Request.ApplicationPath: " + Page.Request.ApplicationPath + "<br " + "/>";
Message.Text += "Page.Request.FilePath: " + Page.Request.FilePath + "<br " + "/>";
Message.Text += "Page.Request.Path: " + Page.Request.Path + "<br " + "/>";
Message.Text += "Page.Request.PathInfo: " + Page.Request.PathInfo + "<br " + "/>";
Message.Text += "Page.Request.PhysicalApplicationPath: " + Page.Request.PhysicalApplicationPath + "<br " + "/>";
Message.Text += "Page.Request.PhysicalPath: " + Page.Request.PhysicalPath + "<br " + "/>";
Message.Text += "Page.Request.RawUrl: " + Page.Request.RawUrl + "<br " + "/>";
Message.Text += "Page.Request.UserAgent: " + Page.Request.UserAgent + "<br " + "/>";
Message.Text += "Page.Request.UserHostAddress: " + Page.Request.UserHostAddress + "<br " + "/>";
Message.Text += "Page.Request.UserHostName: " + Page.Request.UserHostName + "<br " + "/>";
Message.Text += "Page.Request.Url.AbsolutePath: " + Page.Request.Url.AbsolutePath + "<br " + "/>";
Message.Text += "Page.Request.Url.Host: " + Page.Request.Url.Host + "<br " + "/>";
Message.Text += "Page.Request.Url.LocalPath: " + Page.Request.Url.LocalPath + "<br " + "/>";
Message.Text += "Page.Request.Url.PathAndQuery: " + Page.Request.Url.PathAndQuery + "<br " + "/>";
Message.Text += "<br " + "/>";

Message.Text += "<hr />Request.UrlReferrer<br>";
if (Request.UrlReferrer != null)
{
Uri referrer = Request.UrlReferrer;
Message.Text += "Request.UrlReferrer.AbsolutePath: " + referrer.AbsolutePath + "<br>";
Message.Text += "Request.UrlReferrer.AbsoluteUri: " + referrer.AbsoluteUri + "<br>";
Message.Text += "Request.UrlReferrer.Authority: " + referrer.Authority + "<br>";
Message.Text += "Request.UrlReferrer.Fragment: " + referrer.Fragment + "<br>";
Message.Text += "Request.UrlReferrer.Host: " + referrer.Host + "<br>";
Message.Text += "Request.UrlReferrer.LocalPath: " + referrer.LocalPath + "<br>";
Message.Text += "Request.UrlReferrer.PathAndQuery: " + referrer.PathAndQuery + "<br>";
Message.Text += "Request.UrlReferrer.Query: " + referrer.Query + "<br>";
Message.Text += "Request.UrlReferrer.Scheme: " + referrer.Scheme + "<br>";
Message.Text += "Request.UrlReferrer.UserInfo: " + referrer.UserInfo + "<br>";
Message.Text += "<br " + "/>";
}

Message.Text += "<hr />Request.Headers" + "<br " + "/>";
OutputCollection(Request.Headers);

Message.Text += "<hr />Request.Browser" + "<br " + "/>";
HttpBrowserCapabilities bc = Request.Browser;
Message.Text += "Type = " + bc.Type + "<br>";
Message.Text += "Name = " + bc.Browser + "<br>";
Message.Text += "Version = " + bc.Version + "<br>";
Message.Text += "Major Version = " + bc.MajorVersion + "<br>";
Message.Text += "Minor Version = " + bc.MinorVersion + "<br>";
Message.Text += "Platform = " + bc.Platform + "<br>";
Message.Text += "Is Beta = " + bc.Beta + "<br>";
Message.Text += "Is Crawler = " + bc.Crawler + "<br>";
Message.Text += "Is AOL = " + bc.AOL + "<br>";
Message.Text += "Is Win16 = " + bc.Win16 + "<br>";
Message.Text += "Is Win32 = " + bc.Win32 + "<br>";
Message.Text += "Supports Frames = " + bc.Frames + "<br>";
Message.Text += "Supports Tables = " + bc.Tables + "<br>";
Message.Text += "Supports Cookies = " + bc.Cookies + "<br>";
Message.Text += "Supports VB Script = " + bc.VBScript + "<br>";
Message.Text += "Supports JavaScript = " + bc.JavaScript + "<br>";
Message.Text += "Supports Java Applets = " + bc.JavaApplets + "<br>";
Message.Text += "Supports ActiveX Controls = " + bc.ActiveXControls + "<br>";
Message.Text += "CDF = " + bc.CDF + "<br>";

Message.Text += "<hr />Request.ServerVariables" + "<br " + "/>";
OutputCollection(Request.ServerVariables);

}

private void OutputCollection(NameValueCollection coll)
{
int loop1, loop2;
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1<arr1.Length; loop1++)
{
Message.Text += "Key: " + arr1[loop1] + "<br " + "/>";
// Get all values under this key.
String[] arr2=coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2<arr2.Length; loop2++)
{
Message.Text += "Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br " + "/>" + "<br " + "/>";
}
}
}
</script>


Don't you think usingTrace would be simpler for this?
> Don't you think using Trace would be simpler for this?

The test page does have tracing turned on, so trace information is included on the page.

But Trace alone will not show the value of the Request's properties, or the Request.UrlReferrer's properties.

I know that much of my output is redundant for a page with Trace output. But the idea is tosee how the values in the HTTP headers and the form collection translate into the various properties available in the current Request object.

A simple page like this excuses me from having to remember which of the Request properties include the querystring, and which do not. Even though it was a test page I made when I was new to ASP.NET, I still find it helpful. I simply thought it may help the original poster, too.
Thanks SomeNewKid, that test page does help a LOT!

Yes, it is because I am doing a new user email confirm activate new account page.
The URL will have a querry sting in it for confirmation.

Zath

Saturday, March 24, 2012

Strip space before page rendering

Is there any benefit to stripping all the space from the page before
rendering by overriding the page render and using the htmltextwriter and
stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
that may site's source code is like this. Is this because it is better for
the browser or harder for someone to be able to read it. Or maybe there is a
method or command to do this automatically?

Any thoughts are appreciated.

Mikesaves bandwidth mainly...

"vMike" <Michael.George@.gewarren.com.nospam> wrote in message
news:bnpsnk$rfa$1@.ngspool-d02.news.aol.com...
> Is there any benefit to stripping all the space from the page before
> rendering by overriding the page render and using the htmltextwriter and
> stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
> that may site's source code is like this. Is this because it is better for
> the browser or harder for someone to be able to read it. Or maybe there is
a
> method or command to do this automatically?
> Any thoughts are appreciated.
> Mike
I don't think there is a way to do it automatically, but it's simple enough
to implement.

This is the approach I use:

I have a base class derived from System.Web.UI.Page and override Render

namespace DoNot.Invade.MySpace
{
class Page : System.Web.UI.Page
{
protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);

base.Render (hw);

string html = sb.ToString();

html = html.Replace(Environment.NewLine, string.Empty);
html = html.Replace("\n", string.Empty); // This may be redundant
html = html.Replace("\t", string.Empty);

writer.Write(html);
}
}
}

Hope this helps
Brian W

"vMike" <Michael.George@.gewarren.com.nospam> wrote in message
news:bnpsnk$rfa$1@.ngspool-d02.news.aol.com...
> Is there any benefit to stripping all the space from the page before
> rendering by overriding the page render and using the htmltextwriter and
> stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
> that may site's source code is like this. Is this because it is better for
> the browser or harder for someone to be able to read it. Or maybe there is
a
> method or command to do this automatically?
> Any thoughts are appreciated.
> Mike
Thanks, I had something similar to that. The only thing I had to do was do
remove the <!-- that asp puts before the javascipt for postback because when
I removed the rest of the line is caused an error. But I wonder is stripping
the space make the page display any quicker in the browser as I image there
is a small amount of overhead on the server side.

"Brian W" <brianw@.gold_death_2_spam_rush.com> wrote in message
news:%23zf8QjxnDHA.1488@.TK2MSFTNGP12.phx.gbl...
> I don't think there is a way to do it automatically, but it's simple
enough
> to implement.
> This is the approach I use:
> I have a base class derived from System.Web.UI.Page and override Render
> namespace DoNot.Invade.MySpace
> {
> class Page : System.Web.UI.Page
> {
> protected override void Render(HtmlTextWriter writer)
> {
> StringBuilder sb = new StringBuilder();
> StringWriter sw = new StringWriter(sb);
> HtmlTextWriter hw = new HtmlTextWriter(sw);
> base.Render (hw);
> string html = sb.ToString();
> html = html.Replace(Environment.NewLine, string.Empty);
> html = html.Replace("\n", string.Empty); // This may be redundant
> html = html.Replace("\t", string.Empty);
> writer.Write(html);
> }
> }
> }
> Hope this helps
> Brian W
> "vMike" <Michael.George@.gewarren.com.nospam> wrote in message
> news:bnpsnk$rfa$1@.ngspool-d02.news.aol.com...
> > Is there any benefit to stripping all the space from the page before
> > rendering by overriding the page render and using the htmltextwriter and
> > stringbuilder to strip linefeeds, tabs and extra space etc. I have
noticed
> > that may site's source code is like this. Is this because it is better
for
> > the browser or harder for someone to be able to read it. Or maybe there
is
> a
> > method or command to do this automatically?
> > Any thoughts are appreciated.
> > Mike
Brian W wrote:

> I don't think there is a way to do it automatically, but it's simple enough
> to implement.
> This is the approach I use:
> I have a base class derived from System.Web.UI.Page and override Render
> namespace DoNot.Invade.MySpace
> {
> class Page : System.Web.UI.Page
> {
> protected override void Render(HtmlTextWriter writer)
> {
> StringBuilder sb = new StringBuilder();
> StringWriter sw = new StringWriter(sb);
> HtmlTextWriter hw = new HtmlTextWriter(sw);
> base.Render (hw);
> string html = sb.ToString();
> html = html.Replace(Environment.NewLine, string.Empty);
> html = html.Replace("\n", string.Empty); // This may be redundant
> html = html.Replace("\t", string.Empty);
> writer.Write(html);
> }
> }
> }

You'll want to be careful with simplistic code like this. There are
times when whitespace and newlines are significant, such as text inside
of a <pre> element or script code.

> Hope this helps
> Brian W
> "vMike" <Michael.George@.gewarren.com.nospam> wrote in message
> news:bnpsnk$rfa$1@.ngspool-d02.news.aol.com...
>>Is there any benefit to stripping all the space from the page before
>>rendering by overriding the page render and using the htmltextwriter and
>>stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
>>that may site's source code is like this. Is this because it is better for
>>the browser or harder for someone to be able to read it. Or maybe there is
> a
>>method or command to do this automatically?
>>
>>Any thoughts are appreciated.
>>
>>Mike
>>
>>

--
mikeb
True, I guess I should have mentioned that. Since the site I'm currently
working on doesn't use <pre> I don't worry about it. And what I have written
can be expanded upon to handle these situations.

There are other cases where this is a problem too. Such as the following:

<p>
This is
some text
</p
will produce the following output:

This issome text

For me, though, I just edit the html and make sure there is also a space
before the newline.

Regards
Brian W

"mikeb" <mailbox.google@.mailnull.com> wrote in message
news:%23YdMB$xnDHA.1672@.TK2MSFTNGP09.phx.gbl...
> Brian W wrote:
> > I don't think there is a way to do it automatically, but it's simple
enough
> > to implement.
> > This is the approach I use:
> > I have a base class derived from System.Web.UI.Page and override Render
> > namespace DoNot.Invade.MySpace
> > {
> > class Page : System.Web.UI.Page
> > {
> > protected override void Render(HtmlTextWriter writer)
> > {
> > StringBuilder sb = new StringBuilder();
> > StringWriter sw = new StringWriter(sb);
> > HtmlTextWriter hw = new HtmlTextWriter(sw);
> > base.Render (hw);
> > string html = sb.ToString();
> > html = html.Replace(Environment.NewLine, string.Empty);
> > html = html.Replace("\n", string.Empty); // This may be redundant
> > html = html.Replace("\t", string.Empty);
> > writer.Write(html);
> > }
> > }
> > }
> You'll want to be careful with simplistic code like this. There are
> times when whitespace and newlines are significant, such as text inside
> of a <pre> element or script code.
>
> > Hope this helps
> > Brian W
> > "vMike" <Michael.George@.gewarren.com.nospam> wrote in message
> > news:bnpsnk$rfa$1@.ngspool-d02.news.aol.com...
> >>Is there any benefit to stripping all the space from the page before
> >>rendering by overriding the page render and using the htmltextwriter and
> >>stringbuilder to strip linefeeds, tabs and extra space etc. I have
noticed
> >>that may site's source code is like this. Is this because it is better
for
> >>the browser or harder for someone to be able to read it. Or maybe there
is
> > a
> >>method or command to do this automatically?
> >>
> >>Any thoughts are appreciated.
> >>
> >>Mike
> >>
> >>
> --
> mikeb

stripping out html tags for plain txt email

I was wondering what the best way to strip the html tags off of a page and add vbclf and such for plain text emailing of web pages

if you could point me in the right direction it would be greatTo remove HTML tags from awell-formed document:
Converting HTML to Text
awesome what a life saver
now how could I change the code below so that it replaces the </p> and <br> with a _vbclrf or a plaintext line break and also how can I get it to remove all of the dead space I see a comment posted on the page you linked about doing it but no one actually does


Public Function StripTags(ByVal HTML As String) As String
' Removes tags from passed HTML
Dim objRegEx As _
System.Text.RegularExpressions.Regex
Return objRegEx.Replace(HTML, "<[^>]*>", "")
End Function

Try the following:
 Import System.Text.RegularExpressions

Public Function StripTags(ByVal HTML As String) As String
Dim cleanString As String = HTML
Dim objRegEx As Regex

' First, remove whitespace
objRegEx = New RegEx( "\s{2,}" )
cleanString = objRegEx.Replace( cleanString, " " )

' Second, replace HTML linebreaks with text line breaks
objRegEx = New RegEx( "((</p>)|(<br ?/?>))" )
cleanString = objRegEx.Replace( cleanString, System.Environment.NewLine )

' Third, clean up any occurrence of newline + space
objRegEx = New RegEx( "(^|\n) +" )
cleanString = objRegEx.Replace( cleanString, String.Empty)

' Finally, remove HTML tags
objRegEx = New RegEx( "<[^>]*?>" )
cleanString = objRegEx.Replace( cleanString, String.Empty)

Return cleanString
End Function

Stripping the time portion from date field

Hi all
I've got a textbox on the web page that captures a date.
When an insert is done, the information captured into the database is of the format dd/mm/yyyy hh:mm:ss.
How do I strip the time portion and save only the date part into the database ?
I'm using a formview, sqldatasource controls for this web page.
I tried the following in formview iteminserting event:
Dim culture_2 As System.Globalization.CultureInfo = New CultureInfo("en-GB", True)
Dim wAcceptanceD As TextBox = CType(FormView1.Row.FindControl("dtAcceptDTextBox"), TextBox)
e.Values.Add("dtAcceptD", DateTime.Parse(wAcceptanceD.Text, culture_2, DateTimeStyles.NoCurrentDateDefault))

When I run the web page, I get the following error:

System.ArgumentException was unhandled by user code
Message="Item has already been added. Key in dictionary: 'dtAcceptD' Key being added: 'dtAcceptD'"
Source="mscorlib"
StackTrace:
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)

at System.Collections.Hashtable.Add(Object key, Object value)

at System.Collections.Specialized.OrderedDictionary.Add(Object key, Object value)

at Default3.FormView1_ItemInserting(Object sender, FormViewInsertEventArgs e) in C:\SRS\Default3.aspx.vb:line 12

at System.Web.UI.WebControls.FormView.OnItemInserting(FormViewInsertEventArgs e)

at System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation)

at System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)

at System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e)

at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)

at System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e)

at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)

at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)

at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)

at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Can someone pleaseeeeeeeeeeeeeeeee tell me what's wrong ?
TIA.

The problem here is not the date parsing. Well, it is a problem too but not the one you're seeing.
You're using always the same key in your dictionary: "dtAcceptD". The first time it's ok, the second time, it crashes with the error you're seeing. A dictionary can have only one entry with a given key.
As for date parsing, you should specify the date format you're expecting explicitly. There is an overload of ParseExact that takes a format string.
Once you've gotten a DateTime object, it's easy to strip the time part (but why are you asking for it if you're going to throw it away? ) by constructing a new date object from the parts of the old one, something like:
new DateTime(myDate.Year, myDate.Month, myDate.Day)

Hi
Thanks for your reply.
Realised the following:
1) SQL saves the information for a datetime field with date and time information.
2) Viewing the information from the following sources have different results:
From SQL Enterprise Manager, information displayed as dd/mm/yyy.
From SQL Query Analyzer, information displayed as yyyy-mm-dd 00:00:00.
From VS (via the Database Explorer), its displayed as dd/mm/yyyy 12:00:00.
I probably dont need to do any conversion in the ItemInserting event of the formview.
Thanks for the tip on stripping the time portion of a datetime object. I'm sure it will come in handy.

Strong name a ASPX web Page Question

Hello,
Can anyone tell me how to strong name a web page?
Thanks
GopalBuck, Rock, and Dirk are all traditionally considered strong names. ;-)
Seriously, though, a page cannot have a strong name. An assembly can.
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Gopal Krish" <gsgk@.yahoo.com> wrote in message
news:8b4092e6.0411041121.7cdcfe25@.posting.google.com...
> Hello,
> Can anyone tell me how to strong name a web page?
> Thanks
> Gopal
Thanks Kevin,
Then my question is how to strong name an assembly that contains aspx
web page(s). I understand the runtime creates a assembly of the aspx
pages just before executing it.
Can I strong name that somehow?
The reason I ask this is strong names are really valuable to protect
code from hacking attempt but I can't use SecurityAction.Demand in my
class libraries because I could not strong name my ASPX pages (They do
full stack walk).
I know I can use LinkDemand or Assert but I also know they are less
secure than Demand / full stack walk.
SO, is there any way to strong name a ASPX assembly?
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
You can give a strong name to ANY .Net assembly. Here's how:
http://msdn.microsoft.com/library/d...ystrongname.asp
I'm not sure what you mean by "an assembly that contains aspx web page(s)."
Only classes are in an assembly. The Template files are not.
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Gopal Krish" <gsgk@.yahoo.com> wrote in message
news:uYvdhhtwEHA.2568@.TK2MSFTNGP11.phx.gbl...
> Thanks Kevin,
> Then my question is how to strong name an assembly that contains aspx
> web page(s). I understand the runtime creates a assembly of the aspx
> pages just before executing it.
> Can I strong name that somehow?
> The reason I ask this is strong names are really valuable to protect
> code from hacking attempt but I can't use SecurityAction.Demand in my
> class libraries because I could not strong name my ASPX pages (They do
> full stack walk).
> I know I can use LinkDemand or Assert but I also know they are less
> secure than Demand / full stack walk.
> SO, is there any way to strong name a ASPX assembly?
>
>
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
Interesting question!
Do you want to strong name the temporary assemblies the runtime
creates when it parses and compiles ASPX pages?
I can't think of a way to do this.
Scott
http://www.OdeToCode.com/blogs/scott/
On Thu, 04 Nov 2004 17:40:06 -0800, Gopal Krish <gsgk@.yahoo.com>
wrote:

>Thanks Kevin,
>Then my question is how to strong name an assembly that contains aspx
>web page(s). I understand the runtime creates a assembly of the aspx
>pages just before executing it.
>Can I strong name that somehow?
>The reason I ask this is strong names are really valuable to protect
>code from hacking attempt but I can't use SecurityAction.Demand in my
>class libraries because I could not strong name my ASPX pages (They do
>full stack walk).
>I know I can use LinkDemand or Assert but I also know they are less
>secure than Demand / full stack walk.
>SO, is there any way to strong name a ASPX assembly?
>
>
>
>*** Sent via Developersdex http://www.examnotes.net ***
>Don't just participate in USENET...get rewarded for it!
I couldn't answer that question, Gopal.
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Gopal Krish" <gsgk@.yahoo.com> wrote in message
news:uYvdhhtwEHA.2568@.TK2MSFTNGP11.phx.gbl...
> Thanks Kevin,
> Then my question is how to strong name an assembly that contains aspx
> web page(s). I understand the runtime creates a assembly of the aspx
> pages just before executing it.
> Can I strong name that somehow?
> The reason I ask this is strong names are really valuable to protect
> code from hacking attempt but I can't use SecurityAction.Demand in my
> class libraries because I could not strong name my ASPX pages (They do
> full stack walk).
> I know I can use LinkDemand or Assert but I also know they are less
> secure than Demand / full stack walk.
> SO, is there any way to strong name a ASPX assembly?
>
>
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!

Strong name a ASPX web Page Question

Hello,

Can anyone tell me how to strong name a web page?

Thanks
GopalBuck, Rock, and Dirk are all traditionally considered strong names. ;-)

Seriously, though, a page cannot have a strong name. An assembly can.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Gopal Krish" <geeksgk@.yahoo.com> wrote in message
news:8b4092e6.0411041121.7cdcfe25@.posting.google.c om...
> Hello,
> Can anyone tell me how to strong name a web page?
> Thanks
> Gopal
Thanks Kevin,

Then my question is how to strong name an assembly that contains aspx
web page(s). I understand the runtime creates a assembly of the aspx
pages just before executing it.

Can I strong name that somehow?

The reason I ask this is strong names are really valuable to protect
code from hacking attempt but I can't use SecurityAction.Demand in my
class libraries because I could not strong name my ASPX pages (They do
full stack walk).

I know I can use LinkDemand or Assert but I also know they are less
secure than Demand / full stack walk.

SO, is there any way to strong name a ASPX assembly?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
You can give a strong name to ANY .Net assembly. Here's how:

http://msdn.microsoft.com/library/d...ystrongname.asp

I'm not sure what you mean by "an assembly that contains aspx web page(s)."
Only classes are in an assembly. The Template files are not.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Gopal Krish" <geeksgk@.yahoo.com> wrote in message
news:uYvdhhtwEHA.2568@.TK2MSFTNGP11.phx.gbl...
> Thanks Kevin,
> Then my question is how to strong name an assembly that contains aspx
> web page(s). I understand the runtime creates a assembly of the aspx
> pages just before executing it.
> Can I strong name that somehow?
> The reason I ask this is strong names are really valuable to protect
> code from hacking attempt but I can't use SecurityAction.Demand in my
> class libraries because I could not strong name my ASPX pages (They do
> full stack walk).
> I know I can use LinkDemand or Assert but I also know they are less
> secure than Demand / full stack walk.
> SO, is there any way to strong name a ASPX assembly?
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Interesting question!

Do you want to strong name the temporary assemblies the runtime
creates when it parses and compiles ASPX pages?

I can't think of a way to do this.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 04 Nov 2004 17:40:06 -0800, Gopal Krish <geeksgk@.yahoo.com>
wrote:

>Thanks Kevin,
>Then my question is how to strong name an assembly that contains aspx
>web page(s). I understand the runtime creates a assembly of the aspx
>pages just before executing it.
>Can I strong name that somehow?
>The reason I ask this is strong names are really valuable to protect
>code from hacking attempt but I can't use SecurityAction.Demand in my
>class libraries because I could not strong name my ASPX pages (They do
>full stack walk).
>I know I can use LinkDemand or Assert but I also know they are less
>secure than Demand / full stack walk.
>SO, is there any way to strong name a ASPX assembly?
>
>
>
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it!
I couldn't answer that question, Gopal.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Gopal Krish" <geeksgk@.yahoo.com> wrote in message
news:uYvdhhtwEHA.2568@.TK2MSFTNGP11.phx.gbl...
> Thanks Kevin,
> Then my question is how to strong name an assembly that contains aspx
> web page(s). I understand the runtime creates a assembly of the aspx
> pages just before executing it.
> Can I strong name that somehow?
> The reason I ask this is strong names are really valuable to protect
> code from hacking attempt but I can't use SecurityAction.Demand in my
> class libraries because I could not strong name my ASPX pages (They do
> full stack walk).
> I know I can use LinkDemand or Assert but I also know they are less
> secure than Demand / full stack walk.
> SO, is there any way to strong name a ASPX assembly?
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Thursday, March 22, 2012

Strongly Type Web Forms

How does a User Control invoke a method on its parent page? Say I have a publicMethod in code behind for an aspx page:
...
public void SomeImportantMethod() { /* do important stuff */}
...
From an Event Handler within the User Control, I'd like to invoke a method on the page in which the User Control is embedded. If I stop in the debugger and inspect this.Page, I see that it has a type of "ASP.MyAspxPage"... where did that come from? Can I delcare it intentionally somewhere?
TIA,
Geo
Your MyAspxPage is your custom page class, which inherits from the System.Web.UI.Page class.
The thing with UserControls is though, that you don't know what parent page they could be in at run-time.
So, to be safe, if you want to call a particular method on the parentPage, I'd say let your Page implement your interface which contains themethod signature (and other stuff if you want).
In your UserControl you then do a defensive cast (using the as keyword)to that interface and check for != null. You then simply call yourmethod on your interface object.
Hope that helps.
Wim

Yes, that does help. It helped in that I was hung up in anold paradigm and should get over it and just use an interface. So, thanks, that helped me get the job done.
I guess I was stuck in theOLD ASP.NET 1.1 code behind days where an ASPX page would have a code behind page which had a namespace declaration and the web form would be a public class derived from System.Web.UI.Page. So, from any C# code I could say:
MyNamespace.MyPage myPage = this.Page as MyNameSpace.MyPage;
if ( myPage != null)
{
myPage.MyMethod("hello world");
}
else
{
Response.Write("what gives?");
}
No fuss no muss, no interfaces.
I think I better go find an article or 2 on code beside or what ever it is we call it now.
Thanks again,
geo

Hello.

I think that you can also use the @.reference directive to introduce the type of the page in the user control (haven't tried it though).

Structure of website

Hi all,

using 1.1

I am creating a dynamic menu structure for my site, however, I may refer to
the structure many times within a page. This would be fine if I was doing it
all in the codebehind of the page, but I am trying to create seperate tiers
for seperate areas. The menu structure I suppose is a middle tier...

The menu is built using a recursive function to build the tree. My page
would normally call a seperate class and function to build the menu. This
would effectively mean that every time I wanted to use the menu in whatever
classes elsewhere in my page, I would have to create the menu from scratch
again to work with it.

This is what I am trying to avoid, as it can be an expensive process to call
the database for every operation.

To throw more confusion into the pot, my page codebehind is derived from my
own class, which is in turn derived from system.web.ui.page. This means that
the codebehind for the page itself has very little code in it, all the work
being done in my derived class.

On the page itself, I have custom controls and user controls. The user
controls also work like the pages where the codebehind is derived from my
derived class, which derives from usercontrol. The custom and user controls
must also be able to work with the menu class.

Where would be the best place to set up the initial menu, so that my derived
page, the page codebehind and my controls can all interact with it, without
having to build the menu each time?

Thanks for your time. If this is a little confusing, please ask me to
attempt to make it clearer.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises availableHi,

I am guessing that I didn't phrase this question easily...

Basically, I want to have a base class that on the first call to the page,
creates and populates a menu object.

When I need to refer to the menu at any time within the page (such as
creating a menu tree or finding which page I am on through following the menu
tree, or creating a breadcrumb trail), I don't want to have to create a menu
class for each instance.

What may add to the confusion is that my page, user controls and custom
controls derive from my own base classes, so there is an extra layer of
confusion. I would like my page base class to be able to know about the menu
(which can pass it to the page class), and my UCs base class to know about
it, which can pass to the UC codebehind.

I don't mind creating the menu for each page, but I really only want to
create it once, because it uses a database call, I don't want to have an
expensive process for each use of it.

All help is appreciated.

Regards,
Dave Colliver.
http://www.DerbyFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available

"David" wrote:

Quote:

Originally Posted by

Hi all,
>
using 1.1
>
I am creating a dynamic menu structure for my site, however, I may refer to
the structure many times within a page. This would be fine if I was doing it
all in the codebehind of the page, but I am trying to create seperate tiers
for seperate areas. The menu structure I suppose is a middle tier...
>
The menu is built using a recursive function to build the tree. My page
would normally call a seperate class and function to build the menu. This
would effectively mean that every time I wanted to use the menu in whatever
classes elsewhere in my page, I would have to create the menu from scratch
again to work with it.
>
This is what I am trying to avoid, as it can be an expensive process to call
the database for every operation.
>
To throw more confusion into the pot, my page codebehind is derived from my
own class, which is in turn derived from system.web.ui.page. This means that
the codebehind for the page itself has very little code in it, all the work
being done in my derived class.
>
On the page itself, I have custom controls and user controls. The user
controls also work like the pages where the codebehind is derived from my
derived class, which derives from usercontrol. The custom and user controls
must also be able to work with the menu class.
>
Where would be the best place to set up the initial menu, so that my derived
page, the page codebehind and my controls can all interact with it, without
having to build the menu each time?
>
Thanks for your time. If this is a little confusing, please ask me to
attempt to make it clearer.
>
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
>
>
>


Hi all,

I am really struggling with this still. Any help would be appreciated...

I don't know if this will work, I am thinking along the lines of ...

In my base page, in the page_init (override), create a new instance of the
class that calls the database for the menu, and create the menu structure
into a dataset (or my own structure)

Then, in my controls (or even the page itself), open the dataset (or my own
structure) that has been created from the base page.

So, for example, I have a data layer... if I have a property in the
datalayer class that stores my dataset, that I populate on the page_init,
when I come to use it in the controls, can I do something as simple as...

MyMenu = this.Menu as MyClass.Menu;

(I am using c#, .net 1.1)

Will it then access the already created Menu?

If it is likely to work, I am not sure of the way to code it. Any help here
is appreciated.

If you don't think it will work the way outlined above, but know of another
way, again, any help is appreciated.

The idea is to just call the database once for something that is likely to
be expensive to create. I don't need it on application or session level.
Page level will be fine. The problem with application or session level is
that if any changes are made to the menu structure, they won't be visible
until it has timed out.

Thanks for your time.

Best regards,
Dave Colliver.
http://www.CardiffFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

"David Colliver" <DavidColliver@.discussions.microsoft.comwrote in message
news:FA252579-0E4C-41FD-979D-171CA8DB9E8F@.microsoft.com...

Quote:

Originally Posted by

Hi,
>
I am guessing that I didn't phrase this question easily...
>
Basically, I want to have a base class that on the first call to the page,
creates and populates a menu object.
>
When I need to refer to the menu at any time within the page (such as
creating a menu tree or finding which page I am on through following the
menu
tree, or creating a breadcrumb trail), I don't want to have to create a
menu
class for each instance.
>
What may add to the confusion is that my page, user controls and custom
controls derive from my own base classes, so there is an extra layer of
confusion. I would like my page base class to be able to know about the
menu
(which can pass it to the page class), and my UCs base class to know about
it, which can pass to the UC codebehind.
>
I don't mind creating the menu for each page, but I really only want to
create it once, because it uses a database call, I don't want to have an
expensive process for each use of it.
>
All help is appreciated.
>
Regards,
Dave Colliver.
http://www.DerbyFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
>
>
>
"David" wrote:
>

Quote:

Originally Posted by

>Hi all,
>>
>using 1.1
>>
>I am creating a dynamic menu structure for my site, however, I may refer
>to
>the structure many times within a page. This would be fine if I was doing
>it
>all in the codebehind of the page, but I am trying to create seperate
>tiers
>for seperate areas. The menu structure I suppose is a middle tier...
>>
>The menu is built using a recursive function to build the tree. My page
>would normally call a seperate class and function to build the menu. This
>would effectively mean that every time I wanted to use the menu in
>whatever
>classes elsewhere in my page, I would have to create the menu from
>scratch
>again to work with it.
>>
>This is what I am trying to avoid, as it can be an expensive process to
>call
>the database for every operation.
>>
>To throw more confusion into the pot, my page codebehind is derived from
>my
>own class, which is in turn derived from system.web.ui.page. This means
>that
>the codebehind for the page itself has very little code in it, all the
>work
>being done in my derived class.
>>
>On the page itself, I have custom controls and user controls. The user
>controls also work like the pages where the codebehind is derived from my
>derived class, which derives from usercontrol. The custom and user
>controls
>must also be able to work with the menu class.
>>
>Where would be the best place to set up the initial menu, so that my
>derived
>page, the page codebehind and my controls can all interact with it,
>without
>having to build the menu each time?
>>
>Thanks for your time. If this is a little confusing, please ask me to
>attempt to make it clearer.
>>
>Best regards,
>Dave Colliver.
>http://www.AshfieldFOCUS.com
>~~
>http://www.FOCUSPortals.com - Local franchises available
>>
>>
>>

Structure of website

Hi all,
using 1.1
I am creating a dynamic menu structure for my site, however, I may refer to
the structure many times within a page. This would be fine if I was doing it
all in the codebehind of the page, but I am trying to create seperate tiers
for seperate areas. The menu structure I suppose is a middle tier...
The menu is built using a recursive function to build the tree. My page
would normally call a seperate class and function to build the menu. This
would effectively mean that every time I wanted to use the menu in whatever
classes elsewhere in my page, I would have to create the menu from scratch
again to work with it.
This is what I am trying to avoid, as it can be an expensive process to call
the database for every operation.
To throw more confusion into the pot, my page codebehind is derived from my
own class, which is in turn derived from system.web.ui.page. This means that
the codebehind for the page itself has very little code in it, all the work
being done in my derived class.
On the page itself, I have custom controls and user controls. The user
controls also work like the pages where the codebehind is derived from my
derived class, which derives from usercontrol. The custom and user controls
must also be able to work with the menu class.
Where would be the best place to set up the initial menu, so that my derived
page, the page codebehind and my controls can all interact with it, without
having to build the menu each time?
Thanks for your time. If this is a little confusing, please ask me to
attempt to make it clearer.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises availableHi,
I am guessing that I didn't phrase this question easily...
Basically, I want to have a base class that on the first call to the page,
creates and populates a menu object.
When I need to refer to the menu at any time within the page (such as
creating a menu tree or finding which page I am on through following the men
u
tree, or creating a breadcrumb trail), I don't want to have to create a menu
class for each instance.
What may add to the confusion is that my page, user controls and custom
controls derive from my own base classes, so there is an extra layer of
confusion. I would like my page base class to be able to know about the menu
(which can pass it to the page class), and my UCs base class to know about
it, which can pass to the UC codebehind.
I don't mind creating the menu for each page, but I really only want to
create it once, because it uses a database call, I don't want to have an
expensive process for each use of it.
All help is appreciated.
Regards,
Dave Colliver.
http://www.DerbyFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"David" wrote:

> Hi all,
> using 1.1
> I am creating a dynamic menu structure for my site, however, I may refer t
o
> the structure many times within a page. This would be fine if I was doing
it
> all in the codebehind of the page, but I am trying to create seperate tier
s
> for seperate areas. The menu structure I suppose is a middle tier...
> The menu is built using a recursive function to build the tree. My page
> would normally call a seperate class and function to build the menu. This
> would effectively mean that every time I wanted to use the menu in whateve
r
> classes elsewhere in my page, I would have to create the menu from scratch
> again to work with it.
> This is what I am trying to avoid, as it can be an expensive process to ca
ll
> the database for every operation.
> To throw more confusion into the pot, my page codebehind is derived from m
y
> own class, which is in turn derived from system.web.ui.page. This means th
at
> the codebehind for the page itself has very little code in it, all the wor
k
> being done in my derived class.
> On the page itself, I have custom controls and user controls. The user
> controls also work like the pages where the codebehind is derived from my
> derived class, which derives from usercontrol. The custom and user control
s
> must also be able to work with the menu class.
> Where would be the best place to set up the initial menu, so that my deriv
ed
> page, the page codebehind and my controls can all interact with it, withou
t
> having to build the menu each time?
> Thanks for your time. If this is a little confusing, please ask me to
> attempt to make it clearer.
> Best regards,
> Dave Colliver.
> http://www.AshfieldFOCUS.com
> ~~
> http://www.FOCUSPortals.com - Local franchises available
>
>
Hi all,
I am really struggling with this still. Any help would be appreciated...
I don't know if this will work, I am thinking along the lines of ...
In my base page, in the page_init (override), create a new instance of the
class that calls the database for the menu, and create the menu structure
into a dataset (or my own structure)
Then, in my controls (or even the page itself), open the dataset (or my own
structure) that has been created from the base page.
So, for example, I have a data layer... if I have a property in the
datalayer class that stores my dataset, that I populate on the page_init,
when I come to use it in the controls, can I do something as simple as...
MyMenu = this.Menu as MyClass.Menu;
(I am using c#, .net 1.1)
Will it then access the already created Menu?
If it is likely to work, I am not sure of the way to code it. Any help here
is appreciated.
If you don't think it will work the way outlined above, but know of another
way, again, any help is appreciated.
The idea is to just call the database once for something that is likely to
be expensive to create. I don't need it on application or session level.
Page level will be fine. The problem with application or session level is
that if any changes are made to the menu structure, they won't be visible
until it has timed out.
Thanks for your time.
Best regards,
Dave Colliver.
http://www.CardiffFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"David Colliver" <DavidColliver@.discussions.microsoft.com> wrote in message
news:FA252579-0E4C-41FD-979D-171CA8DB9E8F@.microsoft.com...
> Hi,
> I am guessing that I didn't phrase this question easily...
> Basically, I want to have a base class that on the first call to the page,
> creates and populates a menu object.
> When I need to refer to the menu at any time within the page (such as
> creating a menu tree or finding which page I am on through following the
> menu
> tree, or creating a breadcrumb trail), I don't want to have to create a
> menu
> class for each instance.
> What may add to the confusion is that my page, user controls and custom
> controls derive from my own base classes, so there is an extra layer of
> confusion. I would like my page base class to be able to know about the
> menu
> (which can pass it to the page class), and my UCs base class to know about
> it, which can pass to the UC codebehind.
> I don't mind creating the menu for each page, but I really only want to
> create it once, because it uses a database call, I don't want to have an
> expensive process for each use of it.
> All help is appreciated.
> Regards,
> Dave Colliver.
> http://www.DerbyFOCUS.com
> ~~
> http://www.FOCUSPortals.com - Portal franchises available
>
> "David" wrote:
>

Tuesday, March 13, 2012

Struggling With Concept

Hi Folks,
As you may know I'm new to ASP.NET and Im having trouble
grappling with one concept.
If I create a user control and place it on a page I can access its public
properties through a pre-render block, But I cant access its public
properties via code. In say the Page_Load event.
Surely if the control is registered, when the Page_Load Loads, it must have
access to the UserControl Object otherwise whats the point?
Please tell me where Im going wrong !
CheersHi,
What you need to do is access the usercontrol directly, for example: -
Page_Load(...)
{
((myusercontroltype)this.FindControl("UserControlInstance1")).<Property>
}
Hth,
Phil Winstanley
Microsoft ASP.NET MVP
http://www.myservicescentral.com
Thank you so much for that, I knew it should be possible, but I must have
missed that Method somehow. I tried this instantly and it work just
absolutely fine.
Thanks Again for your help.
Best Regards - OHM
"Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote i
n
message news:caep52$9ft@.odah37.prod.google.com...
> Hi,
> What you need to do is access the usercontrol directly, for example: -
> Page_Load(...)
> {
> ((myusercontroltype)this.FindControl("UserControlInstance1")).<Property>
> }
> Hth,
> Phil Winstanley
> Microsoft ASP.NET MVP
> http://www.myservicescentral.com
>
You can also declare the control at the module level and use the withevents
keyword to expose its events if they are needed. Then you can reference the
control via the code editor.
#Region " Web Form Designer Generated Code "
'Instantiate the control here and you can use it throughout the page by
name.
Protected WithEvents MyUserControl As New MyUserControl
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
With Me.MyUserControl
.DataSource = SomeDataSource
.Text = "SomeValue"
.SomeOtherProperty = "SomeOtherValue"
End With
End If
End Sub
"One Handed Man ( OHM#)" <news.microsoft.com> wrote in message
news:uazb75GUEHA.1048@.tk2msftngp13.phx.gbl...
> Hi Folks,
> As you may know I'm new to ASP.NET and Im having trouble
> grappling with one concept.
> If I create a user control and place it on a page I can access its public
> properties through a pre-render block, But I cant access its public
> properties via code. In say the Page_Load event.
> Surely if the control is registered, when the Page_Load Loads, it must
> have
> access to the UserControl Object otherwise whats the point?
> Please tell me where Im going wrong !
> Cheers
>

Struggling With Concept

Hi Folks,
As you may know I'm new to ASP.NET and Im having trouble
grappling with one concept.

If I create a user control and place it on a page I can access its public
properties through a pre-render block, But I cant access its public
properties via code. In say the Page_Load event.

Surely if the control is registered, when the Page_Load Loads, it must have
access to the UserControl Object otherwise whats the point?

Please tell me where Im going wrong !

CheersYou can also declare the control at the module level and use the withevents
keyword to expose its events if they are needed. Then you can reference the
control via the code editor.

#Region " Web Form Designer Generated Code "
'Instantiate the control here and you can use it throughout the page by
name.
Protected WithEvents MyUserControl As New MyUserControl

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
With Me.MyUserControl
.DataSource = SomeDataSource
.Text = "SomeValue"
.SomeOtherProperty = "SomeOtherValue"
End With
End If
End Sub

"One Handed Man ( OHM#)" <news.microsoft.com> wrote in message
news:uazb75GUEHA.1048@.tk2msftngp13.phx.gbl...
> Hi Folks,
> As you may know I'm new to ASP.NET and Im having trouble
> grappling with one concept.
> If I create a user control and place it on a page I can access its public
> properties through a pre-render block, But I cant access its public
> properties via code. In say the Page_Load event.
> Surely if the control is registered, when the Page_Load Loads, it must
> have
> access to the UserControl Object otherwise whats the point?
> Please tell me where Im going wrong !
> Cheers

Stuck

Ok,

I got this page (with a datagrid on it) that I hit a button on and it opens
a new page (popup). In that popup I have to option to delete the record that
got me there, or change it.. whatever.

Ok when I am done and close the popup and give focus back to the parent
form...

How can I refresh it so that the changes are shown.. or rebind it or
whatever.. how do I tell the form to do something once the child (popup) is
closed?

thanksYou can use "opener" object before closing the popup form.

like opener.MYFORM.submit(); or opener.refresh;
George.

"HalaszJ" <halaszj@.charter.net> wrote in message
news:eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it
opens
> a new page (popup). In that popup I have to option to delete the record
that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup)
is
> closed?
> thanks
You can use "opener" object before closing the popup form.

like opener.MYFORM.submit(); or opener.refresh;
George.

"HalaszJ" <halaszj@.charter.net> wrote in message
news:eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it
opens
> a new page (popup). In that popup I have to option to delete the record
that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup)
is
> closed?
> thanks
You need some Java Script, to reload the grid's page
before closing your popup try :

opener.document.location.href=opener.document.loca tion.href

or

top.opener.navigate(top.opener.document.location.h ref)

Hope this helps

Eduardo

"HalaszJ" <halaszj@.charter.net> wrote in message news:<eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl>...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it opens
> a new page (popup). In that popup I have to option to delete the record that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup) is
> closed?
> thanks
You need some Java Script, to reload the grid's page
before closing your popup try :

opener.document.location.href=opener.document.loca tion.href

or

top.opener.navigate(top.opener.document.location.h ref)

Hope this helps

Eduardo

"HalaszJ" <halaszj@.charter.net> wrote in message news:<eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl>...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it opens
> a new page (popup). In that popup I have to option to delete the record that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup) is
> closed?
> thanks

stuck in a loop

Hi

I try to use this piece of code, but the page seems to get stuck in the loop. What am I doing wrong here?

Function NumberOfLinesInFile()
Dim path As String = Server.MapPath("row.txt")
Dim sr As StreamReader = New StreamReader(path)
Dim i As Integer
i = 0
Do While sr.Peek() >= 0
i = i + 1
Loop
sr.Close()
Return i
End Function

Regards

Mhello, what if sr.Peek() is always >= 0 ? check the values returned by sr !!!
The Peek function does not move to the next character, it only consumes it. Try using the sr.Read() instead.

hope this helps,

sivilian

stuck in the beggining..

Hi,

Why is it that everytime i try to make a new asp.net page and then put any <% %> code it generates errors? After a couple times of trying to run it i just copy and pasted a snippet of code from a tutorial and still no luck. Am i just forgetting to do something?

thankx.

Pleeze pardon my noobish-ness, just started migrating to asp.net from phpHi,

I am new too and may have had the same prolem. If you are trying to test your Javascript from your development server you have to run some Javascript 'client' tools.

The error mesage is was receiving was something like 'cannot find system. js file' or something like that. Anyway, you just need to run the client stuff. Heres the replied I got for my problem like this...


Run aspnet_regiis.exe -c
on that server. Your client-side scripts are not installed into the \aspnet_client folder for the domain in question.

This was really helpful too and the site's pretty good.


what's the exact error?

sounds like you need the aspnet_client stuff. running aspnet_regiis.exe can help you out there

------------------------
RTFM - straight talk for web developers. Unmoderated, uncensored, occasionally unreadable
Jason Brown - MVP, IIS

I hope that this has helped you.
Hello, well you must know how to create ur asp.net page, it doesn't only start with <% %>, it needs <%@. Page ...... > and other tags too.
Check this page:Creating Our First ASP.NET Web Page

Good Luck.
Thanks both of yall, i have it running now. ^_^
Glad to help you our friend,

Good Luck.

stuck on empty page after sending email with.........mailto:"email address here"

Hi, i have code that opens an Ms outlook new email message window on myGridviews' ItemUpdated event. I did this because of the easy with which users will find email addresses to send messages to with out the pain of remembering or cramming the so many company employee email accounts. After sending the email, outlook closes which is okay to me but the problem is, i now remain with a blank page instead of returning to the page with my Gridview from where i fired the update event that opened outlook. I wish i had away of posting or redirecting to another page or even better returning to the same page from ItemUpdated event that opened outlook was fired from. Iam not sure if this explaination is clear to any one reading it but below is the code iam talking about.

ProtectedSub GridView1_RowUpdated(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.GridViewUpdatedEventArgs

Response.Redirect(mailto:my-email-account@dotnet.itags.org.ppp.co.ug

Response.redirect("Default.aspx") 'Why is this line of code not redirecting to Default.aspx

END SUb

Option Two: How can i open outlook when an event fires without using Response.Redirect because that is exactly what what is bringing me all this mess.

Dont use a Response.Redirect(), just use an HREF...


Your first response.redirect changes the page you are on, so the second one never fires.

Why not just show the email address when your user updates the row? Or use a pop-up to display the email address for the user to click.

Try creating a hidden iframe and setting the location of the iframe to the mailto address. This might do the trick, but I haven't tested it.

--JJ


This is my scenerio. when a row is updated, basically we are talking about a name field which is initially null being filled with an employee name. So when the user clicks update after typing the employee name in this field, On the itemUpdate event of this particular Gridview, outlook opens and then the administrator doing the update should lookup the email address in outlook of the same employee whose name was entererd prevously. The aim is to send a notification email that he has been assigned a record he/she should take charge of.

So at the end of the operation, a record should have been updated and an outlook email(not automatic) should have been send to the employee whose name was entered in the Gridviews' name field.


How do you use HREF in an event handle sub procedure.


By HREF, Curt means a HyperLink. You need to use a hyperlink and open a popup to send the mail

<a href="http://links.10026.com/?link=my-email-account@.ppp.co.ug" target="_blank">Send Mail</a>

Thanks

Stuck on loading pages into a placeholder

Hi Folks,

Can someone point me to a sample or tutorial or the code to load pages into a placeholder.

I have a menu bar on the left of the page and am trying to load the clicked pages on the right.

Any ideas,

Cheers
NickWelcome to the ASP.NET forums, Nick.

You may be very interested inUser Controls. (They were originally called Pagelets, since they are very much like you described ... littles pages that you embed within your main page.)

That link is one of theQuickStart Tutorials which you might want to look through.

Hope this helps.
Hmm ive had a read over and im still stuck.

do i include the code in a script block or in the codebehind file??
Umm, neither.

Can you show the code for your page, indicating which part you want to separate out as the menu bar, and which page will have the content loaded into it?

If you do so, can you please post it between<code> and</code> tags?
Here it is.


for the link
<TD>
<a id="goHome" runat="server"><img src="http://pics.10026.com/?src=images/myWebHome.jpg"></a>
</TD>
with goHome.HRef defined in the cs file.

<TABLE cellSpacing="10" cellPadding="0" width="100%" border="0">
<asp:placeholder id="PageBody" runat="server"></asp:placeholder>
</TABLE>

I'm trying to get the link to display in the placeholder.
Cheers,
Nick
Why not use frames?
One more question before I can show you an answer.

When you say you are trying to load "pages" into a Placeholder, do you mean anentire webpage inside the table cell? Or do you just want to load differentcontent into the table cell, based on the button the user has clicked?
At the moment it is content contained within an aspx file, so an entire page I guess, what other options are available. I'm a bit of a noob to all this and have to get myself on a steep learning curve. Thanks for all your help and time.
You should really be putting yoursections of content in a User Control (.ascx), Loading them (using Page.LoadControl) when appropriate and then adding them to the PlaceHolder Control. For example:

 void Page_Load ( Object src, EventArgs eArgs ) {

Control page;

switch ( QueryString [ "page" ] ) {

case "Home" : page = LoadControl ( "/controls/home.ascx" );
break;
case "About" : page = LoadControl ( "/controls/about.ascx" );
break;
...
}

PageBody.Controls.Add ( page );
}


I assume this goes into a <script> block in the actual page. Now how do I pass the param to the switch?
Either in a <script> declaration block or CodeBehind.

The requesting URL would look like:

 http://www.domain.com/default.aspx?page=Home