Showing posts with label event. Show all posts
Showing posts with label event. Show all posts

Thursday, March 29, 2012

passing value using eventargs

is there a way to pass values using the eventargs of a certain event, lets
say onclick?? or how does everyone else pass values? lets say each button
has 5 things (string, ints, etc) it needs to know, how can you pass that to
the event handler?One option is to utilize the commandarguments argument.
it's a read write property of the control retrievable thru event args ex.
e.commandname

"memememe" <[rem]casolorz[rem]@.hot[rem]mail.com> wrote in message
news:q9iOa.647787$vU3.612940@.news1.central.cox.net ...
> is there a way to pass values using the eventargs of a certain event, lets
> say onclick?? or how does everyone else pass values? lets say each button
> has 5 things (string, ints, etc) it needs to know, how can you pass that
to
> the event handler?
"Alvin Bruney" <vapordan_spam_me_not@.hotmail_no_spamhotmail.com> wrote in
message news:edMGAILRDHA.3144@.tk2msftngp13.phx.gbl...
> One option is to utilize the commandarguments argument.
> it's a read write property of the control retrievable thru event args ex.
> e.commandname
> "memememe" <[rem]casolorz[rem]@.hot[rem]mail.com> wrote in message
> news:q9iOa.647787$vU3.612940@.news1.central.cox.net ...
> > is there a way to pass values using the eventargs of a certain event,
lets
> > say onclick?? or how does everyone else pass values? lets say each
button
> > has 5 things (string, ints, etc) it needs to know, how can you pass that
> to
> > the event handler?

I have used that but it wont solve my problem right now (actually not my
problem, someone elses) because they are using the onlick event of something
other than a button, and it does not have the command event.
Some .Net Event classes contain data in them. It sounds like you might need
to create a custom Event Class and Event Handler delegate, in order to pass
the data you specifically need. Is that correct?

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.

"memememe" <[rem]casolorz[rem]@.hot[rem]mail.com> wrote in message
news:q9iOa.647787$vU3.612940@.news1.central.cox.net ...
> is there a way to pass values using the eventargs of a certain event, lets
> say onclick?? or how does everyone else pass values? lets say each button
> has 5 things (string, ints, etc) it needs to know, how can you pass that
to
> the event handler?
"Kevin Spencer" <kevin@.SPAMMERSSUCKtakempis.com> wrote in message
news:OnHHN2LRDHA.940@.TK2MSFTNGP11.phx.gbl...
> Some .Net Event classes contain data in them. It sounds like you might
need
> to create a custom Event Class and Event Handler delegate, in order to
pass
> the data you specifically need. Is that correct?
> HTH,
> Kevin Spencer
> Microsoft FrontPage MVP
> Internet Developer
> http://www.takempis.com
> Some things just happen.
> Everything else occurs.
> "memememe" <[rem]casolorz[rem]@.hot[rem]mail.com> wrote in message
> news:q9iOa.647787$vU3.612940@.news1.central.cox.net ...
> > is there a way to pass values using the eventargs of a certain event,
lets
> > say onclick?? or how does everyone else pass values? lets say each
button
> > has 5 things (string, ints, etc) it needs to know, how can you pass that
> to
> > the event handler?

that would probably actually work (had considered similar scenarios), i just
hope i can convince the person needing that thats the way to go.
What about creating a class that extends lets say htmlanchor and on the
onclick event it passes something on the event args, or it has some
properties that can be read/write?
As to whether you can successfully override an event handler for an existing
class, you would have to check that class to find out. It's not hard to
create a custom Server Control either.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.

"memememe" <[rem]casolorz[rem]@.hot[rem]mail.com> wrote in message
news:vUjOa.648127$vU3.216888@.news1.central.cox.net ...
> "Kevin Spencer" <kevin@.SPAMMERSSUCKtakempis.com> wrote in message
> news:OnHHN2LRDHA.940@.TK2MSFTNGP11.phx.gbl...
> > Some .Net Event classes contain data in them. It sounds like you might
> need
> > to create a custom Event Class and Event Handler delegate, in order to
> pass
> > the data you specifically need. Is that correct?
> > HTH,
> > Kevin Spencer
> > Microsoft FrontPage MVP
> > Internet Developer
> > http://www.takempis.com
> > Some things just happen.
> > Everything else occurs.
> > "memememe" <[rem]casolorz[rem]@.hot[rem]mail.com> wrote in message
> > news:q9iOa.647787$vU3.612940@.news1.central.cox.net ...
> > > is there a way to pass values using the eventargs of a certain event,
> lets
> > > say onclick?? or how does everyone else pass values? lets say each
> button
> > > has 5 things (string, ints, etc) it needs to know, how can you pass
that
> > to
> > > the event handler?
> > > that would probably actually work (had considered similar scenarios), i
just
> hope i can convince the person needing that thats the way to go.
> What about creating a class that extends lets say htmlanchor and on the
> onclick event it passes something on the event args, or it has some
> properties that can be read/write?

Passing values between two pages

Hi

In my source page I am using;

Context.Items("Msg") = Msg
Response.Redirect("Destination_Page.aspx")

In my destination page in Page_Load event I am using;

lblMsg.Text = CType(Context.Items("Msg"), String)

But the value does not get to the destination page. Is there a more
reliable way to pass a string between pages?

Thanks

RegardsTry a Server.Transfer("WebForm2.aspx");
instead of Redirect.

Note this technique does not work if you use Response.Redirect. A Redirect
results in another round trip to the client and a new HTTP request - thus a
new Context object without our ArrayList. To span requests, you'll need to
use the Session object or another state container. Also, there are other
techniques you can use to pass state between two forms when using
Server.Transfer, these other techniques can be found in the resources
section of the article.
http://www.odetocode.com/Articles/111.aspx
"John" <John@.nospam.infovis.co.ukwrote in message
news:eqgC28EpGHA.504@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Hi
>
In my source page I am using;
>
Context.Items("Msg") = Msg
Response.Redirect("Destination_Page.aspx")
>
In my destination page in Page_Load event I am using;
>
lblMsg.Text = CType(Context.Items("Msg"), String)
>
But the value does not get to the destination page. Is there a more
reliable way to pass a string between pages?
>
Thanks
>
Regards
>
>


If you use Server.Transfer then on the next page you can reference the
PreviousPage object and use the FindControl method to gain reference to
whatever control you want on the previous page (the one that did the
transfer).

--
-Demetri

"sloan" wrote:

Quote:

Originally Posted by

Try a Server.Transfer("WebForm2.aspx");
instead of Redirect.
>
>
Note this technique does not work if you use Response.Redirect. A Redirect
results in another round trip to the client and a new HTTP request - thus a
new Context object without our ArrayList. To span requests, you'll need to
use the Session object or another state container. Also, there are other
techniques you can use to pass state between two forms when using
Server.Transfer, these other techniques can be found in the resources
section of the article.
http://www.odetocode.com/Articles/111.aspx
>
"John" <John@.nospam.infovis.co.ukwrote in message
news:eqgC28EpGHA.504@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Hi

In my source page I am using;

Context.Items("Msg") = Msg
Response.Redirect("Destination_Page.aspx")

In my destination page in Page_Load event I am using;

lblMsg.Text = CType(Context.Items("Msg"), String)

But the value does not get to the destination page. Is there a more
reliable way to pass a string between pages?

Thanks

Regards


>
>
>

Wednesday, March 21, 2012

Passing variables in .vb page_load event to .aspx file

Hello.
In my page_load event of my web form i check against a database to see if a particular record exists and return a boolean.
How do i get my aspx to check that boolean to determine what to display on the screen.?I would have something like:


// pseudo code

page_load()
{
// get from database

bool doesExist = databasecall();

if (doesExist)
continueSuccessfulDraw();
else
continueUnsuccessfulDraw();
}

Does that help?
You can also do this from within the method that handles the page_load event. One option would be to put a Placeholder control on your .aspx page in the location that you'd want to put whatever it is that is dependent on the boolean you are checking -- and then load the specific controls used for display into the Placeholder.
u need to use web controls
based on the value from the database you can set the visible property true/false

can you give some more details like exactly what you want to display?

passing variables into event handlers

I need to pass a variable into an event handler.

In other words, I would like to go <asp:something onclick=doSomething(5)
void dosomething (e, sender, int i)
{
i becomes 5... do something with it
}

now, i know overloading of event handlers isn't possible. Someone suggested using command argument such as:

<asp:something onclick=doSomething commandargument=5>
void dosomething (e, sender)
{
i = sender.commandArgument
}

Unfortuantely the tag i'm using (dataGrid) doesn't support CommandArgument. Any other suggestions how i can pass a variable into an event handler?

Thankshi,
tell me about the situation !!!!
in datagrid you don't need topass anything, you can always get values from a datagrid programatically !!
The thing is that I have a dataGrid inside a repeater. Data is bound to the repeater, and I need that same data to be used to bind the dataGrid.

So for example

dataTable bindData(station)
{
return dataTable from command 'select * from station'
}

changePage (e, sender)
{
do some paging stuff...
dataGrid.Source = bindData(HOW DO I GET A VALUE INTO HERE?)
}

<repeater source = stations>
<datagrid source = bindData(Container.Station) onPageIndexChanged = changePage />
</repeater
------
see... i pass the repeater 'station' into the source for the datagrid, but how do i pass something into the "onPageIndexChanged" ?
What parameter do you want to send to bindData()?

Without any more information (and only haidar will read all your code if you post it, just FYI), I would say that maybe you want to have a link in your repeater that redirects back to the same page, but with a parameter in the querystring, and then on Page_Load you can check for the existence of that parameter in the querystring and run your logic there.

ie ...


Page_Load(...)
{
if (Request.QueryString["selected_id"] != null)
{
bindData(Convert.ToInt32(Request.QueryString["selected_id"]));
}
}

:D whoa
not an elegant solution to say the least

oh well
at least i have a backup plan
thanks
> not an elegant solution to say the least

I prefer "working" to elegant, so I guess I'm about five up on you there ... ;)

But if you find something that you consider to be more "elegant", definitely post it here, since I wouldn't mind seeing a different way of doing this. I use querystrings a lot, since the programming model that I tend to use is that the page pretty much reflects the database so I try to do as little as possible with viewstate. My sites tend to have many concurrant users, so I can't afford stale data sets.

To me ... elegant = simple + powerful
LOL, i cheated

I added a

<asp:LinkButton id="stationIdButtonHolder" CommandName="stationIdHolder" CommandArgument=<%# DataBinder.Eval(Container.DataItem, "StationId") %> Runat="Server" /
Then i accessed it with:

String StationId = ((LinkButton)((Control)sender).NamingContainer.FindControl( "stationIdButtonHolder" )).CommandArgument.ToString();

from my paging function :D ya'ay!

Passing Variables Problem

Hi all

I hope someone can shed some light, im confused...

I have a GridView that displays diary data, the grids has a DataBound event handler shown below........

protected void GridView1_DataBound(object sender, EventArgs e) { TextBox1.Text =string.Empty; DateTime DRStart = DateTime.Now; DateTime DREnd = DateTime.Now;switch (DropDownList1.Text) {case"Tonight": DREnd = DateTime.Now.AddHours(23); txt_DRStart.Text = (string.Format("{0:ddd dd MMM}", DRStart)); txt_DREnd.Text = (string.Format("{0:ddd dd MMM}", DREnd));break;

There's a few more case statements but they just change the DRStart.Text and DREnd.text dates to populate the grid with differnet range of dates.

Back over on the Default.aspx page I have an SqlDataSource adaptor which look like this...........

"ResultsSqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT venue, town, artist, date FROM gigs WHERE (town = @dotnet.itags.org.town) OR (venue = @dotnet.itags.org.venue) OR (artist = @dotnet.itags.org.artist) AND (date BETWEEN @dotnet.itags.org.DRStart AND @dotnet.itags.org.DREnd)"> "TextBox1" Name="town" PropertyName="Text"> "TextBox1" Name="venue" PropertyName="Text"> "TextBox1" Name="artist" PropertyName="Text"> "txt_DRStart" Name="DRStart" PropertyName="Text"> "txt_DREnd" Name="DREnd" PropertyName="Text">

I get an 'error on page' from I.E. when I run it but no compiler error.

I've got a hunch that its because the @dotnet.itags.org.DRStart & @dotnet.itags.org.DREnd have been converted to strings in theGridView_DataBound event handler and the Sql SELECT statement cant read them. I just cant figure out how to get these values in the correct format!

Any suggestions

Kind regards

Tino

are you sure the tags(< >) you are writing here are correct?

Check the start and closings of each tag in Connection.


it also seems to me you have to transfer the data in correct format

do this

AND (date BETWEEN Date(@.DRStart) AND Date(@.DREnd))...................


Hi

Sorry the code I pasted was incorrect, i've tried the following but still no joy, same error on page in explorer.........

<asp:SqlDataSourceID="ResultsSqlDataSource1"runat="server"

ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT venue, town, artist, date FROM gigs WHERE (town = @.town) OR (venue = @.venue) OR (artist = @.artist) AND (date BETWEEN (@.DRStart) AND date(@.DREnd))">
<SelectParameters>
<asp:controlparameterControlID="TextBox1"Name="town"PropertyName="Text"/>
<asp:controlparameterControlID="TextBox1"Name="venue"PropertyName="Text"/>
<asp:controlparameterControlID="TextBox1"Name="artist"PropertyName="Text"/>
<asp:controlparameterControlID="txt_DRStart"Name="DRStart"PropertyName="Text"/>
<asp:controlparameterControlID="txt_DREnd"Name="DREnd"PropertyName="Text"/>
</SelectParameters>
</asp:SqlDataSource>

I get a compile error using this syntax --- BETWEEN (@.DRStart) AND date(@.DREnd))"

So I used 'Configure data source' and it makes it ---BETWEEN (@.DRStart) AND (@.DREnd))" which I assume is the correct SQL syntax for the

BETWEEN statement.

Still getting error though, any suggestions

Tino


Hi,

Based on my understanding, you want to use SqlDataSource to retrieve the data from database. When you run your asp.net application, you get an error message. If I have misunderstood you, please feel free to let me know.

What error message did you get? We can use SqlDataSource wizard to configure correct Sql statement.

For example, there is a table which has two datetime type columns: dateFrom, dateEnd. I want to retrieve the data between some datetime span:

 <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"> </asp:GridView> </div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetforumConnectionString%>" SelectCommand="SELECT dateFrom, dateEnd FROM dateTable WHERE (dateFrom BETWEEN @.dateFrom AND @.dateEnd)"> <SelectParameters> <asp:ControlParameter ControlID="TextBox1" Name="dateFrom" PropertyName="Text" /> <asp:ControlParameter ControlID="TextBox2" Name="dateEnd" PropertyName="Text" /> </SelectParameters> </asp:SqlDataSource> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" />  </form>

I hope this helps.